Skip to content
This repository was archived by the owner on Dec 10, 2019. It is now read-only.

Commit 9cd187b

Browse files
committed
additional tests to cover styleModifier / pattern Parameter relationship
fixes #190
1 parent ffc80cb commit 9cd187b

File tree

6 files changed

+127
-6
lines changed

6 files changed

+127
-6
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ THIS CHANGELOG IS AN ATTEMPT TO DOCUMENT CHANGES TO THIS PROJECT.
33
PL-node-v0.15.1
44
- FIX: Resolve issue with styleModifiers not being replaced when the partial has spaces in it.
55
- ADD: Support multiple styleModifier classes using the | pipe syntax
6+
- FIX: Resolve issue with styleModifiers not being applied correctly when mixed with pattern parameters
67
- THX: Thanks @theorise for the issue reports!
78

89
PL-node-v0.15.0

builder/parameter_hunter.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/*
2-
* patternlab-node - v0.15.1 - 2015
3-
*
1+
/*
2+
* patternlab-node - v0.15.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

@@ -28,6 +28,8 @@
2828
//find the partial's name and retrieve it
2929
var partialName = pMatch.match(/([\w\-\.\/~]+)/g)[0];
3030
var partialPattern = pattern_assembler.get_pattern_by_key(partialName, patternlab);
31+
//if we retrieved a pattern we should make sure that its extendedTemplate is reset. looks to fix #190
32+
partialPattern.extendedTemplate = partialPattern.template;
3133

3234
if(patternlab.config.debug){
3335
console.log('found patternParameters for ' + partialName);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div class="test_group">
2+
{{> test-styled-atom }}
3+
{{> test-styled-atom:test_2(message: '2') }}
4+
{{> test-styled-atom:test_3(message: '3') }}
5+
{{> test-styled-atom:test_4(message: '4') }}
6+
</div>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div class="test_group">
2+
{{> test-styled-atom }}
3+
{{> test-styled-atom:test_2(message: '2') }}
4+
{{> test-styled-atom:test_3(message: '3') }}
5+
{{> test-styled-atom }}
6+
</div>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div class="test_group">
2+
{{> test-styled-atom }}
3+
{{> test-styled-atom:test_2 }}
4+
{{> test-styled-atom:test_3 }}
5+
{{> test-styled-atom}}
6+
</div>

test/pattern_assembler_tests.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,106 @@
349349
var expectedValue = '<div class="test_group"> <span class="test_base {{styleModifier}}"> {{message}} </span> <span class="test_base test_2"> {{message}} </span> <span class="test_base test_3"> {{message}} </span> <span class="test_base test_4"> {{message}} </span> </div>';
350350
test.equals(mixedPattern.extendedTemplate.replace(/\s\s+/g, ' ').trim(), expectedValue.trim());
351351
test.done();
352+
},
353+
'processPatternRecursive - correctly ignores bookended partials without a style modifier when the same partial has a style modifier between' : function(test){
354+
//arrange
355+
var fs = require('fs-extra');
356+
var pattern_assembler = new pa();
357+
358+
var pl = {};
359+
pl.config = {};
360+
pl.data = {};
361+
pl.data.link = {};
362+
pl.config.debug = false;
363+
pl.patterns = [];
364+
var patterns_dir = './test/files/_patterns';
365+
366+
var atomPattern = new object_factory.oPattern('test/files/_patterns/00-test/03-styled-atom.mustache', '00-test', '03-styled-atom.mustache');
367+
atomPattern.template = fs.readFileSync(patterns_dir + '/00-test/03-styled-atom.mustache', 'utf8');
368+
atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern);
369+
370+
var bookendPattern = new object_factory.oPattern('test/files/_patterns/00-test/09-bookend.mustache', '00-test', '09-bookend.mustache');
371+
bookendPattern.template = fs.readFileSync(patterns_dir + '/00-test/09-bookend.mustache', 'utf8');
372+
bookendPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(bookendPattern);
373+
374+
pl.patterns.push(atomPattern);
375+
pl.patterns.push(bookendPattern);
376+
377+
//act
378+
pattern_assembler.process_pattern_recursive('test/files/_patterns/00-test/09-bookend.mustache', pl, {});
379+
380+
//assert. here we expect {{styleModifier}} to be in the first and last group, since it was not replaced by anything. rendering with data will then remove this (correctly)
381+
var expectedValue = '<div class="test_group"> <span class="test_base {{styleModifier}}"> {{message}} </span> <span class="test_base test_2"> {{message}} </span> <span class="test_base test_3"> {{message}} </span> <span class="test_base {{styleModifier}}"> {{message}} </span> </div>';
382+
test.equals(bookendPattern.extendedTemplate.replace(/\s\s+/g, ' ').trim(), expectedValue.trim());
383+
test.done();
384+
},
385+
'processPatternRecursive - correctly ignores a partial without a style modifier when the same partial later has a style modifier and pattern parameters' : function(test){
386+
//arrange
387+
var fs = require('fs-extra');
388+
var pattern_assembler = new pa();
389+
390+
var pl = {};
391+
pl.config = {};
392+
pl.data = {};
393+
pl.data.link = {};
394+
pl.config.debug = false;
395+
pl.patterns = [];
396+
var patterns_dir = './test/files/_patterns';
397+
398+
var atomPattern = new object_factory.oPattern('test/files/_patterns/00-test/03-styled-atom.mustache', '00-test', '03-styled-atom.mustache');
399+
atomPattern.template = fs.readFileSync(patterns_dir + '/00-test/03-styled-atom.mustache', 'utf8');
400+
atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern);
401+
atomPattern.parameteredPartials = pattern_assembler.find_pattern_partials_with_parameters(atomPattern);
402+
403+
var mixedPattern = new object_factory.oPattern('test/files/_patterns/00-test/07-mixed-params.mustache', '00-test', '07-mixed-params.mustache');
404+
mixedPattern.template = fs.readFileSync(patterns_dir + '/00-test/07-mixed-params.mustache', 'utf8');
405+
mixedPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(mixedPattern);
406+
mixedPattern.parameteredPartials = pattern_assembler.find_pattern_partials_with_parameters(mixedPattern);
407+
408+
pl.patterns.push(atomPattern);
409+
pl.patterns.push(mixedPattern);
410+
411+
//act
412+
pattern_assembler.process_pattern_recursive('test/files/_patterns/00-test/07-mixed-params.mustache', pl, {});
413+
414+
//assert. here we expect {{styleModifier}} to be in the first span, since it was not replaced by anything. rendering with data will then remove this (correctly)
415+
var expectedValue = '<div class="test_group"> <span class="test_base {{styleModifier}}"> {{message}} </span> <span class="test_base test_2"> 2 </span> <span class="test_base test_3"> 3 </span> <span class="test_base test_4"> 4 </span> </div>';
416+
test.equals(mixedPattern.extendedTemplate.replace(/\s\s+/g, ' ').trim(), expectedValue.trim());
417+
test.done();
418+
},
419+
'processPatternRecursive - correctly ignores bookended partials without a style modifier when the same partial has a style modifier and pattern parameters between' : function(test){
420+
//arrange
421+
var fs = require('fs-extra');
422+
var pattern_assembler = new pa();
423+
424+
var pl = {};
425+
pl.config = {};
426+
pl.data = {};
427+
pl.data.link = {};
428+
pl.config.debug = false;
429+
pl.patterns = [];
430+
var patterns_dir = './test/files/_patterns';
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.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern);
435+
atomPattern.parameteredPartials = pattern_assembler.find_pattern_partials_with_parameters(atomPattern);
436+
437+
var bookendPattern = new object_factory.oPattern('test/files/_patterns/00-test/08-bookend-params.mustache', '00-test', '08-bookend-params.mustache');
438+
bookendPattern.template = fs.readFileSync(patterns_dir + '/00-test/08-bookend-params.mustache', 'utf8');
439+
bookendPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(bookendPattern);
440+
bookendPattern.parameteredPartials = pattern_assembler.find_pattern_partials_with_parameters(bookendPattern);
441+
442+
pl.patterns.push(atomPattern);
443+
pl.patterns.push(bookendPattern);
444+
445+
//act
446+
pattern_assembler.process_pattern_recursive('test/files/_patterns/00-test/08-bookend-params.mustache', pl, {});
447+
448+
//assert. here we expect {{styleModifier}} to be in the first and last span, since it was not replaced by anything. rendering with data will then remove this (correctly)
449+
var expectedValue = '<div class="test_group"> <span class="test_base {{styleModifier}}"> {{message}} </span> <span class="test_base test_2"> 2 </span> <span class="test_base test_3"> 3 </span> <span class="test_base {{styleModifier}}"> {{message}} </span> </div>';
450+
test.equals(bookendPattern.extendedTemplate.replace(/\s\s+/g, ' ').trim(), expectedValue.trim());
451+
test.done();
352452
}
353453
};
354454
}());

0 commit comments

Comments
 (0)