Skip to content

Commit 32a13e1

Browse files
committed
feat(ui_builder): Broke out buildFooter
1 parent 7a14c09 commit 32a13e1

File tree

2 files changed

+42
-33
lines changed

2 files changed

+42
-33
lines changed

core/lib/buildFooter.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"use strict";
2+
3+
const jsonCopy = require('./json_copy');
4+
const logger = require('./log');
5+
const of = require('./object_factory');
6+
const Pattern = of.Pattern;
7+
8+
let render = require('./render'); //eslint-disable-line prefer-const
9+
10+
/**
11+
* Builds footer HTML from the general footer and user-defined footer
12+
* @param patternlab - global data store
13+
* @param patternPartial - the partial key to build this for, either viewall-patternPartial or a viewall-patternType-all
14+
* @returns A promise which resolves with the HTML
15+
*/
16+
module.exports = function (patternlab, patternPartial) {
17+
//first render the general footer
18+
return render(Pattern.createEmpty({extendedTemplate: patternlab.footer}), {
19+
patternData: JSON.stringify({
20+
patternPartial: patternPartial,
21+
}),
22+
cacheBuster: patternlab.cacheBuster
23+
}).then(footerPartial => {
24+
25+
let allFooterData;
26+
try {
27+
allFooterData = jsonCopy(patternlab.data, 'config.paths.source.data plus patterns data');
28+
} catch (err) {
29+
logger.warning('There was an error parsing JSON for patternlab.data');
30+
logger.warning(err);
31+
}
32+
allFooterData.patternLabFoot = footerPartial;
33+
34+
return render(Pattern.createEmpty({extendedTemplate: patternlab.userFoot}), allFooterData);
35+
}).catch(reason => {
36+
console.log(reason);
37+
logger.error('Error building buildFooterHTML');
38+
});
39+
};

core/lib/ui_builder.js

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const path = require('path');
44
const _ = require('lodash');
55
const eol = require('os').EOL;
66

7-
const jsonCopy = require('./json_copy');
87
const ae = require('./annotation_exporter');
98
const of = require('./object_factory');
109
const Pattern = of.Pattern;
@@ -13,6 +12,7 @@ const logger = require('./log');
1312
//these are mocked in unit tests, so let them be overridden
1413
let render = require('./render'); //eslint-disable-line prefer-const
1514
let fs = require('fs-extra'); //eslint-disable-line prefer-const
15+
let buildFooter = require('./buildFooter'); //eslint-disable-line prefer-const
1616

1717
const ui_builder = function () {
1818

@@ -407,36 +407,6 @@ const ui_builder = function () {
407407
return groupedPatterns;
408408
}
409409

410-
/**
411-
* Builds footer HTML from the general footer and user-defined footer
412-
* @param patternlab - global data store
413-
* @param patternPartial - the partial key to build this for, either viewall-patternPartial or a viewall-patternType-all
414-
* @returns A promise which resolves with the HTML
415-
*/
416-
function buildFooterHTML(patternlab, patternPartial) {
417-
//first render the general footer
418-
return render(Pattern.createEmpty({extendedTemplate:patternlab.footer}), {
419-
patternData: JSON.stringify({
420-
patternPartial: patternPartial,
421-
}),
422-
cacheBuster: patternlab.cacheBuster
423-
}).then(footerPartial => {
424-
425-
let allFooterData;
426-
try {
427-
allFooterData = jsonCopy(patternlab.data, 'config.paths.source.data plus patterns data');
428-
} catch (err) {
429-
logger.warning('There was an error parsing JSON for patternlab.data');
430-
logger.warning(err);
431-
}
432-
allFooterData.patternLabFoot = footerPartial;
433-
434-
return render(Pattern.createEmpty({extendedTemplate: patternlab.userFoot}), allFooterData);
435-
}).catch(reason => {
436-
console.log(reason);
437-
logger.error('Error building buildFooterHTML');
438-
});
439-
}
440410

441411
/**
442412
* Takes a set of patterns and builds a viewall HTML page for them
@@ -493,7 +463,7 @@ const ui_builder = function () {
493463
}
494464

495465
//render the footer needed for the viewall template
496-
return buildFooterHTML(patternlab, 'viewall-' + patternPartial).then(footerHTML => {
466+
return buildFooter(patternlab, 'viewall-' + patternPartial).then(footerHTML => {
497467

498468
//render the viewall template by finding these smallest subtype-grouped patterns
499469
const subtypePatterns = sortPatterns(_.values(patternSubtypes));
@@ -535,7 +505,7 @@ const ui_builder = function () {
535505
}
536506

537507
//render the footer needed for the viewall template
538-
return buildFooterHTML(patternlab, 'viewall-' + patternType + '-all').then(footerHTML => {
508+
return buildFooter(patternlab, 'viewall-' + patternType + '-all').then(footerHTML => {
539509

540510
//add any flat patterns
541511
//todo this isn't quite working yet

0 commit comments

Comments
 (0)