-
Notifications
You must be signed in to change notification settings - Fork 399
Expand file tree
/
Copy pathdecompose.js
More file actions
51 lines (43 loc) · 1.48 KB
/
decompose.js
File metadata and controls
51 lines (43 loc) · 1.48 KB
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
44
45
46
47
48
49
50
51
'use strict';
const logger = require('./log');
const lh = require('./lineage_hunter');
const lih = require('./list_item_hunter');
const addPattern = require('./addPattern');
const lineage_hunter = new lh();
const list_item_hunter = new lih();
/**
* A helper that unravels a pattern looking for partials or listitems to unravel.
* The goal is really to convert pattern.template into pattern.extendedTemplate
* @param pattern - the pattern to decompose
* @param patternlab - global data store
* @param ignoreLineage - whether or not to hunt for lineage for this pattern
*/
module.exports = function (pattern, patternlab, ignoreLineage) {
//set the extendedTemplate to operate on later if we find partials to replace
if (!pattern.extendedTemplate) {
pattern.extendedTemplate = pattern.template;
}
//find any listItem blocks that within the pattern, even if there are no partials
const listItemPromise = list_item_hunter.process_list_item_partials(
pattern,
patternlab
);
let lineagePromise;
//find pattern lineage
if (!ignoreLineage) {
lineagePromise = Promise.resolve(
lineage_hunter.find_lineage(pattern, patternlab)
);
} else {
lineagePromise = Promise.resolve();
}
const addPromise = Promise.resolve(() => {
//add to patternlab object so we can look these up later.
addPattern(pattern, patternlab);
});
return Promise.all([listItemPromise, lineagePromise, addPromise]).catch(
(reason) => {
logger.error(reason);
}
);
};