Skip to content

Commit ea6c625

Browse files
author
Brian Muenzenmeyer
committed
Merge pull request #218 from pattern-lab/190
Issue 190
2 parents bf8cc0d + a972335 commit ea6c625

File tree

4 files changed

+74
-9
lines changed

4 files changed

+74
-9
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ PL-node-v1.0.1
55
- 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.
66
- THX: Thanks @theorise for reporting these issues.
77
- THX: Thanks @dmolsen for input on desired behavior.
8+
- 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
89

910
PL-node-v1.0.0
1011
- FIX: Resolve issue with not hiding underscored patterns.

builder/list_item_hunter.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/*
2-
* patternlab-node - v1.0.1 - 2015
3-
*
1+
/*
2+
* patternlab-node - v1.0.1 - 2015
3+
*
44
* 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.
5+
* Licensed under the MIT license.
6+
*
7+
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
88
*
99
*/
1010

@@ -72,13 +72,16 @@
7272
var partialName = foundPartials[j].match(/([\w\-\.\/~]+)/g)[0];
7373
var partialPattern = pattern_assembler.get_pattern_by_key(partialName, patternlab);
7474

75+
//create a copy of the partial so as to not pollute it after the get_pattern_by_key call.
76+
var cleanPartialPattern = JSON.parse(JSON.stringify(partialPattern));
77+
7578
//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);
79+
if(foundPartials[j].indexOf(':') > -1){
80+
style_modifier_hunter.consume_style_modifier(cleanPartialPattern, foundPartials[j], patternlab);
7881
}
7982

8083
//replace its reference within the block with the extended template
81-
thisBlockTemplate = thisBlockTemplate.replace(foundPartials[j], partialPattern.extendedTemplate);
84+
thisBlockTemplate = thisBlockTemplate.replace(foundPartials[j], cleanPartialPattern.extendedTemplate);
8285
}
8386

8487
//render with data
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div class="test_group">
2+
{{#listItems.two}}
3+
{{> test-styled-atom }}
4+
{{> test-styled-atom:test_1 }}
5+
{{> test-styled-atom}}
6+
{{/listItems.two}}
7+
</div>

test/list_item_hunter_tests.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"use strict";
33

44
var lih = require('../builder/list_item_hunter');
5+
var pa = require('../builder/pattern_assembler');
6+
var object_factory = require('../builder/object_factory');
57

68
exports['list_item_hunter'] = {
79
'process_list_item_partials finds and outputs basic repeating blocks' : function(test){
@@ -394,6 +396,58 @@
394396
//assert
395397
test.equals(currentPattern.extendedTemplate, "One" );
396398

399+
test.done();
400+
},
401+
402+
'process_list_item_partials - correctly ignores bookended partials without a style modifier when the same partial has a style modifier between' : function(test){
403+
//arrange
404+
var fs = require('fs-extra');
405+
var pattern_assembler = new pa();
406+
var list_item_hunter = new lih();
407+
var patterns_dir = './test/files/_patterns';
408+
409+
var pl = {};
410+
pl.config = {};
411+
pl.data = {};
412+
pl.data.link = {};
413+
pl.config.debug = false;
414+
pl.patterns = [];
415+
pl.config.patterns = { source: patterns_dir};
416+
pl.listitems = {
417+
"1": [
418+
{
419+
"message": "Foo"
420+
}
421+
],
422+
"2": [
423+
{
424+
"message": "Foo"
425+
},
426+
{
427+
"message": "Bar"
428+
}
429+
]
430+
};
431+
432+
var atomPattern = new object_factory.oPattern('test/files/_patterns/00-test/03-styled-atom.mustache', '00-test', '03-styled-atom.mustache');
433+
atomPattern.template = fs.readFileSync(patterns_dir + '/00-test/03-styled-atom.mustache', 'utf8');
434+
atomPattern.extendedTemplate = atomPattern.template;
435+
atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern);
436+
437+
var bookendPattern = new object_factory.oPattern('test/files/_patterns/00-test/11-bookend-listitem.mustache', '00-test', '11-bookend-listitem.mustache');
438+
bookendPattern.template = fs.readFileSync(patterns_dir + '/00-test/11-bookend-listitem.mustache', 'utf8');
439+
bookendPattern.extendedTemplate = bookendPattern.template;
440+
bookendPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(bookendPattern);
441+
442+
pl.patterns.push(atomPattern);
443+
pl.patterns.push(bookendPattern);
444+
445+
//act
446+
list_item_hunter.process_list_item_partials(bookendPattern, pl);
447+
448+
//assert. here we expect {{styleModifier}} to be replaced with an empty string or the styleModifier value from the found partial with the :styleModifier
449+
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>';
450+
test.equals(bookendPattern.extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), expectedValue.trim());
397451
test.done();
398452
}
399453

0 commit comments

Comments
 (0)