|
139 | 139 |
|
140 | 140 |
|
141 | 141 |
|
| 142 | + function expandPartials(foundPatternPartials, list_item_hunter, patternlab, currentPattern) { |
| 143 | + var smh = require('./style_modifier_hunter'), |
| 144 | + ph = require('./parameter_hunter'); |
| 145 | + |
| 146 | + var style_modifier_hunter = new smh(), |
| 147 | + parameter_hunter = new ph(); |
| 148 | + |
| 149 | + if(patternlab.config.debug){ |
| 150 | + console.log('found partials for ' + currentPattern.key); |
| 151 | + } |
| 152 | + |
| 153 | + // determine if the template contains any pattern parameters. if so they |
| 154 | + // must be immediately consumed |
| 155 | + parameter_hunter.find_parameters(currentPattern, patternlab); |
| 156 | + |
| 157 | + //do something with the regular old partials |
| 158 | + for(var i = 0; i < foundPatternPartials.length; i++){ |
| 159 | + var partialKey = currentPattern.getPartialKey(foundPatternPartials[i]); |
| 160 | + var partialPath; |
| 161 | + |
| 162 | + //identify which pattern this partial corresponds to |
| 163 | + for(var j = 0; j < patternlab.patterns.length; j++){ |
| 164 | + if(patternlab.patterns[j].key === partialKey || |
| 165 | + patternlab.patterns[j].abspath.indexOf(partialKey) > -1) |
| 166 | + { |
| 167 | + partialPath = patternlab.patterns[j].abspath; |
| 168 | + } |
| 169 | + } |
| 170 | + |
| 171 | + //recurse through nested partials to fill out this extended template. |
| 172 | + processPatternRecursive(partialPath, patternlab); |
| 173 | + |
| 174 | + //complete assembly of extended template |
| 175 | + var partialPattern = getpatternbykey(partialKey, patternlab); |
| 176 | + |
| 177 | + //if partial has style modifier data, replace the styleModifier value |
| 178 | + if(currentPattern.stylePartials && currentPattern.stylePartials.length > 0){ |
| 179 | + style_modifier_hunter.consume_style_modifier(partialPattern, foundPatternPartials[i], patternlab); |
| 180 | + } |
| 181 | + |
| 182 | + currentPattern.extendedTemplate = currentPattern.extendedTemplate.replace(foundPatternPartials[i], partialPattern.extendedTemplate); |
| 183 | + } |
| 184 | + } |
| 185 | + |
142 | 186 | function processPatternRecursive(file, patternlab, additionalData){
|
143 | 187 | var lh = require('./lineage_hunter'),
|
144 |
| - ph = require('./parameter_hunter'), |
145 | 188 | pph = require('./pseudopattern_hunter'),
|
146 |
| - lih = require('./list_item_hunter'), |
147 |
| - smh = require('./style_modifier_hunter'); |
| 189 | + lih = require('./list_item_hunter'); |
148 | 190 |
|
149 |
| - var parameter_hunter = new ph(), |
150 |
| - lineage_hunter = new lh(), |
151 |
| - list_item_hunter = new lih(), |
152 |
| - style_modifier_hunter = new smh(), |
153 |
| - pseudopattern_hunter = new pph(); |
| 191 | + var lineage_hunter = new lh(), |
| 192 | + list_item_hunter = new lih(), |
| 193 | + pseudopattern_hunter = new pph(); |
154 | 194 |
|
155 | 195 | //find current pattern in patternlab object using var file as a key
|
156 |
| - var currentPattern, |
157 |
| - i; |
| 196 | + var currentPattern, i; |
158 | 197 |
|
159 | 198 | for(i = 0; i < patternlab.patterns.length; i++){
|
160 | 199 | if(patternlab.patterns[i].abspath === file){
|
|
163 | 202 | }
|
164 | 203 |
|
165 | 204 | //return if processing an ignored file
|
166 |
| - if(typeof currentPattern === 'undefined'){ |
167 |
| - return; |
168 |
| - } |
| 205 | + if (typeof currentPattern === 'undefined') { return; } |
169 | 206 |
|
170 | 207 | currentPattern.extendedTemplate = currentPattern.template;
|
171 | 208 |
|
172 | 209 | //find how many partials there may be for the given pattern
|
173 | 210 | var foundPatternPartials = currentPattern.findPartials(currentPattern);
|
174 | 211 |
|
175 |
| - if(foundPatternPartials !== null && foundPatternPartials.length > 0){ |
176 |
| - |
177 |
| - if(patternlab.config.debug){ |
178 |
| - console.log('found partials for ' + currentPattern.key); |
179 |
| - } |
180 |
| - |
181 |
| - //find any listItem blocks |
182 |
| - list_item_hunter.process_list_item_partials(currentPattern, patternlab); |
183 |
| - |
184 |
| - //determine if the template contains any pattern parameters. if so they must be immediately consumed |
185 |
| - parameter_hunter.find_parameters(currentPattern, patternlab); |
186 |
| - |
187 |
| - //do something with the regular old partials |
188 |
| - for(i = 0; i < foundPatternPartials.length; i++){ |
189 |
| - var partialKey = currentPattern.getPartialKey(foundPatternPartials[i]); |
190 |
| - |
191 |
| - var partialPath; |
192 |
| - |
193 |
| - //identify which pattern this partial corresponds to |
194 |
| - for(var j = 0; j < patternlab.patterns.length; j++){ |
195 |
| - if(patternlab.patterns[j].key === partialKey || |
196 |
| - patternlab.patterns[j].abspath.indexOf(partialKey) > -1) |
197 |
| - { |
198 |
| - partialPath = patternlab.patterns[j].abspath; |
199 |
| - } |
200 |
| - } |
| 212 | + //find any listItem blocks that within the pattern, even if there are no partials |
| 213 | + list_item_hunter.process_list_item_partials(currentPattern, patternlab); |
201 | 214 |
|
202 |
| - //recurse through nested partials to fill out this extended template. |
203 |
| - processPatternRecursive(partialPath, patternlab); |
204 |
| - |
205 |
| - //complete assembly of extended template |
206 |
| - var partialPattern = getpatternbykey(partialKey, patternlab); |
207 |
| - |
208 |
| - //if partial has style modifier data, replace the styleModifier value |
209 |
| - if(currentPattern.stylePartials && currentPattern.stylePartials.length > 0){ |
210 |
| - style_modifier_hunter.consume_style_modifier(partialPattern, foundPatternPartials[i], patternlab); |
211 |
| - } |
212 |
| - |
213 |
| - currentPattern.extendedTemplate = currentPattern.extendedTemplate.replace(foundPatternPartials[i], partialPattern.extendedTemplate); |
214 |
| - |
215 |
| - } |
216 |
| - |
217 |
| - } else{ |
218 |
| - //find any listItem blocks that within the pattern, even if there are no partials |
219 |
| - list_item_hunter.process_list_item_partials(currentPattern, patternlab); |
| 215 | + // expand any partials present in this pattern; that is, drill down into the template and replace their calls in this template with rendered results |
| 216 | + if (currentPattern.engine.expandPartials && (foundPatternPartials !== null && foundPatternPartials.length > 0)) { |
| 217 | + expandPartials(foundPatternPartials, list_item_hunter, patternlab, currentPattern); |
220 | 218 | }
|
221 | 219 |
|
222 | 220 | //find pattern lineage
|
|
0 commit comments