Skip to content

Commit c85a8bb

Browse files
committed
Merge branch 'e2tha-e-more-flexible-mustache-partial-syntax' into dev
2 parents c39bbe0 + e23f6ba commit c85a8bb

File tree

4 files changed

+171
-7
lines changed

4 files changed

+171
-7
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;

test/parameter_hunter_tests.js

Lines changed: 145 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,150 @@
149149
test.done();
150150
},
151151

152-
};
152+
'pattern hunter finds and extends templates with verbose partials' : function(test){
153+
154+
//setup current pattern from what we would have during execution
155+
var currentPattern = {
156+
"fileName": "01-sticky-comment",
157+
"subdir": "02-organisms/02-comments",
158+
"name": "02-organisms-02-comments-01-sticky-comment",
159+
"data": null,
160+
"jsonFileData": {},
161+
"patternName": "sticky-comment",
162+
"patternLink": "02-organisms-02-comments-01-sticky-comment/02-organisms-02-comments-01-sticky-comment.html",
163+
"patternGroup": "organisms",
164+
"patternSubGroup": "comments",
165+
"flatPatternPath": "02-organisms-02-comments",
166+
"key": "organisms-sticky-comment",
167+
"template": "{{> 01-molecules/06-components/02-single-comment(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}",
168+
"patternPartial": "",
169+
"lineage": [
170+
],
171+
"lineageIndex": [
172+
],
173+
"lineageR": [
174+
],
175+
"lineageRIndex": [
176+
],
177+
"patternState": "",
178+
"extendedTemplate": "{{> 01-molecules/06-components/02-single-comment(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}"
179+
};
180+
var patternlab = {
181+
patterns: [
182+
{
183+
"fileName": "02-single-comment",
184+
"subdir": "01-molecules/06-components",
185+
"name": "01-molecules-06-components-02-single-comment",
186+
"data": null,
187+
"jsonFileData": {},
188+
"patternName": "single-comment",
189+
"patternLink": "01-molecules-06-components-02-single-comment/01-molecules-06-components-02-single-comment.html",
190+
"patternGroup": "molecules",
191+
"patternSubGroup": "components",
192+
"flatPatternPath": "01-molecules-06-components",
193+
"key": "molecules-single-comment",
194+
"template": "<p>{{description}}</p>",
195+
"patternPartial": "",
196+
"lineage": [
197+
],
198+
"lineageIndex": [
199+
],
200+
"lineageR": [
201+
],
202+
"lineageRIndex": [
203+
],
204+
"patternState": "",
205+
"extendedTemplate": "<p>{{description}}</p>"
206+
}
207+
],
208+
config: {
209+
debug: false
210+
},
211+
data: {
212+
description: 'Not a quote from a smart man'
213+
}
214+
};
215+
216+
var parameter_hunter = new ph();
217+
218+
parameter_hunter.find_parameters(currentPattern, patternlab);
219+
test.equals(currentPattern.extendedTemplate, '<p>A life is like a garden. Perfect moments can be had, but not preserved, except in memory.</p>');
220+
221+
test.done();
222+
},
223+
224+
'pattern hunter finds and extends templates with fully-pathed partials' : function(test){
225+
226+
//setup current pattern from what we would have during execution
227+
var currentPattern = {
228+
"fileName": "01-sticky-comment",
229+
"subdir": "02-organisms/02-comments",
230+
"name": "02-organisms-02-comments-01-sticky-comment",
231+
"data": null,
232+
"jsonFileData": {},
233+
"patternName": "sticky-comment",
234+
"patternLink": "02-organisms-02-comments-01-sticky-comment/02-organisms-02-comments-01-sticky-comment.html",
235+
"patternGroup": "organisms",
236+
"patternSubGroup": "comments",
237+
"flatPatternPath": "02-organisms-02-comments",
238+
"key": "organisms-sticky-comment",
239+
"template": "{{> 01-molecules/06-components/02-single-comment.mustache(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}",
240+
"patternPartial": "",
241+
"lineage": [
242+
],
243+
"lineageIndex": [
244+
],
245+
"lineageR": [
246+
],
247+
"lineageRIndex": [
248+
],
249+
"patternState": "",
250+
"extendedTemplate": "{{> 01-molecules/06-components/02-single-comment.mustache(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}"
251+
};
252+
var patternlab = {
253+
patterns: [
254+
{
255+
"fileName": "02-single-comment",
256+
"subdir": "01-molecules/06-components",
257+
"name": "01-molecules-06-components-02-single-comment",
258+
"data": null,
259+
"jsonFileData": {},
260+
"patternName": "single-comment",
261+
"patternLink": "01-molecules-06-components-02-single-comment/01-molecules-06-components-02-single-comment.html",
262+
"patternGroup": "molecules",
263+
"patternSubGroup": "components",
264+
"flatPatternPath": "01-molecules-06-components",
265+
"key": "molecules-single-comment",
266+
"template": "<p>{{description}}</p>",
267+
"patternPartial": "",
268+
"lineage": [
269+
],
270+
"lineageIndex": [
271+
],
272+
"lineageR": [
273+
],
274+
"lineageRIndex": [
275+
],
276+
"patternState": "",
277+
"extendedTemplate": "<p>{{description}}</p>"
278+
}
279+
],
280+
config: {
281+
debug: false
282+
},
283+
data: {
284+
description: 'Not a quote from a smart man'
285+
}
286+
};
287+
288+
var parameter_hunter = new ph();
289+
290+
parameter_hunter.find_parameters(currentPattern, patternlab);
291+
test.equals(currentPattern.extendedTemplate, '<p>A life is like a garden. Perfect moments can be had, but not preserved, except in memory.</p>');
292+
293+
test.done();
294+
}
295+
296+
};
153297

154298
}());

test/pattern_assembler_tests.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@
1818
test.equals(results[0], '{{> molecules-comment-header}}');
1919
test.equals(results[1], '{{> molecules-single-comment(description: \'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.\') }}');
2020

21+
test.done();
22+
},
23+
24+
'find_pattern_partials finds verbose partials' : function(test){
25+
26+
//setup current pattern from what we would have during execution
27+
var currentPattern = {
28+
"template": "<h1>{{> 01-molecules/06-components/03-comment-header.mustache }}</h1><div>{{> 01-molecules/06-components/02-single-comment(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}</div>",
29+
};
30+
31+
var pattern_assembler = new pa();
32+
33+
var results = pattern_assembler.find_pattern_partials(currentPattern);
34+
test.equals(results.length, 2);
35+
test.equals(results[0], '{{> 01-molecules/06-components/03-comment-header.mustache }}');
36+
test.equals(results[1], '{{> 01-molecules/06-components/02-single-comment(description: \'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.\') }}');
37+
2138
test.done();
2239
}
2340

0 commit comments

Comments
 (0)