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

Commit bdb0b7b

Browse files
committed
Factor getPartialKey out of pattern assembler -- it's Mustache-specific
1 parent b2e1a38 commit bdb0b7b

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

builder/object_factory.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/*
2-
* patternlab-node - v0.15.1 - 2015
3-
*
1+
/*
2+
* patternlab-node - v0.15.1 - 2015
3+
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
66
*
@@ -77,6 +77,10 @@
7777

7878
findListItems: function () {
7979
return this.engine.findListItems(this);
80+
},
81+
82+
getPartialKey: function (partialString) {
83+
return this.engine.getPartialKey(this, partialString);
8084
}
8185
};
8286

builder/pattern_assembler.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@
145145
addPattern(currentPattern, patternlab);
146146
}
147147

148+
149+
148150
function processPatternRecursive(file, patternlab, additionalData){
149151
var lh = require('./lineage_hunter'),
150152
ph = require('./parameter_hunter'),
@@ -192,7 +194,7 @@
192194

193195
//do something with the regular old partials
194196
for(i = 0; i < foundPatternPartials.length; i++){
195-
var partialKey = foundPatternPartials[i].replace(/{{>([ ])?([\w\-\.\/~]+)(:[A-z-_|]+)?(?:\:[A-Za-z0-9-_]+)?(?:(| )\(.*)?([ ])?}}/g, '$2');
197+
var partialKey = currentPattern.getPartialKey(foundPatternPartials[i]);
196198

197199
var partialPath;
198200

builder/pattern_engines/engine_mustache.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
findPartialsWithStyleModifiersRE: /{{>([ ])?([\w\-\.\/~]+)(?!\()(\:[A-Za-z0-9-_|]+)+(?:(| )\(.*)?([ ])?}}/g,
2424
findPartialsWithPatternParametersRE: /{{>([ ])?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-_|]+)?(?:(| )\(.*)+([ ])?}}/g,
2525
findListItemsRE: /({{#( )?)(list(I|i)tems.)(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty)( )?}}/g,
26+
getPartialKeyRE: /{{>([ ])?([\w\-\.\/~]+)(:[A-z-_|]+)?(?:\:[A-Za-z0-9-_]+)?(?:(| )\(.*)?([ ])?}}/g,
2627

2728
// render it
2829
renderPattern: function renderPattern(template, data, partials) {
@@ -37,18 +38,25 @@
3738
var matches = pattern.template.match(this.findPartialsRE);
3839
return matches;
3940
},
40-
findPartialsWithStyleModifiers: function(pattern){
41+
findPartialsWithStyleModifiers: function(pattern) {
4142
var matches = pattern.template.match(this.findPartialsWithStyleModifiersRE);
4243
return matches;
4344
},
44-
// returns any patterns that match {{> value(foo:"bar") }} or {{> value:mod(foo:"bar") }} within the pattern
45-
findPartialsWithPatternParameters: function(pattern){
45+
// returns any patterns that match {{> value(foo:"bar") }} or {{>
46+
// value:mod(foo:"bar") }} within the pattern
47+
findPartialsWithPatternParameters: function(pattern) {
4648
var matches = pattern.template.match(this.findPartialsWithPatternParametersRE);
4749
return matches;
4850
},
49-
findListItems: function(pattern){
51+
findListItems: function(pattern) {
5052
var matches = pattern.template.match(this.findListItemsRE);
5153
return matches;
54+
},
55+
// given a pattern, and a partial string, tease out the "pattern key" and
56+
// return it.
57+
getPartialKey: function(pattern, partialString) {
58+
var partialKey = partialString.replace(this.getPartialKeyRE, '$2');
59+
return partialKey;
5260
}
5361
};
5462

0 commit comments

Comments
 (0)