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

Commit 3d9753a

Browse files
author
Brian Muenzenmeyer
committed
Merge pull request #191 from geoffp/pattern-engines
PatternEngines: support multiple template engines, v2
2 parents c6cbcdb + 2c04ac1 commit 3d9753a

18 files changed

+769
-297
lines changed

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
tab_width = 2
8+
end_of_line = lf
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true

.eslintrc

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"env": {
3+
"jasmine": true,
4+
"node": true,
5+
"mocha": true,
6+
"browser": true,
7+
"builtin": true
8+
},
9+
"globals": {},
10+
"rules": {
11+
"block-scoped-var": 2,
12+
"camelcase": 0,
13+
"curly": [
14+
2,
15+
"all"
16+
],
17+
"dot-notation": [
18+
2,
19+
{
20+
"allowKeywords": true
21+
}
22+
],
23+
"eqeqeq": [
24+
2,
25+
"allow-null"
26+
],
27+
"global-strict": [
28+
2,
29+
"never"
30+
],
31+
"guard-for-in": 2,
32+
"new-cap": 0,
33+
"no-bitwise": 2,
34+
"no-caller": 2,
35+
"no-cond-assign": [
36+
2,
37+
"except-parens"
38+
],
39+
"no-debugger": 2,
40+
"no-empty": 2,
41+
"no-eval": 2,
42+
"no-extend-native": 2,
43+
"no-extra-parens": 0,
44+
"no-irregular-whitespace": 1,
45+
"no-iterator": 2,
46+
"no-loop-func": 2,
47+
"no-multi-str": 2,
48+
"no-multi-spaces": 0,
49+
"no-new": 2,
50+
"no-proto": 2,
51+
"no-script-url": 2,
52+
"no-sequences": 2,
53+
"no-shadow": 2,
54+
"no-undef": 2,
55+
"no-unused-vars": 2,
56+
"no-with": 2,
57+
"quotes": [
58+
0,
59+
"single"
60+
],
61+
"semi": [
62+
0,
63+
"never"
64+
],
65+
"strict": 2,
66+
"valid-typeof": 2,
67+
"wrap-iife": [
68+
2,
69+
"inside"
70+
]
71+
}
72+
}

builder/lineage_hunter.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/*
2-
* patternlab-node - v0.14.0 - 2015
3-
*
1+
/*
2+
* patternlab-node - v0.14.0 - 2015
3+
*
44
* Brian Muenzenmeyer, and the web community.
5-
* Licensed under the MIT license.
6-
*
7-
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
5+
* Licensed under the MIT license.
6+
*
7+
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
88
*
99
*/
1010

@@ -19,7 +19,8 @@
1919
var pattern_assembler = new pa();
2020

2121
//find the {{> template-name }} within patterns
22-
var matches = pattern_assembler.find_pattern_partials(pattern);
22+
console.log('===\n', pattern, '\n===');
23+
var matches = pattern.findPartials();
2324
if(matches !== null){
2425
matches.forEach(function(match, index, matches){
2526
//strip out the template cruft

builder/list_item_hunter.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/*
2-
* patternlab-node - v0.14.0 - 2015
3-
*
1+
/*
2+
* patternlab-node - v0.14.0 - 2015
3+
*
44
* Brian Muenzenmeyer, and the web community.
5-
* Licensed under the MIT license.
6-
*
7-
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
5+
* Licensed under the MIT license.
6+
*
7+
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
88
*
99
*/
1010

@@ -14,20 +14,23 @@
1414
var list_item_hunter = function(){
1515

1616
var extend = require('util')._extend,
17-
pa = require('./pattern_assembler'),
18-
smh = require('./style_modifier_hunter'),
19-
mustache = require('mustache'),
20-
pattern_assembler = new pa(),
21-
style_modifier_hunter = new smh(),
22-
items = [ 'zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen','twenty'];
17+
pa = require('./pattern_assembler'),
18+
smh = require('./style_modifier_hunter'),
19+
config = require('../config.json'),
20+
of = require('./object_factory');
21+
22+
var pattern_assembler = new pa(),
23+
style_modifier_hunter = new smh(),
24+
items = [ 'zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen','twenty'];
2325

2426
function processListItemPartials(pattern, patternlab){
2527
//find any listitem blocks
26-
var matches = pattern_assembler.find_list_items(pattern, patternlab);
28+
var matches = pattern.findListItems();
29+
2730
if(matches !== null){
2831
matches.forEach(function(liMatch, index, matches){
2932

30-
if(patternlab.config.debug){
33+
if(config.debug){
3134
console.log('found listItem of size ' + liMatch + ' inside ' + pattern.key);
3235
}
3336

@@ -39,6 +42,7 @@
3942
var repeatedBlockTemplate = [];
4043
var repeatedBlockHtml = '';
4144
for(var i = 0; i < items.indexOf(loopNumberString); i++){
45+
console.log('adding', patternBlock, 'to repeatedBlockTemplate');
4246
repeatedBlockTemplate.push(patternBlock);
4347
}
4448

@@ -62,7 +66,7 @@
6266
allData.link = extend({}, patternlab.data.link);
6367

6468
//check for partials within the repeated block
65-
var foundPartials = pattern_assembler.find_pattern_partials({ 'template' : thisBlockTemplate });
69+
var foundPartials = of.oPattern.createEmpty({'template': thisBlockTemplate}).findPartials();
6670

6771
if(foundPartials && foundPartials.length > 0){
6872

builder/object_factory.js

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
1-
/*
2-
* patternlab-node - v0.14.0 - 2015
3-
*
1+
/*
2+
* patternlab-node - v0.14.0 - 2015
3+
*
44
* Brian Muenzenmeyer, and the web community.
5-
* Licensed under the MIT license.
6-
*
7-
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
5+
* Licensed under the MIT license.
6+
*
7+
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
88
*
99
*/
1010

1111
(function () {
1212
"use strict";
1313

14+
var patternEngines = require('./pattern_engines/pattern_engines');
15+
var path = require('path');
16+
var fs = require('fs-extra');
17+
var config = fs.readJSONSync('./config.json');
18+
var extend = require('util')._extend;
19+
20+
// oPattern properties
21+
1422
var oPattern = function(abspath, subdir, filename, data){
23+
if (config.debug) {
24+
console.log('=== NEW OPATTERN.', '\nabsPath:', abspath, '\nsubdir:', subdir, '\nfilename:', filename, '\ndata:\n', data);
25+
}
1526
this.fileName = filename.substring(0, filename.indexOf('.'));
27+
this.fileExtension = path.extname(abspath);
1628
this.abspath = abspath;
1729
this.subdir = subdir;
1830
this.name = subdir.replace(/[\/\\]/g, '-') + '-' + this.fileName; //this is the unique name with the subDir
@@ -32,7 +44,52 @@
3244
this.lineageIndex = [];
3345
this.lineageR = [];
3446
this.lineageRIndex = [];
47+
this.isPseudoPattern = false;
48+
this.engine = patternEngines.getEngineForPattern(this);
49+
};
50+
51+
// oPattern methods
52+
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 ===');
58+
}
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);
3571
};
72+
oPattern.prototype.findListItems = function () {
73+
return this.engine.findListItems(this);
74+
};
75+
76+
// oPattern static methods
77+
78+
// factory: creates an empty oPattern for miscellaneous internal use, such as
79+
// by list_item_hunter
80+
oPattern.createEmpty = function (customProps) {
81+
var pattern = new oPattern('', '', '', null);
82+
return extend(pattern, customProps);
83+
};
84+
85+
// factory: creates an oPattern object on-demand from a hash; the hash accepts
86+
// parameters that replace the positional parameters that the oPattern
87+
// constructor takes.
88+
oPattern.create = function (abspath, subdir, filename, data, customProps) {
89+
var newPattern = new oPattern(abspath || '', subdir || '', filename || '', data || null);
90+
return extend(newPattern, customProps);
91+
};
92+
3693

3794
var oBucket = function(name){
3895
this.bucketNameLC = name;
@@ -45,6 +102,7 @@
45102
this.patternItemsIndex = [];
46103
};
47104

105+
48106
var oNavItem = function(name){
49107
this.sectionNameLC = name;
50108
this.sectionNameUC = name.split('-').reduce(function(val, working){
@@ -54,6 +112,7 @@
54112
this.navSubItemsIndex = [];
55113
};
56114

115+
57116
var oNavSubItem = function(name){
58117
this.patternPath = '';
59118
this.patternPartial = '';
@@ -62,11 +121,12 @@
62121
}, '').trim();
63122
};
64123

124+
65125
module.exports = {
66126
oPattern: oPattern,
67127
oBucket: oBucket,
68128
oNavItem: oNavItem,
69129
oNavSubItem: oNavSubItem
70130
};
71131

72-
}());
132+
})();

builder/parameter_hunter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* patternlab-node - v0.14.0 - 2015
33
*
44
* Brian Muenzenmeyer, and the web community.
5-
* Licensed under the MIT license.
6-
*
7-
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
5+
* Licensed under the MIT license.
6+
*
7+
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
88
*
99
*/
1010

0 commit comments

Comments
 (0)