Skip to content
This repository was archived by the owner on Dec 10, 2019. It is now read-only.

Commit 96c88c0

Browse files
committed
Migrate some things to a nicer object literal syntax; use the oPattern
factory in the pseudopattern hunter; misc. code cleanup; hide some debug console.logs behind the flag
1 parent e8f99c1 commit 96c88c0

File tree

5 files changed

+41
-34
lines changed

5 files changed

+41
-34
lines changed

builder/lineage_hunter.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717

1818
var pa = require('./pattern_assembler');
1919
var pattern_assembler = new pa();
20+
var config = require('../config.json');
2021

2122
//find the {{> template-name }} within patterns
22-
console.log('===\n', pattern, '\n===');
23+
if (config.debug) {
24+
console.log('===\n', pattern, '\n===');
25+
}
2326
var matches = pattern.findPartials();
2427
if(matches !== null){
2528
matches.forEach(function(match, index, matches){

builder/object_factory.js

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
// oPattern properties
2121

22-
var oPattern = function(abspath, subdir, filename, data){
22+
var oPattern = function(abspath, subdir, filename, data) {
2323
if (config.debug) {
2424
console.log('=== NEW OPATTERN.', '\nabsPath:', abspath, '\nsubdir:', subdir, '\nfilename:', filename, '\ndata:\n', data);
2525
}
@@ -50,27 +50,34 @@
5050

5151
// oPattern methods
5252

53-
// render method on oPatterns; this acts as a proxy for the PatternEngine's
54-
// render function
55-
oPattern.prototype.render = function (data, partials) {
56-
if (config.debug && this.isPseudoPattern) {
57-
console.log('===', this.name + ' IS A PSEUDO-PATTERN ===');
53+
oPattern.prototype = {
54+
55+
// render method on oPatterns; this acts as a proxy for the PatternEngine's
56+
// render function
57+
render: function (data, partials) {
58+
if (config.debug && this.isPseudoPattern) {
59+
console.log('===', this.name + ' IS A PSEUDO-PATTERN ===');
60+
}
61+
return this.engine.renderPattern(this.extendedTemplate, data, partials);
62+
},
63+
64+
// the finders all delegate to the PatternEngine, which also encapsulates all
65+
// appropriate regexes
66+
findPartials: function () {
67+
return this.engine.findPartials(this);
68+
},
69+
70+
findPartialsWithStyleModifiers: function () {
71+
return this.engine.findPartialsWithStyleModifiers(this);
72+
},
73+
74+
findPartialsWithPatternParameters: function () {
75+
return this.engine.findPartialsWithPatternParameters(this);
76+
},
77+
78+
findListItems: function () {
79+
return this.engine.findListItems(this);
5880
}
59-
return this.engine.renderPattern(this.extendedTemplate, data, partials);
60-
};
61-
// the finders all delegate to the PatternEngine, which also encapsulates all
62-
// appropriate regexes
63-
oPattern.prototype.findPartials = function () {
64-
return this.engine.findPartials(this);
65-
};
66-
oPattern.prototype.findPartialsWithStyleModifiers = function () {
67-
return this.engine.findPartialsWithStyleModifiers(this);
68-
};
69-
oPattern.prototype.findPartialsWithPatternParameters = function () {
70-
return this.engine.findPartialsWithPatternParameters(this);
71-
};
72-
oPattern.prototype.findListItems = function () {
73-
return this.engine.findListItems(this);
7481
};
7582

7683
// oPattern static methods

builder/patternlab.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ var patternlab_engine = function () {
1313

1414
var path = require('path'),
1515
fs = require('fs-extra'),
16-
extend = require('util')._extend,
1716
diveSync = require('diveSync'),
18-
glob = require('glob'),
1917
of = require('./object_factory'),
2018
pa = require('./pattern_assembler'),
2119
mh = require('./media_hunter'),

builder/pseudopattern_hunter.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,22 @@
4747
//extend any existing data with variant data
4848
variantFileData = pattern_assembler.merge_data(currentPattern.jsonFileData, variantFileData);
4949

50-
// GTP: mustache-specific stuff here
5150
var variantName = pseudoPatterns[i].substring(pseudoPatterns[i].indexOf('~') + 1).split('.')[0];
5251
var variantFilePath = 'source/_patterns/' + currentPattern.subdir + '/' + currentPattern.fileName + '~' + variantName + '.json';
5352
var variantFileName = currentPattern.fileName + '-' + variantName + '.';
54-
var patternVariant = new of.oPattern(variantFilePath, currentPattern.subdir, variantFileName, variantFileData);
53+
var patternVariant = of.oPattern.create(variantFilePath, currentPattern.subdir, variantFileName, variantFileData, {
54+
//use the same template as the non-variant
55+
template: currentPattern.template,
56+
extendedTemplate: currentPattern.extendedTemplate,
57+
isPseudoPattern: true,
58+
basePattern: currentPattern,
59+
// use the same template engine as the non-variant
60+
engine: currentPattern.engine
61+
});
5562

5663
//see if this file has a state
5764
pattern_assembler.setPatternState(patternVariant, patternlab);
5865

59-
//use the same template as the non-variant
60-
patternVariant.template = currentPattern.template;
61-
patternVariant.extendedTemplate = currentPattern.extendedTemplate;
62-
patternVariant.isPseudoPattern = true;
63-
patternVariant.basePattern = currentPattern;
64-
patternVariant.engine = patternVariant.basePattern.engine;
65-
6666
//find pattern lineage
6767
lineage_hunter.find_lineage(patternVariant, patternlab);
6868

test/pattern_engines_tests.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
'getEngineNameForPattern returns "mustache" for an artificial empty template': function (test) {
2828
test.expect(1);
2929
var emptyPattern = of.oPattern.createEmpty();
30-
console.log(emptyPattern);
3130
test.equals(patternEngines.getEngineNameForPattern(emptyPattern), 'mustache');
3231
test.done();
3332
},

0 commit comments

Comments
 (0)