|
1 |
| -/* |
2 |
| - * patternlab-node - v0.13.0 - 2015 |
3 |
| - * |
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. |
8 |
| - * |
9 |
| - */ |
| 1 | +/* |
| 2 | +* patternlab-node - v0.14.0 - 2015 |
| 3 | +* |
| 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. |
| 8 | +* |
| 9 | +*/ |
10 | 10 |
|
11 | 11 | (function () {
|
12 | 12 | "use strict";
|
|
15 | 15 |
|
16 | 16 | var extend = require('util')._extend,
|
17 | 17 | pa = require('./pattern_assembler'),
|
| 18 | + smh = require('./style_modifier_hunter'), |
18 | 19 | mustache = require('mustache'),
|
19 | 20 | pattern_assembler = new pa(),
|
20 |
| - items = [ 'zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen','twenty']; |
| 21 | + style_modifier_hunter = new smh(), |
| 22 | + items = [ 'zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen','twenty']; |
21 | 23 |
|
22 | 24 | function processListItemPartials(pattern, patternlab){
|
23 |
| - //find any listitem blocks |
24 |
| - var matches = pattern_assembler.find_list_items(pattern, patternlab); |
| 25 | + //find any listitem blocks |
| 26 | + var matches = pattern_assembler.find_list_items(pattern, patternlab); |
25 | 27 | if(matches !== null){
|
26 | 28 | matches.forEach(function(liMatch, index, matches){
|
27 | 29 |
|
28 |
| - if(patternlab.config.debug){ |
29 |
| - console.log('found listItem of size ' + liMatch + ' inside ' + pattern.key); |
30 |
| - } |
| 30 | + if(patternlab.config.debug){ |
| 31 | + console.log('found listItem of size ' + liMatch + ' inside ' + pattern.key); |
| 32 | + } |
31 | 33 |
|
32 |
| - //find the boundaries of the block |
33 |
| - var loopNumberString = liMatch.split('.')[1].split('}')[0].trim(); |
34 |
| - var end = liMatch.replace('#', '/'); |
35 |
| - var patternBlock = pattern.template.substring(pattern.template.indexOf(liMatch) + liMatch.length, pattern.template.indexOf(end)).trim(); |
| 34 | + //find the boundaries of the block |
| 35 | + var loopNumberString = liMatch.split('.')[1].split('}')[0].trim(); |
| 36 | + var end = liMatch.replace('#', '/'); |
| 37 | + var patternBlock = pattern.template.substring(pattern.template.indexOf(liMatch) + liMatch.length, pattern.template.indexOf(end)).trim(); |
36 | 38 |
|
37 |
| - //build arrays that repeat the block, however large we need to |
38 |
| - var repeatedBlockTemplate = []; |
39 |
| - var repeatedBlockHtml = ''; |
40 |
| - for(var i = 0; i < items.indexOf(loopNumberString); i++){ |
41 |
| - repeatedBlockTemplate.push(patternBlock); |
42 |
| - } |
| 39 | + //build arrays that repeat the block, however large we need to |
| 40 | + var repeatedBlockTemplate = []; |
| 41 | + var repeatedBlockHtml = ''; |
| 42 | + for(var i = 0; i < items.indexOf(loopNumberString); i++){ |
| 43 | + repeatedBlockTemplate.push(patternBlock); |
| 44 | + } |
43 | 45 |
|
44 |
| - //check for a local listitems.json file |
45 |
| - var listData = JSON.parse(JSON.stringify(patternlab.listitems)); |
46 |
| - listData = pattern_assembler.merge_data(listData, pattern.patternSpecificListJson); |
| 46 | + //check for a local listitems.json file |
| 47 | + var listData = JSON.parse(JSON.stringify(patternlab.listitems)); |
| 48 | + listData = pattern_assembler.merge_data(listData, pattern.patternSpecificListJson); |
47 | 49 |
|
48 |
| - //iterate over each copied block, rendering its contents along with pattenlab.listitems[i] |
49 |
| - for(var i = 0; i < repeatedBlockTemplate.length; i++){ |
| 50 | + //iterate over each copied block, rendering its contents along with pattenlab.listitems[i] |
| 51 | + for(var i = 0; i < repeatedBlockTemplate.length; i++){ |
50 | 52 |
|
51 |
| - var thisBlockTemplate = repeatedBlockTemplate[i]; |
52 |
| - var thisBlockHTML = ""; |
| 53 | + var thisBlockTemplate = repeatedBlockTemplate[i]; |
| 54 | + var thisBlockHTML = ""; |
53 | 55 |
|
54 |
| - //combine listItem data with pattern data with global data |
55 |
| - var itemData = listData['' + items.indexOf(loopNumberString)]; //this is a property like "2" |
56 |
| - var globalData = JSON.parse(JSON.stringify(patternlab.data)); |
57 |
| - var localData = JSON.parse(JSON.stringify(pattern.jsonFileData)); |
| 56 | + //combine listItem data with pattern data with global data |
| 57 | + var itemData = listData['' + items.indexOf(loopNumberString)]; //this is a property like "2" |
| 58 | + var globalData = JSON.parse(JSON.stringify(patternlab.data)); |
| 59 | + var localData = JSON.parse(JSON.stringify(pattern.jsonFileData)); |
58 | 60 |
|
59 |
| - var allData = pattern_assembler.merge_data(globalData, localData); |
60 |
| - allData = pattern_assembler.merge_data(allData, itemData[i]); |
61 |
| - allData.link = extend({}, patternlab.data.link); |
| 61 | + var allData = pattern_assembler.merge_data(globalData, localData); |
| 62 | + allData = pattern_assembler.merge_data(allData, itemData[i]); |
| 63 | + allData.link = extend({}, patternlab.data.link); |
62 | 64 |
|
63 |
| - //check for partials within the repeated block |
64 |
| - var foundPartials = pattern_assembler.find_pattern_partials({ 'template' : thisBlockTemplate }); |
| 65 | + //check for partials within the repeated block |
| 66 | + var foundPartials = pattern_assembler.find_pattern_partials({ 'template' : thisBlockTemplate }); |
65 | 67 |
|
66 |
| - if(foundPartials && foundPartials.length > 0){ |
| 68 | + if(foundPartials && foundPartials.length > 0){ |
67 | 69 |
|
68 |
| - for(var j = 0; j < foundPartials.length; j++){ |
| 70 | + for(var j = 0; j < foundPartials.length; j++){ |
69 | 71 |
|
70 |
| - //get the partial |
71 |
| - var partialName = foundPartials[j].match(/([\w\-\.\/~]+)/g)[0]; |
72 |
| - var partialPattern = pattern_assembler.get_pattern_by_key(partialName, patternlab); |
| 72 | + //get the partial |
| 73 | + var partialName = foundPartials[j].match(/([\w\-\.\/~]+)/g)[0]; |
| 74 | + var partialPattern = pattern_assembler.get_pattern_by_key(partialName, patternlab); |
73 | 75 |
|
74 |
| - //replace its reference within the block with the extended template |
75 |
| - thisBlockTemplate = thisBlockTemplate.replace(foundPartials[j], partialPattern.extendedTemplate); |
76 |
| - } |
| 76 | + //if partial has style modifier data, replace the styleModifier value |
| 77 | + if(pattern.stylePartials && pattern.stylePartials.length > 0){ |
| 78 | + style_modifier_hunter.consume_style_modifier(partialPattern, foundPartials[j], patternlab); |
| 79 | + } |
77 | 80 |
|
78 |
| - //render with data |
79 |
| - thisBlockHTML = pattern_assembler.renderPattern(thisBlockTemplate, allData, patternlab.partials); |
| 81 | + //replace its reference within the block with the extended template |
| 82 | + thisBlockTemplate = thisBlockTemplate.replace(foundPartials[j], partialPattern.extendedTemplate); |
| 83 | + } |
80 | 84 |
|
81 |
| - } else{ |
82 |
| - //just render with mergedData |
83 |
| - thisBlockHTML = pattern_assembler.renderPattern(thisBlockTemplate, allData, patternlab.partials); |
84 |
| - } |
| 85 | + //render with data |
| 86 | + thisBlockHTML = pattern_assembler.renderPattern(thisBlockTemplate, allData, patternlab.partials); |
85 | 87 |
|
86 |
| - //add the rendered HTML to our string |
87 |
| - repeatedBlockHtml = repeatedBlockHtml + thisBlockHTML; |
88 |
| - } |
| 88 | + } else{ |
| 89 | + //just render with mergedData |
| 90 | + thisBlockHTML = pattern_assembler.renderPattern(thisBlockTemplate, allData, patternlab.partials); |
| 91 | + } |
89 | 92 |
|
90 |
| - //replace the block with our generated HTML |
91 |
| - var repeatingBlock = pattern.extendedTemplate.substring(pattern.extendedTemplate.indexOf(liMatch), pattern.extendedTemplate.indexOf(end) + end.length); |
92 |
| - pattern.extendedTemplate = pattern.extendedTemplate.replace(repeatingBlock, repeatedBlockHtml); |
| 93 | + //add the rendered HTML to our string |
| 94 | + repeatedBlockHtml = repeatedBlockHtml + thisBlockHTML; |
| 95 | + } |
| 96 | + |
| 97 | + //replace the block with our generated HTML |
| 98 | + var repeatingBlock = pattern.extendedTemplate.substring(pattern.extendedTemplate.indexOf(liMatch), pattern.extendedTemplate.indexOf(end) + end.length); |
| 99 | + pattern.extendedTemplate = pattern.extendedTemplate.replace(repeatingBlock, repeatedBlockHtml); |
93 | 100 |
|
94 | 101 | });
|
95 | 102 | }
|
|
0 commit comments