Skip to content

Commit 0307ab3

Browse files
committed
Merge branch 'dev' into fuzzy-patterns
2 parents 980118f + ea6c625 commit 0307ab3

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){
@@ -396,6 +398,58 @@
396398
//assert
397399
test.equals(currentPattern.extendedTemplate, "One" );
398400

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

0 commit comments

Comments
 (0)