Skip to content

Commit 0927706

Browse files
author
e2tha-e
committed
more-flexible-mustache-partial-syntax
1 parent 31b4dfc commit 0927706

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

builder/parameter_hunter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
function findparameters(pattern, patternlab){
2222

2323
//find the {{> template-name(*) }} within patterns
24-
var matches = pattern.template.match(/{{>([ ]+)?([A-Za-z0-9-]+)(\()(.+)(\))([ ]+)?}}/g);
24+
var matches = pattern.template.match(/{{>([ ]+)?([\w\-\.\/~]+)(\()(.+)(\))([ ]+)?}}/g);
2525
if(matches !== null){
2626
//compile this partial immeadiately, essentially consuming it.
2727
matches.forEach(function(pMatch, index, matches){
2828
//find the partial's name
29-
var partialName = pMatch.match(/([a-z-]+)/ig)[0];
29+
var partialName = pMatch.match(/([\w\-\.\/~]+)/g)[0];
3030

3131
if(patternlab.config.debug){
3232
console.log('found patternParameters for ' + partialName);

builder/pattern_assembler.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
//find and return any {{> template-name }} within pattern
2727
function findPartials(pattern){
28-
var matches = pattern.template.match(/{{>([ ])?([A-Za-z0-9-]+)(?:\:[A-Za-z0-9-]+)?(?:(| )\(.*)?([ ])?}}/g);
28+
var matches = pattern.template.match(/{{>([ ])?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-]+)?(?:(| )\(.*)?([ ])?}}/g);
2929
return matches;
3030
}
3131

@@ -138,7 +138,7 @@
138138

139139
//do something with the regular old partials
140140
for(var i = 0; i < foundPatternPartials.length; i++){
141-
var partialKey = foundPatternPartials[i].replace(/{{>([ ])?([A-Za-z0-9-]+)(?:\:[A-Za-z0-9-]+)?(?:(| )\(.*)?([ ])?}}/g, '$2');
141+
var partialKey = foundPatternPartials[i].replace(/{{>([ ])?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-]+)?(?:(| )\(.*)?([ ])?}}/g, '$2');
142142
var partialPattern = getpatternbykey(partialKey, patternlab);
143143
currentPattern.extendedTemplate = currentPattern.extendedTemplate.replace(foundPatternPartials[i], partialPattern.extendedTemplate);
144144
}
@@ -157,8 +157,11 @@
157157

158158
function getpatternbykey(key, patternlab){
159159
for(var i = 0; i < patternlab.patterns.length; i++){
160-
if(patternlab.patterns[i].key === key){
161-
return patternlab.patterns[i];
160+
switch (key) {
161+
case patternlab.patterns[i].key:
162+
case patternlab.patterns[i].subdir + '/' + patternlab.patterns[i].fileName:
163+
case patternlab.patterns[i].subdir + '/' + patternlab.patterns[i].fileName + '.mustache':
164+
return patternlab.patterns[i];
162165
}
163166
}
164167
throw 'Could not find pattern with key ' + key;

0 commit comments

Comments
 (0)