forked from pattern-lab/patternlab-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildFooter.js
43 lines (39 loc) · 1.35 KB
/
buildFooter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';
const jsonCopy = require('./json_copy');
const logger = require('./log');
const of = require('./object_factory');
const Pattern = of.Pattern;
let render = require('./render'); //eslint-disable-line prefer-const
/**
* Builds footer HTML from the general footer and user-defined footer
* @param patternlab - global data store
* @param patternPartial - the partial key to build this for, either viewall-patternPartial or a viewall-patternGroup-all
* @returns A promise which resolves with the HTML
*/
module.exports = function(patternlab, patternPartial, uikit) {
//first render the general footer
return render(Pattern.createEmpty({ extendedTemplate: uikit.footer }), {
patternData: JSON.stringify({
patternPartial: patternPartial
}),
cacheBuster: patternlab.cacheBuster
})
.then(footerPartial => {
let allFooterData;
try {
allFooterData = jsonCopy(
patternlab.data,
'config.paths.source.data plus patterns data'
);
} catch (err) {
logger.warning('There was an error parsing JSON for patternlab.data');
logger.warning(err);
}
allFooterData.patternLabFoot = footerPartial;
return render(patternlab.userFoot, allFooterData);
})
.catch(reason => {
console.log(reason);
logger.error('Error building buildFooterHTML');
});
};