Skip to content

Commit

Permalink
Factor getPartialKey out of pattern assembler -- it's Mustache-specific
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffp committed Dec 4, 2015
1 parent b2e1a38 commit bdb0b7b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
10 changes: 7 additions & 3 deletions builder/object_factory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* patternlab-node - v0.15.1 - 2015
*
/*
* patternlab-node - v0.15.1 - 2015
*
* Brian Muenzenmeyer, and the web community.
* Licensed under the MIT license.
*
Expand Down Expand Up @@ -77,6 +77,10 @@

findListItems: function () {
return this.engine.findListItems(this);
},

getPartialKey: function (partialString) {
return this.engine.getPartialKey(this, partialString);
}
};

Expand Down
4 changes: 3 additions & 1 deletion builder/pattern_assembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@
addPattern(currentPattern, patternlab);
}



function processPatternRecursive(file, patternlab, additionalData){
var lh = require('./lineage_hunter'),
ph = require('./parameter_hunter'),
Expand Down Expand Up @@ -192,7 +194,7 @@

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

var partialPath;

Expand Down
16 changes: 12 additions & 4 deletions builder/pattern_engines/engine_mustache.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
findPartialsWithStyleModifiersRE: /{{>([ ])?([\w\-\.\/~]+)(?!\()(\:[A-Za-z0-9-_|]+)+(?:(| )\(.*)?([ ])?}}/g,
findPartialsWithPatternParametersRE: /{{>([ ])?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-_|]+)?(?:(| )\(.*)+([ ])?}}/g,
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,
getPartialKeyRE: /{{>([ ])?([\w\-\.\/~]+)(:[A-z-_|]+)?(?:\:[A-Za-z0-9-_]+)?(?:(| )\(.*)?([ ])?}}/g,

// render it
renderPattern: function renderPattern(template, data, partials) {
Expand All @@ -37,18 +38,25 @@
var matches = pattern.template.match(this.findPartialsRE);
return matches;
},
findPartialsWithStyleModifiers: function(pattern){
findPartialsWithStyleModifiers: function(pattern) {
var matches = pattern.template.match(this.findPartialsWithStyleModifiersRE);
return matches;
},
// returns any patterns that match {{> value(foo:"bar") }} or {{> value:mod(foo:"bar") }} within the pattern
findPartialsWithPatternParameters: function(pattern){
// returns any patterns that match {{> value(foo:"bar") }} or {{>
// value:mod(foo:"bar") }} within the pattern
findPartialsWithPatternParameters: function(pattern) {
var matches = pattern.template.match(this.findPartialsWithPatternParametersRE);
return matches;
},
findListItems: function(pattern){
findListItems: function(pattern) {
var matches = pattern.template.match(this.findListItemsRE);
return matches;
},
// given a pattern, and a partial string, tease out the "pattern key" and
// return it.
getPartialKey: function(pattern, partialString) {
var partialKey = partialString.replace(this.getPartialKeyRE, '$2');
return partialKey;
}
};

Expand Down

0 comments on commit bdb0b7b

Please sign in to comment.