diff --git a/CHANGELOG b/CHANGELOG index 83067b2b8..47e84b680 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,8 @@ THIS CHANGELOG IS AN ATTEMPT TO DOCUMENT CHANGES TO THIS PROJECT. +PL-node-v0.10.1 + - ADD: Added more unit tests for recently more-modular code + - FIX: Lineage was not working for patterns with pattern parameters + PL-node-v0.10.0 - ADD: Added support for pattern parameters! Resolves #88 - FIX: Data inheritance is now working as advertised. Resolves #127. This turned out to be a MAJOR thing, as I realized the home-page was not passing down any of its json data to partials. @@ -7,7 +11,8 @@ PL-node-v0.10.0 - ADD: Added a new comment organism, the sticky comment, to ship an example of pattern parameters - CHG: Start some JS linting of the project. I don't quite agree with a lot of it, so am trying to set some smart configurations - CHG: Wrapped some build messages in the patternlab.config.debug flag - - FIX: Allow users to set a base url path. Resolves #125 ([)testing in the while requested) + - FIX: Allow users to set a base url path. Resolves #125 (testing in the wild requested) + - THX: Thanks @scottnath for the proposed base url solution and @jkbyln for discussion on the topic too! PL-node-v0.9.1 - FIX: Fixed an issue with view all navigation not checking for index out of bounds cases diff --git a/Gruntfile.js b/Gruntfile.js index 53f28e6b4..cd9112eb3 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -133,7 +133,7 @@ module.exports = function(grunt) { grunt.registerTask('default', ['clean', 'concat', 'patternlab', /*'sass',*/ 'copy']); //travis CI task - grunt.registerTask('travis', ['clean', 'concat', 'patternlab', /*'sass',*/ 'copy', 'nodeunit']); + grunt.registerTask('travis', ['nodeunit', 'clean', 'concat', 'patternlab', /*'sass',*/ 'copy']); grunt.registerTask('serve', ['clean', 'concat', 'patternlab', /*'sass',*/ 'copy', 'connect', 'watch']); diff --git a/README.md b/README.md index 61b1bae75..f2eb63b62 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ Pattern states should be lowercase and use hyphens where spaces are present. ``` ##### Pattern Parameters -attern parameters are a simple mechanism for replacing Mustache variables via attributes on a pattern partial tag rather than having to use a pattern-specific json file. They are especially useful when you want to supply distinct values for Mustache variables in a specific pattern partial instance that may be included multiple times in a molecule, template, or page. +Pattern parameters are a simple mechanism for replacing Mustache variables via attributes on a pattern partial tag rather than having to use a pattern-specific json file. They are especially useful when you want to supply distinct values for Mustache variables in a specific pattern partial instance that may be included multiple times in a molecule, template, or page. The basic syntax is this: diff --git a/builder/lineage_hunter.js b/builder/lineage_hunter.js index 8566dd0cb..bb072bf74 100644 --- a/builder/lineage_hunter.js +++ b/builder/lineage_hunter.js @@ -1,5 +1,5 @@ /* - * patternlab-node - v0.10.0 - 2015 + * patternlab-node - v0.10.1 - 2015 * * Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. @@ -25,6 +25,11 @@ //strip out the template cruft var foundPattern = match.replace("{{> ", "").replace(" }}", "").replace("{{>", "").replace("}}", ""); + // remove any potential pattern parameters. this and the above are rather brutish but I didn't want to do a regex at the time + if(foundPattern.indexOf('(') > 0){ + foundPattern = foundPattern.substring(0, foundPattern.indexOf('(')); + } + //add if it doesnt exist if (pattern.lineageIndex.indexOf(foundPattern) === -1){ diff --git a/builder/media_hunter.js b/builder/media_hunter.js index 0ac7a985f..3900d81ed 100644 --- a/builder/media_hunter.js +++ b/builder/media_hunter.js @@ -1,5 +1,5 @@ /* - * patternlab-node - v0.10.0 - 2015 + * patternlab-node - v0.10.1 - 2015 * * Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. @@ -17,10 +17,10 @@ var media_hunter = function(){ - function findMediaQueries(patternlab){ + function findMediaQueries(dir, patternlab){ patternlab.mediaQueries = []; - diveSync('./source/css', function(err, file){ + diveSync(dir, function(err, file){ if(path.extname(file) === '.css'){ var contents = fs.readFileSync(file, 'utf8'); var safeContents = contents.replace("\r", " ").replace("\n", " "); @@ -33,13 +33,16 @@ } } }); - //alpha sort for now, but should meet most use-cases except greater than 100ems. you are using ems right? - patternlab.mediaQueries.sort(); + patternlab.mediaQueries.sort(function(a,b){ + var integerPartA = a.match(/(?:\d*\.)?\d+/g); + var integerPartB = b.match(/(?:\d*\.)?\d+/g); + return parseInt(a,10) > parseInt(b,10); + }); } return { - find_media_queries: function(patternlab){ - findMediaQueries(patternlab); + find_media_queries: function(dir, patternlab){ + findMediaQueries(dir, patternlab); } }; diff --git a/builder/object_factory.js b/builder/object_factory.js index fe6ca3a1c..f1809b16e 100644 --- a/builder/object_factory.js +++ b/builder/object_factory.js @@ -1,5 +1,5 @@ /* - * patternlab-node - v0.10.0 - 2015 + * patternlab-node - v0.10.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 2e9947a6a..0541b211f 100644 --- a/builder/parameter_hunter.js +++ b/builder/parameter_hunter.js @@ -1,5 +1,5 @@ /* - * patternlab-node - v0.10.0 - 2015 + * patternlab-node - v0.10.1 - 2015 * * Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. @@ -40,7 +40,6 @@ var paramData = eval(paramString); //compile this partial immeadiately, essentially consuming it. - //TODO: see how this affects lineage. perhaps add manually here. var partialPattern = pattern_assembler.get_pattern_by_key(partialName, patternlab); var existingData = pattern.data || patternlab.data; @@ -48,7 +47,7 @@ for (var prop in paramData) { if (existingData.hasOwnProperty(prop)) { existingData[prop] = paramData[prop]; - } + } } //extend pattern data links into link for pattern link shortcuts to work. we do this locally and globally @@ -57,9 +56,6 @@ //remove the parameter from the partial and replace it with the rendered partial + paramData pattern.extendedTemplate = pattern.extendedTemplate.replace(pMatch, renderedPartial); - - //TODO: lineage is missing for this pattern - }); } } diff --git a/builder/pattern_assembler.js b/builder/pattern_assembler.js index 3f1a42639..a024a7dac 100644 --- a/builder/pattern_assembler.js +++ b/builder/pattern_assembler.js @@ -1,5 +1,5 @@ /* - * patternlab-node - v0.10.0 - 2015 + * patternlab-node - v0.10.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 cc84de047..61f62cccf 100644 --- a/builder/pattern_exporter.js +++ b/builder/pattern_exporter.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v0.10.0 - 2015 - * +/* + * patternlab-node - v0.10.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. * */ diff --git a/builder/patternlab.js b/builder/patternlab.js index f93c6fadb..74e4c186f 100644 --- a/builder/patternlab.js +++ b/builder/patternlab.js @@ -1,5 +1,5 @@ /* - * patternlab-node - v0.10.0 - 2015 + * patternlab-node - v0.10.1 - 2015 * * Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. @@ -113,7 +113,7 @@ var patternlab_engine = function () { patternlab.viewAllPaths = {}; //find mediaQueries - media_hunter.find_media_queries(patternlab); + media_hunter.find_media_queries('./source/css', patternlab); //build the styleguide var styleguideTemplate = fs.readFileSync('./source/_patternlab-files/styleguide.mustache', 'utf8'), diff --git a/builder/patternlab_grunt.js b/builder/patternlab_grunt.js index 3cd8d802e..a79854e6f 100644 --- a/builder/patternlab_grunt.js +++ b/builder/patternlab_grunt.js @@ -1,5 +1,5 @@ /* - * patternlab-node - v0.10.0 - 2015 + * patternlab-node - v0.10.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 98137cbe8..b2b74a125 100644 --- a/builder/pseudopattern_hunter.js +++ b/builder/pseudopattern_hunter.js @@ -1,5 +1,5 @@ /* - * patternlab-node - v0.10.0 - 2015 + * patternlab-node - v0.10.1 - 2015 * * Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. diff --git a/package.json b/package.json index 41cadb886..91df44efb 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.10.0", + "version": "0.10.1", "devDependencies": { "grunt": "~0.4.0", "grunt-contrib-watch": "^0.6.1", diff --git a/test/files/test.css b/test/files/test.css new file mode 100644 index 000000000..725f2054d --- /dev/null +++ b/test/files/test.css @@ -0,0 +1,19 @@ +@media only screen and (min-width: 35em){ + body{ + color: rebeccapurple; + } +} + +@media (min-width:50em){ body{ color: grey;} } + +@media only screen and (min-width: 70em) and (max-width: 1600px){ + body{ + color: green; + } +} + +@media only screen and( max-width: 50em){ + body{ + color: orange; + } +} diff --git a/test/lineage_hunter_tests.js b/test/lineage_hunter_tests.js index b80009404..d773f6d6e 100644 --- a/test/lineage_hunter_tests.js +++ b/test/lineage_hunter_tests.js @@ -93,7 +93,170 @@ test.equals(currentPattern.lineageIndex[2], "molecules-search"); test.done(); - } + }, + + 'test lineage hunter finds lineage with spaced pattern parameters' : function(test){ + //setup current pattern from what we would have during execution + var currentPattern = { + "name": "01-molecules-01-toast-00-error", + "subdir": "01-molecules\\01-toast", + "filename": "00-error.mustache", + "data": null, + "template": "{{> atoms-error(message: 'That\'s no moon...') }}", + "patternPartial": "{{> atoms-error(message: 'That\'s no moon...') }}", + "patternName": "error", + "patternLink": "01-molecules-01-toast-00-error/01-molecules-01-toast-00-error.html", + "patternGroup": "molecules", + "patternSubGroup": "molecules\\01-toast", + "flatPatternPath": "01-molecules\\01-toast", + "patternState": "", + "lineage": [], + "lineageIndex": [], + "lineageR": [], + "lineageRIndex": [] + }; + var patternlab = { + patterns: [ + { + "name": "01-atoms-05-alerts-00-error", + "subdir": "01-atoms\\05-alerts", + "filename": "00-error.mustache", + "data": null, + "template": "
{{description}}
", + "patternPartial": "", + "lineage": [ + ], + "lineageIndex": [ + ], + "lineageR": [ + ], + "lineageRIndex": [ + ], + "patternState": "", + "extendedTemplate": "{{description}}
" + } + ], + config: { + debug: false + }, + data: { + description: 'Not a quote from a smart man' + } + }; + + var parameter_hunter = new ph(); + + parameter_hunter.find_parameters(currentPattern, patternlab); + test.equals(currentPattern.extendedTemplate, 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.
'); + + test.done(); + }, + + 'pattern hunter finds and extends templates with mixed parameter and global data' : function(test){ + + //setup current pattern from what we would have during execution + var currentPattern = { + "fileName": "01-sticky-comment", + "subdir": "02-organisms/02-comments", + "name": "02-organisms-02-comments-01-sticky-comment", + "data": null, + "jsonFileData": {}, + "patternName": "sticky-comment", + "patternLink": "02-organisms-02-comments-01-sticky-comment/02-organisms-02-comments-01-sticky-comment.html", + "patternGroup": "organisms", + "patternSubGroup": "comments", + "flatPatternPath": "02-organisms-02-comments", + "key": "organisms-sticky-comment", + "template": "{{> molecules-single-comment(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}", + "patternPartial": "", + "lineage": [ + ], + "lineageIndex": [ + ], + "lineageR": [ + ], + "lineageRIndex": [ + ], + "patternState": "", + "extendedTemplate": "{{> molecules-single-comment(description: 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.') }}" + }; + var patternlab = { + patterns: [ + { + "fileName": "02-single-comment", + "subdir": "01-molecules/06-components", + "name": "01-molecules-06-components-02-single-comment", + "data": null, + "jsonFileData": {}, + "patternName": "single-comment", + "patternLink": "01-molecules-06-components-02-single-comment/01-molecules-06-components-02-single-comment.html", + "patternGroup": "molecules", + "patternSubGroup": "components", + "flatPatternPath": "01-molecules-06-components", + "key": "molecules-single-comment", + "template": "{{description}}
", + "patternPartial": "", + "lineage": [ + ], + "lineageIndex": [ + ], + "lineageR": [ + ], + "lineageRIndex": [ + ], + "patternState": "", + "extendedTemplate": "{{description}}
" + } + ], + config: { + debug: false + }, + data: { + foo: 'Bar', + description: 'Baz' + } + }; + + var parameter_hunter = new ph(); + + parameter_hunter.find_parameters(currentPattern, patternlab); + test.equals(currentPattern.extendedTemplate, 'A life is like a garden. Perfect moments can be had, but not preserved, except in memory.
'); + + test.done(); + }, + + }; + +}()); diff --git a/test/pattern_assembler_tests.js b/test/pattern_assembler_tests.js new file mode 100644 index 000000000..361b6f15d --- /dev/null +++ b/test/pattern_assembler_tests.js @@ -0,0 +1,26 @@ +(function () { + "use strict"; + + var pa = require('../builder/pattern_assembler'); + + exports['pattern_assembler'] = { + 'find_pattern_partials finds partials' : function(test){ + + //setup current pattern from what we would have during execution + var currentPattern = { + "template": "