diff --git a/.travis.yml b/.travis.yml index ed3078720..90d48e964 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,10 @@ language: node_js node_js: - - stable - - 5.0 - - 4.0 + - node + - 6 + - 5 + - 4 before_install: - phantomjs --version @@ -15,7 +16,6 @@ branches: only: - master - dev - - pattern-engines - dev-2.0-core notifications: diff --git a/core/lib/list_item_hunter.js b/core/lib/list_item_hunter.js index e8d278609..ec4199327 100644 --- a/core/lib/list_item_hunter.js +++ b/core/lib/list_item_hunter.js @@ -91,6 +91,9 @@ var list_item_hunter = function () { console.log(err); } + //if we retrieved a pattern we should make sure that its extendedTemplate is reset. looks to fix #356 + cleanPartialPattern.extendedTemplate = cleanPartialPattern.template; + //if partial has style modifier data, replace the styleModifier value if (foundPartials[j].indexOf(':') > -1) { style_modifier_hunter.consume_style_modifier(cleanPartialPattern, foundPartials[j], patternlab); diff --git a/test/files/_patterns/00-test/12-another-styled-atom.mustache b/test/files/_patterns/00-test/12-another-styled-atom.mustache new file mode 100644 index 000000000..2f03b4974 --- /dev/null +++ b/test/files/_patterns/00-test/12-another-styled-atom.mustache @@ -0,0 +1 @@ +{{> test-styled-atom:test_1 }} diff --git a/test/files/_patterns/00-test/13-listitem.mustache b/test/files/_patterns/00-test/13-listitem.mustache new file mode 100644 index 000000000..cad86d2c7 --- /dev/null +++ b/test/files/_patterns/00-test/13-listitem.mustache @@ -0,0 +1,5 @@ +
+ {{#listItems.one}} + {{> test-styled-atom }} + {{/listItems.one}} +
diff --git a/test/list_item_hunter_tests.js b/test/list_item_hunter_tests.js index 361763eaa..7fe3cea56 100644 --- a/test/list_item_hunter_tests.js +++ b/test/list_item_hunter_tests.js @@ -4,6 +4,8 @@ var lih = require('../core/lib/list_item_hunter'); var Pattern = require('../core/lib/object_factory').Pattern; var extend = require('util')._extend; + var pa = require('../core/lib/pattern_assembler'); + var pattern_assembler = new pa(); // fake pattern creators function createFakeListPattern(customProps) { @@ -17,22 +19,56 @@ } function createFakePatternLab(customProps) { + + //NOTE: These listitems are faked so that pattern_assembler.combine_listitems has already clobbered them. + var pl = { "listitems": { "1": [ - { "title": "Foo" } + { + "title": "Foo", + "message": "FooM" + } ], - "2": [ - { "title": "Foo" }, - { "title": "Bar" } + "2" : [ + { + "title": "Foo", + "message": "FooM" + }, + { + "title": "Bar", + "message": "BarM" + } + ], + "3": [ + { + "title": "Foo", + "message": "FooM" + }, + { + "title": "Bar", + "message": "BarM" + }, + { + "title": "Baz", + "message": "BazM" + }, ] }, "data": { "link": {}, "partials": [] }, - "config": {"debug": false}, - "partials" : {} + "config": { + "debug": false, + "paths": { + "source": { + "patterns": "./test/files/_patterns" + } + } + }, + "partials" : {}, + "patterns" : [] }; return extend(pl, customProps); @@ -335,7 +371,46 @@ var expectedValue = '
Foo Foo Foo Bar Bar Bar
'; test.equals(bookendPattern.extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), expectedValue.trim()); test.done(); - } + }, + + 'process_list_item_partials - correctly ignores already processed partial that had a style modifier when the same partial no longer has one' : function(test){ + //arrange + var fs = require('fs-extra'); + var list_item_hunter = new lih(); + + var pl = createFakePatternLab(); + + var atomPattern = new Pattern('00-test/03-styled-atom.mustache'); + atomPattern.template = fs.readFileSync(pl.config.paths.source.patterns + '/00-test/03-styled-atom.mustache', 'utf8'); + atomPattern.extendedTemplate = atomPattern.template; + atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern); + + var anotherStyledAtomPattern = new Pattern('00-test/12-another-styled-atom.mustache'); + anotherStyledAtomPattern.template = fs.readFileSync(pl.config.paths.source.patterns + '/00-test/12-another-styled-atom.mustache', 'utf8'); + anotherStyledAtomPattern.extendedTemplate = anotherStyledAtomPattern.template; + anotherStyledAtomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(anotherStyledAtomPattern); + + var listPattern = new Pattern('00-test/13-listitem.mustache'); + listPattern.template = fs.readFileSync(pl.config.paths.source.patterns + '/00-test/13-listitem.mustache', 'utf8'); + listPattern.extendedTemplate = listPattern.template; + listPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(listPattern); + + pl.patterns.push(atomPattern); + pl.patterns.push(anotherStyledAtomPattern); + pl.patterns.push(listPattern); + + //act + + //might need to cal processPatternRecursive instead + pattern_assembler.process_pattern_recursive(atomPattern.relPath, pl); + pattern_assembler.process_pattern_recursive(anotherStyledAtomPattern.relPath, pl); + pattern_assembler.process_pattern_recursive(listPattern.relPath, pl); + + //assert. + var expectedValue = '
FooM
'; + test.equals(listPattern.extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), expectedValue.trim()); + test.done(); + }, };