Skip to content

Commit 8c7a7f6

Browse files
author
Brian Muenzenmeyer
authored
Merge pull request #359 from pattern-lab/356-listitem-bug
356 listitem bug
2 parents 50950a9 + a17fa30 commit 8c7a7f6

File tree

5 files changed

+95
-11
lines changed

5 files changed

+95
-11
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
language: node_js
22

33
node_js:
4-
- stable
5-
- 5.0
6-
- 4.0
4+
- node
5+
- 6
6+
- 5
7+
- 4
78

89
before_install:
910
- phantomjs --version
@@ -15,7 +16,6 @@ branches:
1516
only:
1617
- master
1718
- dev
18-
- pattern-engines
1919
- dev-2.0-core
2020

2121
notifications:

core/lib/list_item_hunter.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ var list_item_hunter = function () {
9191
console.log(err);
9292
}
9393

94+
//if we retrieved a pattern we should make sure that its extendedTemplate is reset. looks to fix #356
95+
cleanPartialPattern.extendedTemplate = cleanPartialPattern.template;
96+
9497
//if partial has style modifier data, replace the styleModifier value
9598
if (foundPartials[j].indexOf(':') > -1) {
9699
style_modifier_hunter.consume_style_modifier(cleanPartialPattern, foundPartials[j], patternlab);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{> test-styled-atom:test_1 }}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div class="test_group">
2+
{{#listItems.one}}
3+
{{> test-styled-atom }}
4+
{{/listItems.one}}
5+
</div>

test/list_item_hunter_tests.js

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
var lih = require('../core/lib/list_item_hunter');
55
var Pattern = require('../core/lib/object_factory').Pattern;
66
var extend = require('util')._extend;
7+
var pa = require('../core/lib/pattern_assembler');
8+
var pattern_assembler = new pa();
79

810
// fake pattern creators
911
function createFakeListPattern(customProps) {
@@ -17,22 +19,56 @@
1719
}
1820

1921
function createFakePatternLab(customProps) {
22+
23+
//NOTE: These listitems are faked so that pattern_assembler.combine_listitems has already clobbered them.
24+
2025
var pl = {
2126
"listitems": {
2227
"1": [
23-
{ "title": "Foo" }
28+
{
29+
"title": "Foo",
30+
"message": "FooM"
31+
}
2432
],
25-
"2": [
26-
{ "title": "Foo" },
27-
{ "title": "Bar" }
33+
"2" : [
34+
{
35+
"title": "Foo",
36+
"message": "FooM"
37+
},
38+
{
39+
"title": "Bar",
40+
"message": "BarM"
41+
}
42+
],
43+
"3": [
44+
{
45+
"title": "Foo",
46+
"message": "FooM"
47+
},
48+
{
49+
"title": "Bar",
50+
"message": "BarM"
51+
},
52+
{
53+
"title": "Baz",
54+
"message": "BazM"
55+
},
2856
]
2957
},
3058
"data": {
3159
"link": {},
3260
"partials": []
3361
},
34-
"config": {"debug": false},
35-
"partials" : {}
62+
"config": {
63+
"debug": false,
64+
"paths": {
65+
"source": {
66+
"patterns": "./test/files/_patterns"
67+
}
68+
}
69+
},
70+
"partials" : {},
71+
"patterns" : []
3672
};
3773

3874
return extend(pl, customProps);
@@ -335,7 +371,46 @@
335371
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>';
336372
test.equals(bookendPattern.extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), expectedValue.trim());
337373
test.done();
338-
}
374+
},
375+
376+
'process_list_item_partials - correctly ignores already processed partial that had a style modifier when the same partial no longer has one' : function(test){
377+
//arrange
378+
var fs = require('fs-extra');
379+
var list_item_hunter = new lih();
380+
381+
var pl = createFakePatternLab();
382+
383+
var atomPattern = new Pattern('00-test/03-styled-atom.mustache');
384+
atomPattern.template = fs.readFileSync(pl.config.paths.source.patterns + '/00-test/03-styled-atom.mustache', 'utf8');
385+
atomPattern.extendedTemplate = atomPattern.template;
386+
atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern);
387+
388+
var anotherStyledAtomPattern = new Pattern('00-test/12-another-styled-atom.mustache');
389+
anotherStyledAtomPattern.template = fs.readFileSync(pl.config.paths.source.patterns + '/00-test/12-another-styled-atom.mustache', 'utf8');
390+
anotherStyledAtomPattern.extendedTemplate = anotherStyledAtomPattern.template;
391+
anotherStyledAtomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(anotherStyledAtomPattern);
392+
393+
var listPattern = new Pattern('00-test/13-listitem.mustache');
394+
listPattern.template = fs.readFileSync(pl.config.paths.source.patterns + '/00-test/13-listitem.mustache', 'utf8');
395+
listPattern.extendedTemplate = listPattern.template;
396+
listPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(listPattern);
397+
398+
pl.patterns.push(atomPattern);
399+
pl.patterns.push(anotherStyledAtomPattern);
400+
pl.patterns.push(listPattern);
401+
402+
//act
403+
404+
//might need to cal processPatternRecursive instead
405+
pattern_assembler.process_pattern_recursive(atomPattern.relPath, pl);
406+
pattern_assembler.process_pattern_recursive(anotherStyledAtomPattern.relPath, pl);
407+
pattern_assembler.process_pattern_recursive(listPattern.relPath, pl);
408+
409+
//assert.
410+
var expectedValue = '<div class="test_group"> <span class="test_base "> FooM </span> </div>';
411+
test.equals(listPattern.extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), expectedValue.trim());
412+
test.done();
413+
},
339414

340415
};
341416

0 commit comments

Comments
 (0)