Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 12 additions & 9 deletions builder/list_item_hunter.js
Original file line number Diff line number Diff line change
@@ -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.
*
*/

Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/files/_patterns/00-test/11-bookend-listitem.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="test_group">
{{#listItems.two}}
{{> test-styled-atom }}
{{> test-styled-atom:test_1 }}
{{> test-styled-atom}}
{{/listItems.two}}
</div>
54 changes: 54 additions & 0 deletions test/list_item_hunter_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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 = '<div class="test_group"> <span class="test_base "> Foo </span> <span class="test_base test_1"> Foo </span> <span class="test_base "> Foo </span> <span class="test_base "> Bar </span> <span class="test_base test_1"> Bar </span> <span class="test_base "> Bar </span> </div>';
test.equals(bookendPattern.extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), expectedValue.trim());
test.done();
}

Expand Down