diff --git a/CHANGELOG b/CHANGELOG index f0c3788c7..b17f7fbdb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ PL-node-v1.0.1 - FIX: Fix issue where excluded patterns were still rendered on the Pattern Lab site. Now they do not directly get rendered via the menu, view all links, or the styleguide, but are accessible for inclusion as pattern partials, and can be accessed via lineage. - THX: Thanks @theorise for reporting these issues. - THX: Thanks @dmolsen for input on desired behavior. +- FIX: Fix issue where style modifier partials within list item blocks where not uniquely being applied. this seems like a regression. added a unit test with fix PL-node-v1.0.0 - FIX: Resolve issue with not hiding underscored patterns. diff --git a/builder/list_item_hunter.js b/builder/list_item_hunter.js index 15d51b0e8..ddadeeb64 100644 --- a/builder/list_item_hunter.js +++ b/builder/list_item_hunter.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v1.0.1 - 2015 - * +/* + * patternlab-node - v1.0.1 - 2015 + * * Brian Muenzenmeyer, and the web community. - * Licensed under the MIT license. - * - * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. + * Licensed under the MIT license. + * + * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. * */ @@ -72,13 +72,16 @@ var partialName = foundPartials[j].match(/([\w\-\.\/~]+)/g)[0]; var partialPattern = pattern_assembler.get_pattern_by_key(partialName, patternlab); + //create a copy of the partial so as to not pollute it after the get_pattern_by_key call. + var cleanPartialPattern = JSON.parse(JSON.stringify(partialPattern)); + //if partial has style modifier data, replace the styleModifier value - if(pattern.stylePartials && pattern.stylePartials.length > 0){ - style_modifier_hunter.consume_style_modifier(partialPattern, foundPartials[j], patternlab); + if(foundPartials[j].indexOf(':') > -1){ + style_modifier_hunter.consume_style_modifier(cleanPartialPattern, foundPartials[j], patternlab); } //replace its reference within the block with the extended template - thisBlockTemplate = thisBlockTemplate.replace(foundPartials[j], partialPattern.extendedTemplate); + thisBlockTemplate = thisBlockTemplate.replace(foundPartials[j], cleanPartialPattern.extendedTemplate); } //render with data diff --git a/test/files/_patterns/00-test/11-bookend-listitem.mustache b/test/files/_patterns/00-test/11-bookend-listitem.mustache new file mode 100644 index 000000000..816c37c92 --- /dev/null +++ b/test/files/_patterns/00-test/11-bookend-listitem.mustache @@ -0,0 +1,7 @@ +
+ {{#listItems.two}} + {{> test-styled-atom }} + {{> test-styled-atom:test_1 }} + {{> test-styled-atom}} + {{/listItems.two}} +
diff --git a/test/list_item_hunter_tests.js b/test/list_item_hunter_tests.js index d2de41468..eaed526b3 100644 --- a/test/list_item_hunter_tests.js +++ b/test/list_item_hunter_tests.js @@ -2,6 +2,8 @@ "use strict"; var lih = require('../builder/list_item_hunter'); + var pa = require('../builder/pattern_assembler'); + var object_factory = require('../builder/object_factory'); exports['list_item_hunter'] = { 'process_list_item_partials finds and outputs basic repeating blocks' : function(test){ @@ -394,6 +396,58 @@ //assert test.equals(currentPattern.extendedTemplate, "One" ); + test.done(); + }, + + 'process_list_item_partials - correctly ignores bookended partials without a style modifier when the same partial has a style modifier between' : function(test){ + //arrange + var fs = require('fs-extra'); + var pattern_assembler = new pa(); + var list_item_hunter = new lih(); + var patterns_dir = './test/files/_patterns'; + + var pl = {}; + pl.config = {}; + pl.data = {}; + pl.data.link = {}; + pl.config.debug = false; + pl.patterns = []; + pl.config.patterns = { source: patterns_dir}; + pl.listitems = { + "1": [ + { + "message": "Foo" + } + ], + "2": [ + { + "message": "Foo" + }, + { + "message": "Bar" + } + ] + }; + + var atomPattern = new object_factory.oPattern('test/files/_patterns/00-test/03-styled-atom.mustache', '00-test', '03-styled-atom.mustache'); + atomPattern.template = fs.readFileSync(patterns_dir + '/00-test/03-styled-atom.mustache', 'utf8'); + atomPattern.extendedTemplate = atomPattern.template; + atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern); + + var bookendPattern = new object_factory.oPattern('test/files/_patterns/00-test/11-bookend-listitem.mustache', '00-test', '11-bookend-listitem.mustache'); + bookendPattern.template = fs.readFileSync(patterns_dir + '/00-test/11-bookend-listitem.mustache', 'utf8'); + bookendPattern.extendedTemplate = bookendPattern.template; + bookendPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(bookendPattern); + + pl.patterns.push(atomPattern); + pl.patterns.push(bookendPattern); + + //act + list_item_hunter.process_list_item_partials(bookendPattern, pl); + + //assert. here we expect {{styleModifier}} to be replaced with an empty string or the styleModifier value from the found partial with the :styleModifier + var expectedValue = '
Foo Foo Foo Bar Bar Bar
'; + test.equals(bookendPattern.extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), expectedValue.trim()); test.done(); }