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

Commit 7b0a44c

Browse files
committed
factor Mustache-specific findPartialKey out of the lineage hunter and
put it in the Mustach engine, where it replaces one that didn't work as well; normalize all references to getPartialKey to findPartialKey; fix the Mustache findPartialsRE to pass the 'pattern_assembler - processPatternRecursive - correctly replaces multiple stylemodifier classes on same partial' unit test.
1 parent 5769a9c commit 7b0a44c

File tree

5 files changed

+28
-22
lines changed

5 files changed

+28
-22
lines changed

builder/lineage_hunter.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,13 @@
2323
var matches = pattern.findPartials();
2424
if(matches !== null){
2525
matches.forEach(function(match, index, matches){
26-
//strip out the template cruft
27-
var foundPatternKey = match.replace("{{> ", "").replace(" }}", "").replace("{{>", "").replace("}}", "");
28-
29-
// remove any potential pattern parameters. this and the above are rather brutish but I didn't want to do a regex at the time
30-
if(foundPatternKey.indexOf('(') > 0){
31-
foundPatternKey = foundPatternKey.substring(0, foundPatternKey.indexOf('('));
32-
}
33-
34-
//remove any potential stylemodifiers.
35-
foundPatternKey = foundPatternKey.split(':')[0];
36-
3726
//get the ancestorPattern
38-
var ancestorPattern = pattern_assembler.get_pattern_by_key(foundPatternKey, patternlab);
27+
var ancestorPattern = pattern_assembler.get_pattern_by_key(pattern.findPartialKey(match), patternlab);
3928

4029
if (ancestorPattern && pattern.lineageIndex.indexOf(ancestorPattern.key) === -1){
41-
4230
//add it since it didnt exist
43-
pattern.lineageIndex.push(ancestorPattern.key);
31+
pattern.lineageIndex.push(ancestorPattern.key);
32+
4433
//create the more complex patternLineage object too
4534
var l = {
4635
"lineagePattern": ancestorPattern.key,

builder/object_factory.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@
8282
return this.engine.findListItems(this);
8383
},
8484

85-
getPartialKey: function (partialString) {
86-
return this.engine.getPartialKey(this, partialString);
85+
findPartialKey: function (partialString) {
86+
return this.engine.findPartialKey(partialString);
8787
}
8888
};
8989

builder/pattern_assembler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156

157157
//do something with the regular old partials
158158
for(var i = 0; i < foundPatternPartials.length; i++){
159-
var partialKey = currentPattern.getPartialKey(foundPatternPartials[i]);
159+
var partialKey = currentPattern.findPartialKey(foundPatternPartials[i]);
160160
var partialPath;
161161

162162
//identify which pattern this partial corresponds to

builder/pattern_engines/engine_handlebars.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
},
6565
// given a pattern, and a partial string, tease out the "pattern key" and
6666
// return it.
67-
getPartialKey: function(pattern, partialString) {
67+
findPartialKey: function(pattern, partialString) {
6868
var partialKey = partialString.replace(this.findPartialsRE, '$1');
6969
return partialKey;
7070
}

builder/pattern_engines/engine_mustache.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
expandPartials: true,
2424

2525
// regexes, stored here so they're only compiled once
26-
findPartialsRE: /{{>\s*((?:\d+-[\w-]+\/)+(\d+-[\w-]+(\.\w+)?)|[A-Za-z0-9-]+)(\:[\w-]+)?(\(\s*\w+\s*:\s*(?:'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*")\))?\s*}}/g,
26+
findPartialsRE: /{{>\s*((?:\d+-[\w-]+\/)+(\d+-[\w-]+(\.\w+)?)|[A-Za-z0-9-]+)(\:[\w-]+(?:\|[\w-]+)*)?(\(\s*\w+\s*:\s*(?:'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*")\))?\s*}}/g,
2727
findPartialsWithStyleModifiersRE: /{{>([ ])?([\w\-\.\/~]+)(?!\()(\:[A-Za-z0-9-_|]+)+(?:(| )\(.*)?([ ])?}}/g,
2828
findPartialsWithPatternParametersRE: /{{>([ ])?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-_|]+)?(?:(| )\(.*)+([ ])?}}/g,
2929
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,
30-
getPartialKeyRE: /{{>([ ])?([\w\-\.\/~]+)(:[A-z-_|]+)?(?:\:[A-Za-z0-9-_]+)?(?:(| )\(.*)?([ ])?}}/g,
30+
findPartialKeyRE: /{{>([ ])?([\w\-\.\/~]+)(:[A-z-_|]+)?(?:\:[A-Za-z0-9-_]+)?(?:(| )\(.*)?([ ])?}}/g,
3131

3232
// render it
3333
renderPattern: function renderPattern(template, data, partials) {
@@ -58,9 +58,26 @@
5858
},
5959
// given a pattern, and a partial string, tease out the "pattern key" and
6060
// return it.
61-
getPartialKey: function(pattern, partialString) {
62-
var partialKey = partialString.replace(this.getPartialKeyRE, '$2');
61+
findPartialKey_new: function(partialString) {
62+
var partialKey = partialString.replace(this.findPartialKeyRE, '$2');
6363
return partialKey;
64+
},
65+
66+
// GTP: the old implementation works better. We might not need
67+
// this.findPartialKeyRE anymore if it works in all cases!
68+
findPartialKey: function(partialString) {
69+
//strip out the template cruft
70+
var foundPatternKey = partialString.replace("{{> ", "").replace(" }}", "").replace("{{>", "").replace("}}", "");
71+
72+
// remove any potential pattern parameters. this and the above are rather brutish but I didn't want to do a regex at the time
73+
if(foundPatternKey.indexOf('(') > 0){
74+
foundPatternKey = foundPatternKey.substring(0, foundPatternKey.indexOf('('));
75+
}
76+
77+
//remove any potential stylemodifiers.
78+
foundPatternKey = foundPatternKey.split(':')[0];
79+
80+
return foundPatternKey;
6481
}
6582
};
6683

0 commit comments

Comments
 (0)