|
1 | 1 | /*
|
2 |
| - * patternlab-node - v0.13.0 - 2015 |
| 2 | + * patternlab-node - v0.14.0 - 2015 |
3 | 3 | *
|
4 | 4 | * Brian Muenzenmeyer, and the web community.
|
5 | 5 | * Licensed under the MIT license.
|
|
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(); |
| 38 | + //build arrays that repeat the block, however large we need to |
| 39 | + var repeatedBlockTemplate = []; |
| 40 | + var repeatedBlockHtml = ''; |
| 41 | + for(var i = 0; i < items.indexOf(loopNumberString); i++){ |
| 42 | + repeatedBlockTemplate.push(patternBlock); |
| 43 | + } |
36 | 44 |
|
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 |
| - } |
| 45 | + //check for a local listitems.json file |
| 46 | + var listData = JSON.parse(JSON.stringify(patternlab.listitems)); |
| 47 | + listData = pattern_assembler.merge_data(listData, pattern.listitems); |
43 | 48 |
|
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); |
| 49 | + //iterate over each copied block, rendering its contents along with pattenlab.listitems[i] |
| 50 | + for(var i = 0; i < repeatedBlockTemplate.length; i++){ |
47 | 51 |
|
48 |
| - //iterate over each copied block, rendering its contents along with pattenlab.listitems[i] |
49 |
| - for(var i = 0; i < repeatedBlockTemplate.length; i++){ |
| 52 | + var thisBlockTemplate = repeatedBlockTemplate[i]; |
| 53 | + var thisBlockHTML = ""; |
50 | 54 |
|
51 |
| - var thisBlockTemplate = repeatedBlockTemplate[i]; |
52 |
| - var thisBlockHTML = ""; |
| 55 | + //combine listItem data with pattern data with global data |
| 56 | + var itemData = listData['' + items.indexOf(loopNumberString)]; //this is a property like "2" |
| 57 | + var globalData = JSON.parse(JSON.stringify(patternlab.data)); |
| 58 | + var localData = JSON.parse(JSON.stringify(pattern.jsonFileData)); |
53 | 59 |
|
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)); |
| 60 | + var allData = pattern_assembler.merge_data(globalData, localData); |
| 61 | + allData = pattern_assembler.merge_data(allData, itemData != undefined ? itemData[i] : {}); //itemData could be undefined if the listblock contains no partial, just markup |
| 62 | + allData.link = extend({}, patternlab.data.link); |
58 | 63 |
|
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); |
| 64 | + //check for partials within the repeated block |
| 65 | + var foundPartials = pattern_assembler.find_pattern_partials({ 'template' : thisBlockTemplate }); |
62 | 66 |
|
63 |
| - //check for partials within the repeated block |
64 |
| - var foundPartials = pattern_assembler.find_pattern_partials({ 'template' : thisBlockTemplate }); |
| 67 | + if(foundPartials && foundPartials.length > 0){ |
65 | 68 |
|
66 |
| - if(foundPartials && foundPartials.length > 0){ |
| 69 | + for(var j = 0; j < foundPartials.length; j++){ |
67 | 70 |
|
68 |
| - for(var j = 0; j < foundPartials.length; j++){ |
| 71 | + //get the partial |
| 72 | + var partialName = foundPartials[j].match(/([\w\-\.\/~]+)/g)[0]; |
| 73 | + var partialPattern = pattern_assembler.get_pattern_by_key(partialName, patternlab); |
69 | 74 |
|
70 |
| - //get the partial |
71 |
| - var partialName = foundPartials[j].match(/([\w\-\.\/~]+)/g)[0]; |
72 |
| - var partialPattern = pattern_assembler.get_pattern_by_key(partialName, patternlab); |
| 75 | + //if partial has style modifier data, replace the styleModifier value |
| 76 | + if(pattern.stylePartials && pattern.stylePartials.length > 0){ |
| 77 | + style_modifier_hunter.consume_style_modifier(partialPattern, foundPartials[j], patternlab); |
| 78 | + } |
73 | 79 |
|
74 |
| - //replace its reference within the block with the extended template |
75 |
| - thisBlockTemplate = thisBlockTemplate.replace(foundPartials[j], partialPattern.extendedTemplate); |
76 |
| - } |
| 80 | + //replace its reference within the block with the extended template |
| 81 | + thisBlockTemplate = thisBlockTemplate.replace(foundPartials[j], partialPattern.extendedTemplate); |
| 82 | + } |
77 | 83 |
|
78 |
| - //render with data |
79 |
| - thisBlockHTML = pattern_assembler.renderPattern(thisBlockTemplate, allData, patternlab.partials); |
| 84 | + //render with data |
| 85 | + thisBlockHTML = pattern_assembler.renderPattern(thisBlockTemplate, allData, patternlab.partials); |
80 | 86 |
|
81 |
| - } else{ |
82 |
| - //just render with mergedData |
83 |
| - thisBlockHTML = pattern_assembler.renderPattern(thisBlockTemplate, allData, patternlab.partials); |
84 |
| - } |
| 87 | + } else{ |
| 88 | + //just render with mergedData |
| 89 | + thisBlockHTML = pattern_assembler.renderPattern(thisBlockTemplate, allData, patternlab.partials); |
| 90 | + } |
85 | 91 |
|
86 |
| - //add the rendered HTML to our string |
87 |
| - repeatedBlockHtml = repeatedBlockHtml + thisBlockHTML; |
88 |
| - } |
| 92 | + //add the rendered HTML to our string |
| 93 | + repeatedBlockHtml = repeatedBlockHtml + thisBlockHTML; |
| 94 | + } |
89 | 95 |
|
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); |
| 96 | + //replace the block with our generated HTML |
| 97 | + var repeatingBlock = pattern.extendedTemplate.substring(pattern.extendedTemplate.indexOf(liMatch), pattern.extendedTemplate.indexOf(end) + end.length); |
| 98 | + pattern.extendedTemplate = pattern.extendedTemplate.replace(repeatingBlock, repeatedBlockHtml); |
93 | 99 |
|
94 | 100 | });
|
95 | 101 | }
|
|
0 commit comments