diff --git a/CHANGELOG b/CHANGELOG index df3b02510..6e29f56f0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,11 @@ THIS CHANGELOG IS AN ATTEMPT TO DOCUMENT CHANGES TO THIS PROJECT. +PL-node-v0.15.1 +- FIX: Resolve issue with styleModifiers not being replaced when the partial has spaces in it. +- ADD: Support multiple styleModifier classes using the | pipe syntax +- FIX: Resolve issue with styleModifiers not being applied correctly when mixed with pattern parameters +- THX: Thanks @theorise for the issue reports! + PL-node-v0.15.0 - CHG: Updated package.json devDependencies for Node 4.X and 5.X support. - CHG: Updated package.gulp.json devDependencies for Node 4.X and 5.X support. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index dcaef2d3d..87af6849d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,7 +1,7 @@ #Contributing to Patternlab - Node If you'd like to contribute to patternlab - node, please do so! There is always a lot of ground to cover, with patternlab - php being so feature-rich. -No pull request is too small. +No pull request is too small. Check out any [up for grabs issues](https://github.com/pattern-lab/patternlab-node/labels/up%20for%20grabs) as a good way to get your feet wet. ##Guidelines 1. Please keep your pull requests concise and limited to **ONE** substantive change at a time. diff --git a/README.md b/README.md index 820ecf1e6..c628bf065 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ It's not expected to toggle between the two build systems, but for those migrati ### Upgrading -You can find some simple upgrade documenation in it's current home here (unreleased but confirmed to work): [https://github.com/pattern-lab/website/blob/dev/patternlabsite/docs/node/upgrading.md](https://github.com/pattern-lab/website/blob/dev/patternlabsite/docs/node/upgrading.md) +You can find instructions on how to upgrade from version to version of Pattern Lab Node here: [https://github.com/pattern-lab/patternlab-node/wiki/Upgrading](https://github.com/pattern-lab/patternlab-node/wiki/Upgrading) ### Command Line Interface @@ -212,6 +212,11 @@ Once rendered, it looks like this: ``` +You may also specify multiple classes using a pipe character (|). + +``` +{{> atoms-message:error|is-on }} +``` diff --git a/builder/lineage_hunter.js b/builder/lineage_hunter.js index 4bd4acc9c..9056cdeac 100644 --- a/builder/lineage_hunter.js +++ b/builder/lineage_hunter.js @@ -1,5 +1,5 @@ /* - * patternlab-node - v0.15.0 - 2015 + * patternlab-node - v0.15.1 - 2015 * * Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. diff --git a/builder/list_item_hunter.js b/builder/list_item_hunter.js index 970e44f98..87574eee9 100644 --- a/builder/list_item_hunter.js +++ b/builder/list_item_hunter.js @@ -1,5 +1,5 @@ /* - * patternlab-node - v0.15.0 - 2015 + * patternlab-node - v0.15.1 - 2015 * * Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. diff --git a/builder/media_hunter.js b/builder/media_hunter.js index 94ea61e09..d5ada91ce 100644 --- a/builder/media_hunter.js +++ b/builder/media_hunter.js @@ -1,5 +1,5 @@ /* - * patternlab-node - v0.15.0 - 2015 + * patternlab-node - v0.15.1 - 2015 * * Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. diff --git a/builder/object_factory.js b/builder/object_factory.js index 685f95196..d1206866d 100644 --- a/builder/object_factory.js +++ b/builder/object_factory.js @@ -1,5 +1,5 @@ /* - * patternlab-node - v0.15.0 - 2015 + * patternlab-node - v0.15.1 - 2015 * * Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. diff --git a/builder/parameter_hunter.js b/builder/parameter_hunter.js index 1d1962008..4732ad0a5 100644 --- a/builder/parameter_hunter.js +++ b/builder/parameter_hunter.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v0.15.0 - 2015 - * +/* + * patternlab-node - v0.15.1 - 2015 + * * Brian Muenzenmeyer, and the web community. - * Licensed under the MIT license. - * - * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. + * Licensed under the MIT license. + * + * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. * */ @@ -28,6 +28,8 @@ //find the partial's name and retrieve it var partialName = pMatch.match(/([\w\-\.\/~]+)/g)[0]; var partialPattern = pattern_assembler.get_pattern_by_key(partialName, patternlab); + //if we retrieved a pattern we should make sure that its extendedTemplate is reset. looks to fix #190 + partialPattern.extendedTemplate = partialPattern.template; if(patternlab.config.debug){ console.log('found patternParameters for ' + partialName); diff --git a/builder/pattern_assembler.js b/builder/pattern_assembler.js index 8fc134c9e..5363acbde 100644 --- a/builder/pattern_assembler.js +++ b/builder/pattern_assembler.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v0.15.0 - 2015 - * +/* + * patternlab-node - v0.15.1 - 2015 + * * Brian Muenzenmeyer, and the web community. - * Licensed under the MIT license. - * - * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. + * Licensed under the MIT license. + * + * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. * */ @@ -24,19 +24,19 @@ // returns any patterns that match {{> value:mod }} or {{> value:mod(foo:"bar") }} within the pattern function findPartialsWithStyleModifiers(pattern){ - var matches = pattern.template.match(/{{>([ ])?([\w\-\.\/~]+)(?!\()(\:[A-Za-z0-9-_]+)+(?:(| )\(.*)?([ ])?}}/g); + var matches = pattern.template.match(/{{>([ ])?([\w\-\.\/~]+)(?!\()(\:[A-Za-z0-9-_|]+)+(?:(| )\(.*)?([ ])?}}/g); return matches; } // returns any patterns that match {{> value(foo:"bar") }} or {{> value:mod(foo:"bar") }} within the pattern function findPartialsWithPatternParameters(pattern){ - var matches = pattern.template.match(/{{>([ ])?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-_]+)?(?:(| )\(.*)+([ ])?}}/g); + var matches = pattern.template.match(/{{>([ ])?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-_|]+)?(?:(| )\(.*)+([ ])?}}/g); return matches; } //find and return any {{> template-name* }} within pattern function findPartials(pattern){ - var matches = pattern.template.match(/{{>([ ])?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-_]+)?(?:(| )\(.*)?([ ])?}}/g); + var matches = pattern.template.match(/{{>([ ])?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-_|]+)?(?:(| )\(.*)?([ ])?}}/g); return matches; } @@ -207,7 +207,7 @@ //do something with the regular old partials for(i = 0; i < foundPatternPartials.length; i++){ - var partialKey = foundPatternPartials[i].replace(/{{>([ ])?([\w\-\.\/~]+)(:[A-z-_]+)?(?:\:[A-Za-z0-9-]+)?(?:(| )\(.*)?([ ])?}}/g, '$2'); + var partialKey = foundPatternPartials[i].replace(/{{>([ ])?([\w\-\.\/~]+)(:[A-z-_|]+)?(?:\:[A-Za-z0-9-_]+)?(?:(| )\(.*)?([ ])?}}/g, '$2'); var partialPath; @@ -262,7 +262,7 @@ throw 'Could not find pattern with key ' + key; } - + function mergeData(obj1, obj2){ if(typeof obj2 === 'undefined'){ obj2 = {}; diff --git a/builder/pattern_exporter.js b/builder/pattern_exporter.js index 5ac4421d1..90915ec86 100644 --- a/builder/pattern_exporter.js +++ b/builder/pattern_exporter.js @@ -1,5 +1,5 @@ /* - * patternlab-node - v0.15.0 - 2015 + * patternlab-node - v0.15.1 - 2015 * * Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. diff --git a/builder/patternlab.js b/builder/patternlab.js index 25b2232de..9ea38d604 100644 --- a/builder/patternlab.js +++ b/builder/patternlab.js @@ -1,5 +1,5 @@ /* - * patternlab-node - v0.15.0 - 2015 + * patternlab-node - v0.15.1 - 2015 * * Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. diff --git a/builder/patternlab_grunt.js b/builder/patternlab_grunt.js index 3e09643fd..843dd07f1 100644 --- a/builder/patternlab_grunt.js +++ b/builder/patternlab_grunt.js @@ -1,5 +1,5 @@ /* - * patternlab-node - v0.15.0 - 2015 + * patternlab-node - v0.15.1 - 2015 * * Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. diff --git a/builder/patternlab_gulp.js b/builder/patternlab_gulp.js index 2b1db5d0c..d4014cb79 100644 --- a/builder/patternlab_gulp.js +++ b/builder/patternlab_gulp.js @@ -1,5 +1,5 @@ /* - * patternlab-node - v0.15.0 - 2015 + * patternlab-node - v0.15.1 - 2015 * * Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. diff --git a/builder/pseudopattern_hunter.js b/builder/pseudopattern_hunter.js index d47153cbe..9f698650f 100644 --- a/builder/pseudopattern_hunter.js +++ b/builder/pseudopattern_hunter.js @@ -1,5 +1,5 @@ /* - * patternlab-node - v0.15.0 - 2015 + * patternlab-node - v0.15.1 - 2015 * * Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. diff --git a/builder/style_modifier_hunter.js b/builder/style_modifier_hunter.js index 139fc9b2f..9baa6f0aa 100644 --- a/builder/style_modifier_hunter.js +++ b/builder/style_modifier_hunter.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v0.15.0 - 2015 - * +/* + * patternlab-node - v0.15.1 - 2015 + * * Brian Muenzenmeyer, and the web community. - * Licensed under the MIT license. - * - * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. + * Licensed under the MIT license. + * + * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. * */ @@ -16,15 +16,18 @@ function consumestylemodifier(pattern, partial, patternlab){ //extract the classname from the stylemodifier which comes in the format of :className - var styleModifier = partial.match(/:([\w\-_])+/g) ? partial.match(/:([\w\-_])+/g)[0].slice(1) : null; + var styleModifier = partial.match(/:([\w\-_|])+/g) ? partial.match(/:([\w\-_|])+/g)[0].slice(1) : null; if(styleModifier){ + //replace the special character pipe | used to separate multiple classes with a space + styleModifier = styleModifier.replace(/\|/g, ' '); + if(patternlab.config.debug){ console.log('found partial styleModifier within pattern ' + pattern.key); } //replace the stylemodifier placeholder with the class name - pattern.extendedTemplate = pattern.extendedTemplate.replace('{{styleModifier}}', styleModifier); + pattern.extendedTemplate = pattern.extendedTemplate.replace(/{{[ ]?styleModifier[ ]?}}/i, styleModifier); } } diff --git a/package.gulp.json b/package.gulp.json index 288f11faa..099c8d907 100644 --- a/package.gulp.json +++ b/package.gulp.json @@ -1,7 +1,7 @@ { "name": "patternlab-node", "description": "Pattern Lab is a collection of tools to help you create atomic design systems. This is the node command line interface (CLI).", - "version": "0.15.0", + "version": "0.15.1", "devDependencies": { "browser-sync": "^2.10.0", "del": "^2.0.2", diff --git a/package.json b/package.json index c451cb4d4..8d3953d22 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "patternlab-node", "description": "Pattern Lab is a collection of tools to help you create atomic design systems. This is the node command line interface (CLI).", - "version": "0.15.0", + "version": "0.15.1", "devDependencies": { "bs-html-injector": "^3.0.0", "diveSync": "^0.3.0", diff --git a/test/files/_patterns/00-test/03-styled-atom.mustache b/test/files/_patterns/00-test/03-styled-atom.mustache new file mode 100644 index 000000000..b736c06aa --- /dev/null +++ b/test/files/_patterns/00-test/03-styled-atom.mustache @@ -0,0 +1,3 @@ + + {{message}} + diff --git a/test/files/_patterns/00-test/04-group.mustache b/test/files/_patterns/00-test/04-group.mustache new file mode 100644 index 000000000..24ee58979 --- /dev/null +++ b/test/files/_patterns/00-test/04-group.mustache @@ -0,0 +1,6 @@ +
+ {{> test-styled-atom:test_1 }} + {{> test-styled-atom:test_2 }} + {{> test-styled-atom:test_3 }} + {{> test-styled-atom:test_4 }} +
diff --git a/test/files/_patterns/00-test/05-group2.mustache b/test/files/_patterns/00-test/05-group2.mustache new file mode 100644 index 000000000..a3986a1b5 --- /dev/null +++ b/test/files/_patterns/00-test/05-group2.mustache @@ -0,0 +1,6 @@ +
+ {{> test-styled-atom:test_1(message: "1" ) }} + {{> test-styled-atom:test_2(message: "2" ) }} + {{> test-styled-atom:test_3(message: "3" ) }} + {{> test-styled-atom:test_4(message: "4" ) }} +
diff --git a/test/files/_patterns/00-test/06-mixed.mustache b/test/files/_patterns/00-test/06-mixed.mustache new file mode 100644 index 000000000..b0c6d610f --- /dev/null +++ b/test/files/_patterns/00-test/06-mixed.mustache @@ -0,0 +1,6 @@ +
+ {{> test-styled-atom }} + {{> test-styled-atom:test_2 }} + {{> test-styled-atom:test_3 }} + {{> test-styled-atom:test_4 }} +
diff --git a/test/files/_patterns/00-test/07-mixed-params.mustache b/test/files/_patterns/00-test/07-mixed-params.mustache new file mode 100644 index 000000000..408b3f1e4 --- /dev/null +++ b/test/files/_patterns/00-test/07-mixed-params.mustache @@ -0,0 +1,6 @@ +
+ {{> test-styled-atom }} + {{> test-styled-atom:test_2(message: '2') }} + {{> test-styled-atom:test_3(message: '3') }} + {{> test-styled-atom:test_4(message: '4') }} +
diff --git a/test/files/_patterns/00-test/08-bookend-params.mustache b/test/files/_patterns/00-test/08-bookend-params.mustache new file mode 100644 index 000000000..d2d0b4081 --- /dev/null +++ b/test/files/_patterns/00-test/08-bookend-params.mustache @@ -0,0 +1,6 @@ +
+ {{> test-styled-atom }} + {{> test-styled-atom:test_2(message: '2') }} + {{> test-styled-atom:test_3(message: '3') }} + {{> test-styled-atom }} +
diff --git a/test/files/_patterns/00-test/09-bookend.mustache b/test/files/_patterns/00-test/09-bookend.mustache new file mode 100644 index 000000000..74fc3451b --- /dev/null +++ b/test/files/_patterns/00-test/09-bookend.mustache @@ -0,0 +1,6 @@ +
+ {{> test-styled-atom }} + {{> test-styled-atom:test_2 }} + {{> test-styled-atom:test_3 }} + {{> test-styled-atom}} +
diff --git a/test/pattern_assembler_tests.js b/test/pattern_assembler_tests.js index cc4e55333..36b6c3ea8 100644 --- a/test/pattern_assembler_tests.js +++ b/test/pattern_assembler_tests.js @@ -2,6 +2,7 @@ "use strict"; var pa = require('../builder/pattern_assembler'); + var object_factory = require('../builder/object_factory'); exports['pattern_assembler'] = { 'find_pattern_partials finds partials' : function(test){ @@ -283,6 +284,170 @@ //test that 00-foo.mustache included partial 01-bar.mustache test.equals(fooExtended, 'bar'); + test.done(); + }, + 'processPatternRecursive - correctly replaces all stylemodifiers when multiple duplicate patterns with different stylemodifiers found' : function(test){ + //arrange + var fs = require('fs-extra'); + var pattern_assembler = new pa(); + + var pl = {}; + pl.config = {}; + pl.data = {}; + pl.data.link = {}; + pl.config.debug = false; + pl.patterns = []; + var patterns_dir = './test/files/_patterns'; + + var atomPattern = new object_factory.oPattern('test/files/_patterns/00-test/03-styled-atom.mustache', '00-test', '03-styled-atom.mustache'); + atomPattern.template = fs.readFileSync(patterns_dir + '/00-test/03-styled-atom.mustache', 'utf8'); + atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern); + + var groupPattern = new object_factory.oPattern('test/files/_patterns/00-test/04-group.mustache', '00-test', '04-group.mustache'); + groupPattern.template = fs.readFileSync(patterns_dir + '/00-test/04-group.mustache', 'utf8'); + groupPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(groupPattern); + + pl.patterns.push(atomPattern); + pl.patterns.push(groupPattern); + + //act + pattern_assembler.process_pattern_recursive('test/files/_patterns/00-test/04-group.mustache', pl, {}); + + //assert + var expectedValue = '
{{message}} {{message}} {{message}} {{message}}
'; + test.equals(groupPattern.extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), expectedValue.trim()); + test.done(); + }, + 'processPatternRecursive - correctly ignores a partial without a style modifier when the same partial later has a style modifier' : function(test){ + //arrange + var fs = require('fs-extra'); + var pattern_assembler = new pa(); + + var pl = {}; + pl.config = {}; + pl.data = {}; + pl.data.link = {}; + pl.config.debug = false; + pl.patterns = []; + var patterns_dir = './test/files/_patterns'; + + var atomPattern = new object_factory.oPattern('test/files/_patterns/00-test/03-styled-atom.mustache', '00-test', '03-styled-atom.mustache'); + atomPattern.template = fs.readFileSync(patterns_dir + '/00-test/03-styled-atom.mustache', 'utf8'); + atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern); + + var mixedPattern = new object_factory.oPattern('test/files/_patterns/00-test/06-mixed.mustache', '00-test', '06-mixed.mustache'); + mixedPattern.template = fs.readFileSync(patterns_dir + '/00-test/06-mixed.mustache', 'utf8'); + mixedPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(mixedPattern); + + pl.patterns.push(atomPattern); + pl.patterns.push(mixedPattern); + + //act + pattern_assembler.process_pattern_recursive('test/files/_patterns/00-test/06-mixed.mustache', pl, {}); + + //assert. here we expect {{styleModifier}} to be in the first group, since it was not replaced by anything. rendering with data will then remove this (correctly) + var expectedValue = '
{{message}} {{message}} {{message}} {{message}}
'; + test.equals(mixedPattern.extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), expectedValue.trim()); + test.done(); + }, + 'processPatternRecursive - correctly ignores bookended partials without a style modifier when the same partial has a style modifier between' : function(test){ + //arrange + var fs = require('fs-extra'); + var pattern_assembler = new pa(); + + var pl = {}; + pl.config = {}; + pl.data = {}; + pl.data.link = {}; + pl.config.debug = false; + pl.patterns = []; + var patterns_dir = './test/files/_patterns'; + + var atomPattern = new object_factory.oPattern('test/files/_patterns/00-test/03-styled-atom.mustache', '00-test', '03-styled-atom.mustache'); + atomPattern.template = fs.readFileSync(patterns_dir + '/00-test/03-styled-atom.mustache', 'utf8'); + atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern); + + var bookendPattern = new object_factory.oPattern('test/files/_patterns/00-test/09-bookend.mustache', '00-test', '09-bookend.mustache'); + bookendPattern.template = fs.readFileSync(patterns_dir + '/00-test/09-bookend.mustache', 'utf8'); + bookendPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(bookendPattern); + + pl.patterns.push(atomPattern); + pl.patterns.push(bookendPattern); + + //act + pattern_assembler.process_pattern_recursive('test/files/_patterns/00-test/09-bookend.mustache', pl, {}); + + //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) + var expectedValue = '
{{message}} {{message}} {{message}} {{message}}
'; + test.equals(bookendPattern.extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), expectedValue.trim()); + test.done(); + }, + 'processPatternRecursive - correctly ignores a partial without a style modifier when the same partial later has a style modifier and pattern parameters' : function(test){ + //arrange + var fs = require('fs-extra'); + var pattern_assembler = new pa(); + + var pl = {}; + pl.config = {}; + pl.data = {}; + pl.data.link = {}; + pl.config.debug = false; + pl.patterns = []; + var patterns_dir = './test/files/_patterns'; + + var atomPattern = new object_factory.oPattern('test/files/_patterns/00-test/03-styled-atom.mustache', '00-test', '03-styled-atom.mustache'); + atomPattern.template = fs.readFileSync(patterns_dir + '/00-test/03-styled-atom.mustache', 'utf8'); + atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern); + atomPattern.parameteredPartials = pattern_assembler.find_pattern_partials_with_parameters(atomPattern); + + var mixedPattern = new object_factory.oPattern('test/files/_patterns/00-test/07-mixed-params.mustache', '00-test', '07-mixed-params.mustache'); + mixedPattern.template = fs.readFileSync(patterns_dir + '/00-test/07-mixed-params.mustache', 'utf8'); + mixedPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(mixedPattern); + mixedPattern.parameteredPartials = pattern_assembler.find_pattern_partials_with_parameters(mixedPattern); + + pl.patterns.push(atomPattern); + pl.patterns.push(mixedPattern); + + //act + pattern_assembler.process_pattern_recursive('test/files/_patterns/00-test/07-mixed-params.mustache', pl, {}); + + //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) + var expectedValue = '
{{message}} 2 3 4
'; + test.equals(mixedPattern.extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), expectedValue.trim()); + test.done(); + }, + 'processPatternRecursive - correctly ignores bookended partials without a style modifier when the same partial has a style modifier and pattern parameters between' : function(test){ + //arrange + var fs = require('fs-extra'); + var pattern_assembler = new pa(); + + var pl = {}; + pl.config = {}; + pl.data = {}; + pl.data.link = {}; + pl.config.debug = false; + pl.patterns = []; + var patterns_dir = './test/files/_patterns'; + + var atomPattern = new object_factory.oPattern('test/files/_patterns/00-test/03-styled-atom.mustache', '00-test', '03-styled-atom.mustache'); + atomPattern.template = fs.readFileSync(patterns_dir + '/00-test/03-styled-atom.mustache', 'utf8'); + atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern); + atomPattern.parameteredPartials = pattern_assembler.find_pattern_partials_with_parameters(atomPattern); + + var bookendPattern = new object_factory.oPattern('test/files/_patterns/00-test/08-bookend-params.mustache', '00-test', '08-bookend-params.mustache'); + bookendPattern.template = fs.readFileSync(patterns_dir + '/00-test/08-bookend-params.mustache', 'utf8'); + bookendPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(bookendPattern); + bookendPattern.parameteredPartials = pattern_assembler.find_pattern_partials_with_parameters(bookendPattern); + + pl.patterns.push(atomPattern); + pl.patterns.push(bookendPattern); + + //act + pattern_assembler.process_pattern_recursive('test/files/_patterns/00-test/08-bookend-params.mustache', pl, {}); + + //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) + var expectedValue = '
{{message}} 2 3 {{message}}
'; + test.equals(bookendPattern.extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), expectedValue.trim()); test.done(); } }; diff --git a/test/style_modifier_hunter_tests.js b/test/style_modifier_hunter_tests.js index 0245c7349..4951dde18 100644 --- a/test/style_modifier_hunter_tests.js +++ b/test/style_modifier_hunter_tests.js @@ -23,6 +23,44 @@ test.equals(pattern.extendedTemplate, '
'); test.done(); }, + 'replaces style modifiers with spaces in the syntax' : function(test){ + //arrange + var pl = {}; + pl.config = {}; + pl.config.debug = false; + + var pattern = { + extendedTemplate: '
' + }; + + var style_modifier_hunter = new smh(); + + //act + style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar}}', pl); + + //assert + test.equals(pattern.extendedTemplate, '
'); + test.done(); + }, + 'replaces multiple style modifiers' : function(test){ + //arrange + var pl = {}; + pl.config = {}; + pl.config.debug = false; + + var pattern = { + extendedTemplate: '
' + }; + + var style_modifier_hunter = new smh(); + + //act + style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar|baz|dum}}', pl); + + //assert + test.equals(pattern.extendedTemplate, '
'); + test.done(); + }, 'does not alter pattern extendedTemplate if styleModifier not found in partial' : function(test){ //arrange var pl = {};