|
1 | 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 | | - */ |
| 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"; |
|
19 | 19 | mustache = require('mustache'), |
20 | 20 | pattern_assembler = new pa(), |
21 | 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']; |
| 22 | + items = [ 'zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen','twenty']; |
23 | 23 |
|
24 | 24 | function processListItemPartials(pattern, patternlab){ |
25 | | - //find any listitem blocks |
26 | | - var matches = pattern_assembler.find_list_items(pattern, patternlab); |
| 25 | + //find any listitem blocks |
| 26 | + var matches = pattern_assembler.find_list_items(pattern, patternlab); |
27 | 27 | if(matches !== null){ |
28 | 28 | matches.forEach(function(liMatch, index, matches){ |
29 | 29 |
|
30 | | - if(patternlab.config.debug){ |
31 | | - console.log('found listItem of size ' + liMatch + ' inside ' + pattern.key); |
32 | | - } |
| 30 | + if(patternlab.config.debug){ |
| 31 | + console.log('found listItem of size ' + liMatch + ' inside ' + pattern.key); |
| 32 | + } |
33 | 33 |
|
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(); |
| 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(); |
38 | 38 |
|
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 | | - } |
| 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 | + } |
45 | 45 |
|
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); |
| 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); |
49 | 49 |
|
50 | | - //iterate over each copied block, rendering its contents along with pattenlab.listitems[i] |
51 | | - 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++){ |
52 | 52 |
|
53 | | - var thisBlockTemplate = repeatedBlockTemplate[i]; |
54 | | - var thisBlockHTML = ""; |
| 53 | + var thisBlockTemplate = repeatedBlockTemplate[i]; |
| 54 | + var thisBlockHTML = ""; |
55 | 55 |
|
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)); |
| 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)); |
60 | 60 |
|
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); |
| 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); |
64 | 64 |
|
65 | | - //check for partials within the repeated block |
66 | | - 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 }); |
67 | 67 |
|
68 | | - if(foundPartials && foundPartials.length > 0){ |
| 68 | + if(foundPartials && foundPartials.length > 0){ |
69 | 69 |
|
70 | | - for(var j = 0; j < foundPartials.length; j++){ |
| 70 | + for(var j = 0; j < foundPartials.length; j++){ |
71 | 71 |
|
72 | | - //get the partial |
73 | | - var partialName = foundPartials[j].match(/([\w\-\.\/~]+)/g)[0]; |
74 | | - 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); |
75 | 75 |
|
76 | 76 | //if partial has style modifier data, replace the styleModifier value |
77 | 77 | if(pattern.stylePartials && pattern.stylePartials.length > 0){ |
78 | 78 | style_modifier_hunter.consume_style_modifier(partialPattern, foundPartials[j], patternlab); |
79 | 79 | } |
80 | 80 |
|
81 | | - //replace its reference within the block with the extended template |
82 | | - thisBlockTemplate = thisBlockTemplate.replace(foundPartials[j], partialPattern.extendedTemplate); |
83 | | - } |
| 81 | + //replace its reference within the block with the extended template |
| 82 | + thisBlockTemplate = thisBlockTemplate.replace(foundPartials[j], partialPattern.extendedTemplate); |
| 83 | + } |
84 | 84 |
|
85 | | - //render with data |
86 | | - thisBlockHTML = pattern_assembler.renderPattern(thisBlockTemplate, allData, patternlab.partials); |
| 85 | + //render with data |
| 86 | + thisBlockHTML = pattern_assembler.renderPattern(thisBlockTemplate, allData, patternlab.partials); |
87 | 87 |
|
88 | | - } else{ |
89 | | - //just render with mergedData |
90 | | - thisBlockHTML = pattern_assembler.renderPattern(thisBlockTemplate, allData, patternlab.partials); |
91 | | - } |
| 88 | + } else{ |
| 89 | + //just render with mergedData |
| 90 | + thisBlockHTML = pattern_assembler.renderPattern(thisBlockTemplate, allData, patternlab.partials); |
| 91 | + } |
92 | 92 |
|
93 | | - //add the rendered HTML to our string |
94 | | - repeatedBlockHtml = repeatedBlockHtml + thisBlockHTML; |
95 | | - } |
| 93 | + //add the rendered HTML to our string |
| 94 | + repeatedBlockHtml = repeatedBlockHtml + thisBlockHTML; |
| 95 | + } |
96 | 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); |
| 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); |
100 | 100 |
|
101 | 101 | }); |
102 | 102 | } |
|
0 commit comments