Skip to content

Commit eda17c0

Browse files
committed
reset extendedTemplate to template after retrieval
passing unit test and passing npm linked private instance of PL closes #356
1 parent 8c9d85e commit eda17c0

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

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);

test/list_item_hunter_tests.js

Lines changed: 35 additions & 11 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,15 +19,40 @@
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" },
24-
{ "message" : "FooM"}
28+
{
29+
"title": "Foo",
30+
"message": "FooM"
31+
}
2532
],
26-
"2": [
27-
{ "title": "Foo" },
28-
{ "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+
},
2956
]
3057
},
3158
"data": {
@@ -349,25 +376,22 @@
349376
'process_list_item_partials - correctly ignores already processed partial that had a style modifier when the same partial no longer has one' : function(test){
350377
//arrange
351378
var fs = require('fs-extra');
352-
var pa = require('../core/lib/pattern_assembler');
353-
var pattern_assembler = new pa();
354379
var list_item_hunter = new lih();
355-
var patterns_dir = './test/files/_patterns';
356380

357381
var pl = createFakePatternLab();
358382

359383
var atomPattern = new Pattern('00-test/03-styled-atom.mustache');
360-
atomPattern.template = fs.readFileSync(patterns_dir + '/00-test/03-styled-atom.mustache', 'utf8');
384+
atomPattern.template = fs.readFileSync(pl.config.paths.source.patterns + '/00-test/03-styled-atom.mustache', 'utf8');
361385
atomPattern.extendedTemplate = atomPattern.template;
362386
atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern);
363387

364388
var anotherStyledAtomPattern = new Pattern('00-test/12-another-styled-atom.mustache');
365-
anotherStyledAtomPattern.template = fs.readFileSync(patterns_dir + '/00-test/12-another-styled-atom.mustache', 'utf8');
389+
anotherStyledAtomPattern.template = fs.readFileSync(pl.config.paths.source.patterns + '/00-test/12-another-styled-atom.mustache', 'utf8');
366390
anotherStyledAtomPattern.extendedTemplate = anotherStyledAtomPattern.template;
367391
anotherStyledAtomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(anotherStyledAtomPattern);
368392

369393
var listPattern = new Pattern('00-test/13-listitem.mustache');
370-
listPattern.template = fs.readFileSync(patterns_dir + '/00-test/13-listitem.mustache', 'utf8');
394+
listPattern.template = fs.readFileSync(pl.config.paths.source.patterns + '/00-test/13-listitem.mustache', 'utf8');
371395
listPattern.extendedTemplate = listPattern.template;
372396
listPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(listPattern);
373397

0 commit comments

Comments
 (0)