Skip to content

Commit 7d57fe7

Browse files
committed
feat(pattern_assembler): Further separate files
1 parent d7087fa commit 7d57fe7

File tree

5 files changed

+51
-47
lines changed

5 files changed

+51
-47
lines changed

core/lib/decompose.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const smh = require('./style_modifier_hunter');
99
const addPattern = require('./addPattern');
1010
const jsonCopy = require('./json_copy');
1111
const getPartial = require('./get');
12+
const processRecursive = require('./processRecursive');
1213

1314
const lineage_hunter = new lh();
1415
const list_item_hunter = new lih();
@@ -39,7 +40,7 @@ function expandPartials(foundPatternPartials, patternlab, currentPattern) {
3940
}
4041

4142
//recurse through nested partials to fill out this extended template.
42-
pattern_assembler.processPatternRecursive(partialPath, patternlab);
43+
processRecursive(partialPath, patternlab);
4344

4445
//complete assembly of extended template
4546
//create a copy of the partial so as to not pollute it after the getPartial call.

core/lib/pattern_assembler.js

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
const path = require('path');
44
const _ = require('lodash');
5+
56
const Pattern = require('./object_factory').Pattern;
67
const CompileState = require('./object_factory').CompileState;
7-
const pph = require('./pseudopattern_hunter');
88
const mp = require('./markdown_parser');
99
const logger = require('./log');
1010
const patternEngines = require('./pattern_engines');
1111
const ch = require('./changes_hunter');
1212
const da = require('./data_loader');
1313
const addPattern = require('./addPattern');
14-
const decompose = require('./decompose');
1514
const parseLink = require('./parseLink');
15+
1616
const markdown_parser = new mp();
1717
const changes_hunter = new ch();
1818
const dataLoader = new da();
@@ -224,42 +224,6 @@ const pattern_assembler = function () {
224224
return currentPattern;
225225
}
226226

227-
// This is now solely for analysis; loading of the pattern file is
228-
// above, in loadPatternIterative()
229-
function processPatternIterative(pattern, patternlab) {
230-
//look for a pseudo pattern by checking if there is a file
231-
//containing same name, with ~ in it, ending in .json
232-
return pph.find_pseudopatterns(pattern, patternlab).then(() => {
233-
//find any stylemodifiers that may be in the current pattern
234-
pattern.stylePartials = pattern.findPartialsWithStyleModifiers();
235-
236-
//find any pattern parameters that may be in the current pattern
237-
pattern.parameteredPartials = pattern.findPartialsWithPatternParameters();
238-
return pattern;
239-
}).catch(logger.reportError('There was an error in processPatternIterative():'));
240-
}
241-
242-
function processPatternRecursive(file, patternlab) {
243-
244-
//find current pattern in patternlab object using var file as a partial
245-
var currentPattern, i;
246-
247-
for (i = 0; i < patternlab.patterns.length; i++) {
248-
if (patternlab.patterns[i].relPath === file) {
249-
currentPattern = patternlab.patterns[i];
250-
}
251-
}
252-
253-
//return if processing an ignored file
254-
if (typeof currentPattern === 'undefined') { return Promise.resolve(); }
255-
256-
//we are processing a markdown only pattern
257-
if (currentPattern.engine === null) { return Promise.resolve(); }
258-
259-
//call our helper method to actually unravel the pattern with any partials
260-
return decompose(currentPattern, patternlab);
261-
}
262-
263227
/**
264228
* Finds patterns that were modified and need to be rebuilt. For clean patterns load the already
265229
* rendered markup.
@@ -331,12 +295,6 @@ const pattern_assembler = function () {
331295
load_pattern_iterative: function (file, patternlab) {
332296
return loadPatternIterative(file, patternlab);
333297
},
334-
process_pattern_iterative: function (pattern, patternlab) {
335-
return processPatternIterative(pattern, patternlab);
336-
},
337-
process_pattern_recursive: function (file, patternlab, additionalData) {
338-
return processPatternRecursive(file, patternlab, additionalData);
339-
},
340298
combine_listItems: function (patternlab) {
341299
buildListItems(patternlab);
342300
},

core/lib/patternlab.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const packageInfo = require('../../package.json');
1212
const dataLoader = require('./data_loader')();
1313
const decompose = require('./decompose');
1414
const logger = require('./log');
15+
const processIterative = require('./processIterative');
16+
const processRecursive = require('./processRecursive');
1517
const jsonCopy = require('./json_copy');
1618
const render = require('./render');
1719
const pa = require('./pattern_assembler');
@@ -514,7 +516,7 @@ module.exports = class PatternLab {
514516
});
515517
return promiseAllPatternFiles.then(() => {
516518
return Promise.all(this.patterns.map((pattern) => {
517-
return pattern_assembler.process_pattern_iterative(pattern, self);
519+
return processIterative(pattern, self);
518520
}));
519521
});
520522
}
@@ -529,7 +531,7 @@ module.exports = class PatternLab {
529531
logger.info(err);
530532
return;
531533
}
532-
pattern_assembler.process_pattern_recursive(path.relative(patterns_dir, file), self);
534+
processRecursive(path.relative(patterns_dir, file), self);
533535
}
534536
);
535537
}

core/lib/processIterative.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use strict";
2+
3+
const logger = require('./log');
4+
const pph = require('./pseudopattern_hunter');
5+
6+
// This is now solely for analysis; loading of the pattern file is
7+
// above, in loadPatternIterative()
8+
module.exports = function (pattern, patternlab) {
9+
10+
//look for a pseudo pattern by checking if there is a file
11+
//containing same name, with ~ in it, ending in .json
12+
return pph.find_pseudopatterns(pattern, patternlab).then(() => {
13+
//find any stylemodifiers that may be in the current pattern
14+
pattern.stylePartials = pattern.findPartialsWithStyleModifiers();
15+
16+
//find any pattern parameters that may be in the current pattern
17+
pattern.parameteredPartials = pattern.findPartialsWithPatternParameters();
18+
return Promise.resolve(pattern);
19+
}).catch(logger.reportError('There was an error in processPatternIterative():'));
20+
};

core/lib/processRecursive.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use strict";
2+
3+
const decompose = require('./decompose');
4+
5+
module.exports = function (file, patternlab) {
6+
//find current pattern in patternlab object using var file as a partial
7+
var currentPattern, i;
8+
9+
for (i = 0; i < patternlab.patterns.length; i++) {
10+
if (patternlab.patterns[i].relPath === file) {
11+
currentPattern = patternlab.patterns[i];
12+
}
13+
}
14+
15+
//return if processing an ignored file
16+
if (typeof currentPattern === 'undefined') { return Promise.resolve(); }
17+
18+
//we are processing a markdown only pattern
19+
if (currentPattern.engine === null) { return Promise.resolve(); }
20+
21+
//call our helper method to actually unravel the pattern with any partials
22+
return decompose(currentPattern, patternlab);
23+
};

0 commit comments

Comments
 (0)