From e5ac6be158b9c02129803f30b1c1110f8b22d450 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Mon, 16 Nov 2015 22:53:25 -0600 Subject: [PATCH 1/8] fix issue with style modifiers not working with spaces in the template closes #183 --- CHANGELOG | 4 ++++ builder/lineage_hunter.js | 2 +- builder/list_item_hunter.js | 2 +- builder/media_hunter.js | 2 +- builder/object_factory.js | 2 +- builder/parameter_hunter.js | 2 +- builder/pattern_assembler.js | 2 +- builder/pattern_exporter.js | 2 +- builder/patternlab.js | 2 +- builder/patternlab_grunt.js | 2 +- builder/patternlab_gulp.js | 2 +- builder/pseudopattern_hunter.js | 2 +- builder/style_modifier_hunter.js | 4 ++-- package.gulp.json | 2 +- package.json | 2 +- test/style_modifier_hunter_tests.js | 19 +++++++++++++++++++ 16 files changed, 38 insertions(+), 15 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index df3b02510..5f22cfeb9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,9 @@ 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. +- THX: Thanks @theorise for the issue report! + 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/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..5b21008a4 100644 --- a/builder/parameter_hunter.js +++ b/builder/parameter_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/pattern_assembler.js b/builder/pattern_assembler.js index 8fc134c9e..4a1588ff3 100644 --- a/builder/pattern_assembler.js +++ b/builder/pattern_assembler.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/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..b0b909b4e 100644 --- a/builder/style_modifier_hunter.js +++ b/builder/style_modifier_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. @@ -24,7 +24,7 @@ } //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/style_modifier_hunter_tests.js b/test/style_modifier_hunter_tests.js index 0245c7349..2753c60f1 100644 --- a/test/style_modifier_hunter_tests.js +++ b/test/style_modifier_hunter_tests.js @@ -23,6 +23,25 @@ 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(); + }, 'does not alter pattern extendedTemplate if styleModifier not found in partial' : function(test){ //arrange var pl = {}; From 3c3270ad013b24cf8394c3424ae8280add10cd51 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Mon, 16 Nov 2015 23:44:18 -0600 Subject: [PATCH 2/8] added a note to CONTRIBUTING.md that mentions up for grabs issues --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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. From a818d284b2d96caa0840323d13de88788bdea363 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Tue, 17 Nov 2015 00:14:12 -0600 Subject: [PATCH 3/8] support for multiple classes on stylemodifier closes #186 --- CHANGELOG | 3 ++- README.md | 5 +++++ builder/pattern_assembler.js | 22 +++++++++++----------- builder/style_modifier_hunter.js | 17 ++++++++++------- test/style_modifier_hunter_tests.js | 19 +++++++++++++++++++ 5 files changed, 47 insertions(+), 19 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 5f22cfeb9..1a65bc614 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,7 +2,8 @@ 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. -- THX: Thanks @theorise for the issue report! +- ADD: Support multiple styleModifier classes using the | pipe syntax +- 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. diff --git a/README.md b/README.md index 820ecf1e6..56421f9f5 100644 --- a/README.md +++ b/README.md @@ -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/pattern_assembler.js b/builder/pattern_assembler.js index 4a1588ff3..1fcdc2719 100644 --- a/builder/pattern_assembler.js +++ b/builder/pattern_assembler.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v0.15.1 - 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/style_modifier_hunter.js b/builder/style_modifier_hunter.js index b0b909b4e..9baa6f0aa 100644 --- a/builder/style_modifier_hunter.js +++ b/builder/style_modifier_hunter.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v0.15.1 - 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,9 +16,12 @@ 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); } diff --git a/test/style_modifier_hunter_tests.js b/test/style_modifier_hunter_tests.js index 2753c60f1..4951dde18 100644 --- a/test/style_modifier_hunter_tests.js +++ b/test/style_modifier_hunter_tests.js @@ -42,6 +42,25 @@ 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 = {}; From 157a06e2c644ddd0968e187cf5b7df04ebcaed7e Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Tue, 17 Nov 2015 00:32:20 -0600 Subject: [PATCH 4/8] updated the instructions to point to the wiki for now --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 56421f9f5..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 From 8fb7eea79774268f37fb06f352d825f1f9b3aa05 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Tue, 24 Nov 2015 23:38:02 -0600 Subject: [PATCH 5/8] Unit test to cover correct application of multiple partials with differing style modifiers --- builder/pattern_assembler.js | 2 +- .../_patterns/00-test/03-styled-atom.mustache | 3 ++ .../files/_patterns/00-test/04-group.mustache | 6 ++++ .../_patterns/00-test/05-group2.mustache | 6 ++++ test/pattern_assembler_tests.js | 33 +++++++++++++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 test/files/_patterns/00-test/03-styled-atom.mustache create mode 100644 test/files/_patterns/00-test/04-group.mustache create mode 100644 test/files/_patterns/00-test/05-group2.mustache diff --git a/builder/pattern_assembler.js b/builder/pattern_assembler.js index 1fcdc2719..5363acbde 100644 --- a/builder/pattern_assembler.js +++ b/builder/pattern_assembler.js @@ -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; 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/pattern_assembler_tests.js b/test/pattern_assembler_tests.js index cc4e55333..da024251f 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,38 @@ //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, ' ').trim(), expectedValue.trim()); test.done(); } }; From ffc80cb4eeb8ff739563b9eb9606835d62c390ee Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Tue, 24 Nov 2015 23:53:24 -0600 Subject: [PATCH 6/8] a unit test to cover half of #190 --- .../files/_patterns/00-test/06-mixed.mustache | 6 ++++ test/pattern_assembler_tests.js | 34 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 test/files/_patterns/00-test/06-mixed.mustache 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/pattern_assembler_tests.js b/test/pattern_assembler_tests.js index da024251f..af082fda5 100644 --- a/test/pattern_assembler_tests.js +++ b/test/pattern_assembler_tests.js @@ -303,7 +303,6 @@ 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); @@ -313,10 +312,43 @@ //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, ' ').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, ' ').trim(), expectedValue.trim()); + test.done(); } }; }()); From 9cd187b607f9a474f022d6ddeb5d330e004682f8 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Wed, 25 Nov 2015 00:40:35 -0600 Subject: [PATCH 7/8] additional tests to cover styleModifier / pattern Parameter relationship fixes #190 --- CHANGELOG | 1 + builder/parameter_hunter.js | 14 +-- .../00-test/07-mixed-params.mustache | 6 ++ .../00-test/08-bookend-params.mustache | 6 ++ .../_patterns/00-test/09-bookend.mustache | 6 ++ test/pattern_assembler_tests.js | 100 ++++++++++++++++++ 6 files changed, 127 insertions(+), 6 deletions(-) create mode 100644 test/files/_patterns/00-test/07-mixed-params.mustache create mode 100644 test/files/_patterns/00-test/08-bookend-params.mustache create mode 100644 test/files/_patterns/00-test/09-bookend.mustache diff --git a/CHANGELOG b/CHANGELOG index 1a65bc614..6e29f56f0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ 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 diff --git a/builder/parameter_hunter.js b/builder/parameter_hunter.js index 5b21008a4..4732ad0a5 100644 --- a/builder/parameter_hunter.js +++ b/builder/parameter_hunter.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v0.15.1 - 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/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 af082fda5..87a149c24 100644 --- a/test/pattern_assembler_tests.js +++ b/test/pattern_assembler_tests.js @@ -349,6 +349,106 @@ var expectedValue = '
{{message}} {{message}} {{message}} {{message}}
'; test.equals(mixedPattern.extendedTemplate.replace(/\s\s+/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, ' ').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, ' ').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, ' ').trim(), expectedValue.trim()); + test.done(); } }; }()); From 85842319deeef513d1970b1cd164248250f9c96e Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Wed, 25 Nov 2015 01:00:33 -0600 Subject: [PATCH 8/8] looks like there are some newlines on the CI box that are not on my Window's env. --- test/pattern_assembler_tests.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/pattern_assembler_tests.js b/test/pattern_assembler_tests.js index 87a149c24..36b6c3ea8 100644 --- a/test/pattern_assembler_tests.js +++ b/test/pattern_assembler_tests.js @@ -315,7 +315,7 @@ //assert var expectedValue = '
{{message}} {{message}} {{message}} {{message}}
'; - test.equals(groupPattern.extendedTemplate.replace(/\s\s+/g, ' ').trim(), expectedValue.trim()); + 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){ @@ -347,7 +347,7 @@ //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, ' ').trim(), expectedValue.trim()); + 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){ @@ -379,7 +379,7 @@ //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, ' ').trim(), expectedValue.trim()); + 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){ @@ -413,7 +413,7 @@ //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, ' ').trim(), expectedValue.trim()); + 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){ @@ -447,7 +447,7 @@ //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, ' ').trim(), expectedValue.trim()); + test.equals(bookendPattern.extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), expectedValue.trim()); test.done(); } };