|
1 | | -/* |
2 | | - * patternlab-node - v0.14.0 - 2015 |
3 | | - * |
| 1 | +/* |
| 2 | + * patternlab-node - v0.14.0 - 2015 |
| 3 | + * |
4 | 4 | * Brian Muenzenmeyer, and the web community. |
5 | | - * Licensed under the MIT license. |
6 | | - * |
7 | | - * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. |
| 5 | + * Licensed under the MIT license. |
| 6 | + * |
| 7 | + * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. |
8 | 8 | * |
9 | 9 | */ |
10 | 10 |
|
|
24 | 24 |
|
25 | 25 | // returns any patterns that match {{> value:mod }} or {{> value:mod(foo:"bar") }} within the pattern |
26 | 26 | function findPartialsWithStyleModifiers(pattern){ |
27 | | - var matches = pattern.template.match(/{{>([ ])?([\w\-\.\/~]+)(?!\()(\:[A-Za-z0-9-]+)+(?:(| )\(.*)?([ ])?}}/g); |
| 27 | + var matches = pattern.template.match(/{{>([ ])?([\w\-\.\/~]+)(?!\()(\:[A-Za-z0-9-_]+)+(?:(| )\(.*)?([ ])?}}/g); |
28 | 28 | return matches; |
29 | 29 | } |
30 | 30 |
|
31 | 31 | // returns any patterns that match {{> value(foo:"bar") }} or {{> value:mod(foo:"bar") }} within the pattern |
32 | 32 | function findPartialsWithPatternParameters(pattern){ |
33 | | - var matches = pattern.template.match(/{{>([ ])?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-]+)?(?:(| )\(.*)+([ ])?}}/g); |
| 33 | + var matches = pattern.template.match(/{{>([ ])?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-_]+)?(?:(| )\(.*)+([ ])?}}/g); |
34 | 34 | return matches; |
35 | 35 | } |
36 | 36 |
|
37 | | - //find and return any {{> template-name }} within pattern |
| 37 | + //find and return any {{> template-name* }} within pattern |
38 | 38 | function findPartials(pattern){ |
39 | | - var matches = pattern.template.match(/{{>([ ])?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-]+)?(?:(| )\(.*)?([ ])?}}/g); |
| 39 | + var matches = pattern.template.match(/{{>([ ])?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-_]+)?(?:(| )\(.*)?([ ])?}}/g); |
40 | 40 | return matches; |
41 | 41 | } |
42 | 42 |
|
|
145 | 145 | //add the raw template to memory |
146 | 146 | currentPattern.template = fs.readFileSync(file, 'utf8'); |
147 | 147 |
|
| 148 | + //find any stylemodifiers that may be in the current pattern |
| 149 | + currentPattern.stylePartials = findPartialsWithStyleModifiers(currentPattern); |
| 150 | + |
| 151 | + //find any pattern parameters that may be in the current pattern |
| 152 | + currentPattern.parameteredPartials = findPartialsWithPatternParameters(currentPattern); |
| 153 | + |
148 | 154 | //add currentPattern to patternlab.patterns array |
149 | 155 | addPattern(currentPattern, patternlab); |
150 | 156 | } |
|
157 | 163 | ph = require('./parameter_hunter'), |
158 | 164 | pph = require('./pseudopattern_hunter'), |
159 | 165 | lih = require('./list_item_hunter'), |
| 166 | + smh = require('./style_modifier_hunter'), |
160 | 167 | path = require('path'); |
161 | 168 |
|
162 | 169 | var parameter_hunter = new ph(), |
163 | 170 | lineage_hunter = new lh(), |
164 | 171 | list_item_hunter = new lih(), |
| 172 | + style_modifier_hunter = new smh(), |
165 | 173 | pseudopattern_hunter = new pph(); |
166 | 174 |
|
167 | 175 | //find current pattern in patternlab object using var file as a key |
|
198 | 206 |
|
199 | 207 | //do something with the regular old partials |
200 | 208 | for(i = 0; i < foundPatternPartials.length; i++){ |
201 | | - var partialKey = foundPatternPartials[i].replace(/{{>([ ])?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-]+)?(?:(| )\(.*)?([ ])?}}/g, '$2'); |
| 209 | + var partialKey = foundPatternPartials[i].replace(/{{>([ ])?([\w\-\.\/~]+)(:[A-z-_]+)?(?:\:[A-Za-z0-9-]+)?(?:(| )\(.*)?([ ])?}}/g, '$2'); |
| 210 | + |
202 | 211 | var partialPath; |
203 | 212 |
|
204 | 213 | //identify which pattern this partial corresponds to |
|
215 | 224 |
|
216 | 225 | //complete assembly of extended template |
217 | 226 | var partialPattern = getpatternbykey(partialKey, patternlab); |
| 227 | + |
| 228 | + //if partial has style modifier data, replace the styleModifier value |
| 229 | + if(currentPattern.stylePartials && currentPattern.stylePartials.length > 0){ |
| 230 | + style_modifier_hunter.consume_style_modifier(partialPattern, foundPatternPartials[i], patternlab); |
| 231 | + } |
| 232 | + |
218 | 233 | currentPattern.extendedTemplate = currentPattern.extendedTemplate.replace(foundPatternPartials[i], partialPattern.extendedTemplate); |
| 234 | + |
219 | 235 | } |
220 | 236 |
|
221 | 237 | } |
|
0 commit comments