MCPcopy
hub / github.com/jdan/cleaver / populateSingle

Function populateSingle

lib/helper.js:50–70  ·  view source on GitHub ↗

* Loads a single asset and sets the returned data to the `loaded` subobject * of a given resource map * * Usage: helper.populateSingle(this.metadata.template, this.templates, 'slides') * helper.populateSingle(this.metadata.layout, this.templates, 'layout') * * @param {string} filename T

(filename, destination, key)

Source from the content-addressed store, hash-verified

48 * @return {Promise}
49 */
50function populateSingle(filename, destination, key) {
51 return loadSingle(filename)
52 .then(function (data) {
53 if (data) {
54 /**
55 * If the key points to an array in the destination map, then
56 * we should also append to an array in the `loaded` section
57 * of the map.
58 *
59 * This is useful for style resources, where `external.style` may
60 * refer to a list of resources to be loaded.
61 */
62 if (Object.prototype.toString.call(destination[key]) === '[object Array]') {
63 destination.loaded[key] = destination.loaded[key] || [];
64 destination.loaded[key].push(data);
65 } else {
66 destination.loaded[key] = data;
67 }
68 }
69 });
70}
71
72
73/**

Callers 1

loadThemeFunction · 0.85

Calls 1

loadSingleFunction · 0.85

Tested by

no test coverage detected