From 4e0ad4daba44242cc833788984304be5f445348b Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Fri, 26 Feb 2016 11:22:34 -0600 Subject: [PATCH 01/37] Support for configuring a default pattern in config.json --- builder/patternlab.js | 6 +++++- config.json | 1 + core/styleguide/js/styleguide.js | 10 ++++++---- source/_patternlab-files/index.mustache | 5 +++-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/builder/patternlab.js b/builder/patternlab.js index aae791f23..9b99f3553 100644 --- a/builder/patternlab.js +++ b/builder/patternlab.js @@ -473,7 +473,11 @@ var patternlab_engine = function (config) { var viewAllPathsPartialHtml = pattern_assembler.renderPattern(viewAllPathsTemplate, {'viewallpaths': JSON.stringify(patternlab.viewAllPaths)}); //render the patternlab template, with all partials - var patternlabSiteHtml = pattern_assembler.renderPattern(patternlabSiteTemplate, {}, { + debugger; + + var patternlabSiteHtml = pattern_assembler.renderPattern(patternlabSiteTemplate, { + defaultPattern: patternlab.config.defaultPattern || 'all' + }, { 'ishControls': ishControlsPartialHtml, 'patternNav': patternNavPartialHtml, 'patternPaths': patternPathsPartialHtml, diff --git a/config.json b/config.json index 0ca6ef1f0..204bdd651 100644 --- a/config.json +++ b/config.json @@ -26,6 +26,7 @@ "templates", "pages" ], + "defaultPattern": "all", "ignored-extensions" : ["scss", "DS_Store", "less"], "ignored-directories" : ["scss"], "debug": false, diff --git a/core/styleguide/js/styleguide.js b/core/styleguide/js/styleguide.js index 44adb6561..ce83f10d5 100644 --- a/core/styleguide/js/styleguide.js +++ b/core/styleguide/js/styleguide.js @@ -469,16 +469,18 @@ } // load the iframe source - var patternName = "all"; + var patternName = window.defaultPattern || "all"; var patternPath = ""; - var iFramePath = window.location.protocol+"//"+window.location.host+window.location.pathname.replace("index.html","")+"styleguide/html/styleguide.html"; + var iFramePath = window.location.protocol + "//" + window.location.host + window.location.pathname.replace("index.html","") + "styleguide/html/styleguide.html"; + + // if we were passed some url parameters, deal with it if ((oGetVars.p != undefined) || (oGetVars.pattern != undefined)) { patternName = (oGetVars.p != undefined) ? oGetVars.p : oGetVars.pattern; - patternPath = urlHandler.getFileName(patternName); - iFramePath = (patternPath != "") ? window.location.protocol+"//"+window.location.host+window.location.pathname.replace("index.html","")+patternPath : iFramePath; } if (patternName != "all") { + patternPath = urlHandler.getFileName(patternName); + iFramePath = (patternPath != "") ? window.location.protocol + "//" + window.location.host + window.location.pathname.replace("index.html","") + patternPath : iFramePath; document.getElementById("title").innerHTML = "Pattern Lab - "+patternName; history.replaceState({ "pattern": patternName }, null, null); } diff --git a/source/_patternlab-files/index.mustache b/source/_patternlab-files/index.mustache index 1688121dd..d98ce37d5 100644 --- a/source/_patternlab-files/index.mustache +++ b/source/_patternlab-files/index.mustache @@ -10,6 +10,7 @@ + > @@ -21,7 +22,7 @@ - +
@@ -91,4 +92,4 @@ - \ No newline at end of file + From 875265208d6c3aed791c119f005d114f2c1d7d58 Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Fri, 26 Feb 2016 15:13:27 -0600 Subject: [PATCH 02/37] Add glob to match ?p= pattern URLs on the main UI chrome so BrowserSync won't load on both in the case where you select a specific pattern and then refresh the whole page. --- Gruntfile.js | 2 +- gulpfile.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 06c6cf6d2..68f7e6dfb 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -103,7 +103,7 @@ module.exports = function(grunt) { }, snippetOptions: { // Ignore all HTML files within the templates folder - blacklist: ['/index.html', '/'] + blacklist: ['/index.html', '/', '/?p=*'] }, plugins: [ { diff --git a/gulpfile.js b/gulpfile.js index fb15e1439..e64b0ae27 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -110,7 +110,7 @@ gulp.task('connect', ['lab'], function () { }, snippetOptions: { // Ignore all HTML files within the templates folder - blacklist: ['/index.html', '/'] + blacklist: ['/index.html', '/', '/?p=*'] }, notify: { styles: [ From 276761f9da04ceece246034aec72fbba7a4379d0 Mon Sep 17 00:00:00 2001 From: New Geoff Date: Fri, 26 Feb 2016 20:53:22 -0600 Subject: [PATCH 03/37] add .editorconfig and .eslintrc from pattern-engines branch --- .editorconfig | 11 ++++++++ .eslintrc | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 .editorconfig create mode 100644 .eslintrc diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..8951c3929 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +# editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +tab_width = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 000000000..4edaeae26 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,74 @@ +{ + "env": { + "node": true, + "builtin": true + }, + "globals": {}, + "rules": { + "block-scoped-var": 2, + "camelcase": 0, + "curly": [ + 2, + "all" + ], + "dot-notation": [ + 1, + { + "allowKeywords": true + } + ], + "eqeqeq": [ + 2, + "allow-null" + ], + "global-strict": [ + 0, + "never" + ], + "guard-for-in": 2, + "key-spacing": [ + 0 + ], + "new-cap": 0, + "no-bitwise": 2, + "no-caller": 2, + "no-cond-assign": [ + 2, + "except-parens" + ], + "no-debugger": 2, + "no-empty": 2, + "no-eval": 2, + "no-extend-native": 2, + "no-extra-parens": 0, + "no-irregular-whitespace": 1, + "no-iterator": 2, + "no-loop-func": 2, + "no-mixed-requires": 0, + "no-multi-str": 2, + "no-multi-spaces": 0, + "no-new": 2, + "no-proto": 2, + "no-script-url": 2, + "no-sequences": 2, + "no-shadow": 2, + "no-undef": 2, + "no-underscore-dangle": 1, + "no-unused-vars": 2, + "no-with": 2, + "quotes": [ + 0, + "single" + ], + "semi": [ + 0, + "never" + ], + "strict": 0, + "valid-typeof": 2, + "wrap-iife": [ + 2, + "inside" + ] + } +} From 6ad1f85295cb61b6315e85e68111f31897e8fe88 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Fri, 26 Feb 2016 22:47:18 -0600 Subject: [PATCH 04/37] deleting the changelog in favor of https://github.com/pattern-lab/patternlab-node/wiki/ChangeLog closes #268 --- CHANGELOG | 232 ------------------------------------------------------ 1 file changed, 232 deletions(-) delete mode 100644 CHANGELOG diff --git a/CHANGELOG b/CHANGELOG deleted file mode 100644 index 8ad1f0731..000000000 --- a/CHANGELOG +++ /dev/null @@ -1,232 +0,0 @@ -THIS CHANGELOG IS AN ATTEMPT TO DOCUMENT CHANGES TO THIS PROJECT. - -PL-node-v1.1.3 -- FIX: Added pattern type view all pages to the navigation, which users view all 'Atoms/Molecules/Organisms' etc. -- THX: Thanks to @gael-boyenval for originally pointing out the omission. - -PL-node-v1.1.2 -- FIX: Greatly improved the browsersync configuration, so that it only fires on the iframe, preventing users from losing their scroll position. Also lightened up the styling and made it less obtrusive. -- THX: Thanks to @geoffp for taking the lead on this issue. -- THX: This release also marks the first with @geoff's more official involvement with the project as a core contributor. His work on the `pattern_engine` branch and configurable paths have and will continue to make Pattern Lab Node better. -- FIX: Replace `eval()` with a smarter `JSON.parse()` call within the `parameter_hunter.js` -- THX: Thanks to @e2tha-e for taking the high road! - -PL-node-v1.1.1 -- FIX: Fixed issue where alternate patterns are added to end of styleguide instead of inline with their parent pattern. - -PL-node-v1.1.0 -- FIX: Fixed issue where partials containing styleModifiers with integers were not found correctly under all circumstances -- FIX: Fixed issue where excluded patterns were still rendered on the Pattern Lab site. Now they do not directly get rendered via the menu, view all links, or the styleguide, but are accessible for inclusion as pattern partials, and can be accessed via lineage. -- THX: Thanks @theorise for reporting these issues. -- THX: Thanks @dmolsen for input on desired behavior. -- FIX: Fixed issue where style modifier partials within list item blocks where not uniquely being applied. this seems like a regression. added a unit test with fix -- ADD: Added fuzzy pattern matching support based on patternType-substring(patternName) to align with PL PHP -- FIX: Fixed issue with gulpfile not copying style.css and watching the wrong directory -- THX: Thanks @robinsonaaron for the issue and pull request! -- FIX: Prefer exact pattern key match over fuzzy matches inside getpatternbykey() -- THX: Thanks @EvanLovely for the suggestion -- ADD: Make all paths configurable -- THX: HUGE Thanks to @geoffp and @EvanLovely for their thoughts, time, and talent to make this a reality! -- FIX: Fix issue where absolute paths in the config path object would not resolve -- THX: Thanks to @geoffp and @EvanLovely for reporting, fixing and testing the issue in the dev branch. -- FIX: Typo in gulp instructions in README. -- THX: Thanks @simonknittel for the watchful eyes -- CHG: Changed locations of ./public/styleguide to ./core/styleguide to make ./public/ a cleaner distribution directory -- CHG: Removed scss files and config from project. This is in preparation for including the default asset repo in the future -- FIX: Fix issue where partials were not being sent to Mustache during pattern parameter parsing. -- THX: Thanks to @e2tha-e for reporting this issue. -- ADD: Now patterns and pseudopatterns can be linked from global or file data.json -- THX: Thanks @kylewelsby for the thoughtful enhancement - -PL-node-v1.0.0 -- FIX: Resolve issue with not hiding underscored patterns. -- THX: Thanks @ivancamilov for reporting this regression. -- FIX: Fix misapplied error input class -- THX: Thanks @johngerome for the pull request! -- ADD: Added a note in the README during installation to run with elevated privileges -- THX: Thanks @RichardBray for the heads up -- ADD: Added a Prerequisites section to the README -- ADD: Added unit tests for pattern states and pseudopatterns -- CHG: Changed pseudopattern generation to use config.patterns.source directory instead of hardcode -- CHG: Explicitly sorting patterns by name prior to building the UI -- ADD: Added ability to specify link.* urls inside data objects -- CHG: Incremented version to 1.0.0. Achieved near-parity with PL PHP 1! -- THX: Thanks to each and every person who cared about Pattern Lab Node! - Brian - -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. - -PL-node-v0.14.0 -- ADD: Support for style modifiers -- ADD: Support for styleGuideExcludes -- THX: Thanks to @bramsmulders for the styleGuideExcludes pull request and @illepic for the original headsup -- FIX: Fix an issue where listitem blocks would only render if the pattern containing the block had a partial within it - -PL-node-v0.13.1 -- FIX: Allow verbose partials for list items -- THX: Thanks @e2tha-e - -PL-node-v0.13.0 -- FIX: Cleanup an old file and an incorrect entry in the .gitignore file -- CHG: Change order of pattern addition and ~variant pattern addition so they build naturally in the menu. -- THX: Thanks @e2tha-e for the flurry of pull requests! -- CHG: Update data merge function to prioritize handle pattern~variant.json files -- THX: Thanks @e2tha-e for finding, fixing, and unit testing the data merge issue. -- ADD: Support for recursive partial inclusion -- THX: Thanks @e2tha-e for making pattern inclusion a lot more robust. Great work!!! -- FIX: Improvements to style guide menu generation and capitalization. - -PL-node-v0.12.0 - - ADD: Gulp support arrives with an optional configuration - - ADD: Instructions how to install and run with Gulp - - DEL: Deleted the sass modules from `package.json` files - - CHG: Commented out all sass tasks in Grunt and Gulp files - - CHG: Changed static web server provider to BrowserSync - - CHG: Replaced the Style Guide toolbar Auto-Reload and Page Follow with a link to the BrowserSync UI - - THX: Thanks @oscar-g for the initial work on the gulpfile! - - ADD: An alternative, more verbose syntax for pattern partial inclusion - - THX: Thanks @e2tha-e for the thoughtful addition with unit test coverage - -PL-node-v0.11.0 - - ADD: Ignore pattern directories that start with an underscore. - - ADD: Support for lists with the listItems variable - - FIX: Resolved issue where pattern parameter data bled into global data object - - ADD: Support a fluid viewport - -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. - - CHG: Refactored a lot of code out of patternlab.js and into separate files. Doing so should make everything dryer, more unit testable, and easier to understand I hope. - - ADD: Added proper styling for the homepage-emergency alert that is displayed for demo purposes - - 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 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 - -PL-node-v0.9.0 - - FIX: Added grunt-contrib-copy args to copy all found source/css/*.css - - ADD: Added upgrade instructions to README - - FIX: Fix issue with styleguide accordions not closing upon click of a sibling menu. - - THX: @getsetbro for reporting more issues :) - - ADD: Added support for pattern search. This is 'in beta' and should have more testing applied to it. - - ADD: Added support for all keyboard shortcuts found in PL-PHP-v1.0.0 - - FIX: Fixed an issue where Hay mode and Disco mode did not stop one another when using keyboard shortcuts - - FIX: Fix location of paragraph closing tag to wrap citation - - THX: @laurendorman for the pull request! - - FIX: Removed some dead code. - - ADD: Added View All links in each menu subsection - - THX: BIG THANKS TO @walmokrani for this work! - -PL-node-v0.8.1 - - FIX: v8 is not pulling in values from global data.json - - FIX: MQ list breaks if media queries don't have spaces - - THX: @getsetbro for reporting these issues :D - - THX: @dmolsen for a cheat codes - -PL-node-v0.8.0 - - CHG: note the change in versioning to proper semver. wanted to do ths to inch closer to a 1.0.0 release - - DEL: deleted most of the lingering PHP sync listener code - - FIX: support for displaying the HTML and Mustache in the code viewer - - ADD: pattern link support - - CHG: updated included mustache templates to reflect pattern links in navigation and compiling pages direct from templates - - THX: @getsetbro for finding and fixing a typo - - FIX: fixed a bug preventing pattern states from displaying on the flat template/pages - - ADD: support for basic pseudo-patterns - - CHG: cleaned up patternlab.js a bit for future testing, a bit more DRYness. - -PL-node-v0.1.7 - - ADD: pattern export - - CHG: updated devDependencies - - FIX: fixed a type in the README and config - - THX: thanks @seanhussey for the pull request! - -PL-node-v0.1.6 - - ADD: media queries found in css added to ish controls - - ADD: basic lineage support - - ADD: more unit tests - -PL-node-v0.1.5 - - ADD: Live reload support for grunt serve task - - THX: thanks @marcinmodestowicz for the configuration fix. VERY useful :) - -PL-node-v0.1.4 - - FIX: Resolved issue with nested pattern rendering - - FIX: Supporting flat pattern name regex's in unix-systems - - THX: thanks @torbs for the issue and pull request - -PL-node-v0.1.3 - - ADD: Pattern states - - ADD: Ships with grunt connect if you are into that kinda thing - - FIX: Removed all grunt dependencies from patternlab.js - - FIX: Ignore dotfiles - - THX: thanks @bramsmulders for suggestion and help with mac - -PL-node-v0.1.2 - - ADD: Abstracted template rendering into a function for easier swapping of rendering engine - - ADD: Smarter filtering of files to support other templates Thanks - - ADD: Help command line agument - - ADD: Version command line argument - - ADD: Patterns only command line argument - - ADD: IshControlsVisible options. Can now hide any ishControls you like. - - ADD: Documented the command line interface - - CHG: Put debug flag in conf.json instead of package.json - - CHG: Aligned styleguide css with patternlab-php - - FIX: Removed node .8 from travis - - FIX: Code and annotation support in patternlab viewer - - THX: thanks @ivanmayes and Shoptology crew for contibutions! - -PL-node-v0.1.1 - - FIX: Removed View All Pattern SubItem Link Logic, no longer in reference implementation - - ADD: Flag for generating debug file - - ADD: Travis CI test support! - - ADD: Contributing file - - ADD: Repository to package.json - - FIX: Manage Mustache dependency using NPM - - THX: thank you @tbranyen for tip on repository, Mustache, and NPM! - -PL-node-v0.1.0 - - FIX: Links to patterns did not work when visited from a server - - FIX: Patterns with hyphens in the name were breaking the iframe messaging - - FIX: Added stlyeguide/js files that were ignored at one point - - FIX: Watch _data/*.json files too - - FIX: Copy images, in an attempt to exclude files like Thumbs.db - - FIX: Typos in CHANGELOG - - ADD: A banner to patternlab.js - -PL-node-v0.0.5 - - FIX: typo in organisms global header - - FIX: flat-structured pattern items rendered as if they had sub-menus #4 - - ADD: Load all grunt tasks using matchdep - - THX: thanks to @colynb for the typo heads up - - THX: shoutout to @joemcgill for better dependency loading - -PL-node-v0.0.4 - - ADD: An explicit MIT license - - FIX: Clean public/patterns/ before build - -PL-node-v0.0.3 - - FIX: Install documentation was incomplete, should not have assumed grunt - - FIX: Remove SASS/SCSS dependency which was causing clean installs from failing - -PL-node-v0.0.2 - - FIX: Sub Nav Items now strip hyphens and are styled like patternlab-php. - - FIX: Exclude patterns by using an underscore - - FIX: Grunt watching styleguide scss - -PL-node-v0.0.1 - - Minimum Viable Product! At this point, I feel you could use Pattern Lab Node to build an atomic design-driven website. From 4dbe10d48c13ea779ef0f392b3e2a0fa52a547f3 Mon Sep 17 00:00:00 2001 From: New Geoff Date: Sat, 27 Feb 2016 10:19:42 -0600 Subject: [PATCH 05/37] Make the glob include anything with a parameter right after the leading slash. This covers these URL patterns as well: http://patternlab.io/docs/pattern-linking.htmla --- Gruntfile.js | 2 +- gulpfile.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 68f7e6dfb..4eef71c14 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -103,7 +103,7 @@ module.exports = function(grunt) { }, snippetOptions: { // Ignore all HTML files within the templates folder - blacklist: ['/index.html', '/', '/?p=*'] + blacklist: ['/index.html', '/', '/?*'] }, plugins: [ { diff --git a/gulpfile.js b/gulpfile.js index e64b0ae27..fb5593def 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -110,7 +110,7 @@ gulp.task('connect', ['lab'], function () { }, snippetOptions: { // Ignore all HTML files within the templates folder - blacklist: ['/index.html', '/', '/?p=*'] + blacklist: ['/index.html', '/', '/?*'] }, notify: { styles: [ From 4f4b06ccfcdc3e98d9fdf619cb5a72af3b16ce2e Mon Sep 17 00:00:00 2001 From: New Geoff Date: Sat, 27 Feb 2016 11:24:04 -0600 Subject: [PATCH 06/37] Better .eslintrc with more rules --- .eslintrc | 77 +++++++++++++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/.eslintrc b/.eslintrc index 4edaeae26..d8f2a98e5 100644 --- a/.eslintrc +++ b/.eslintrc @@ -7,68 +7,67 @@ "rules": { "block-scoped-var": 2, "camelcase": 0, - "curly": [ - 2, - "all" - ], - "dot-notation": [ - 1, - { - "allowKeywords": true - } - ], - "eqeqeq": [ - 2, - "allow-null" - ], - "global-strict": [ - 0, - "never" - ], + "consistent-return": 2, + "curly": [2, "all"], + "dot-notation": [1, { "allowKeywords": true }], + "eqeqeq": [2, "allow-null"], + "global-strict": [0, "never"], "guard-for-in": 2, - "key-spacing": [ - 0 - ], + "indent": [2, 2, {"SwitchCase": 2, "VariableDeclarator": 2}], + "key-spacing": 0, "new-cap": 0, + "no-alert": 2, "no-bitwise": 2, "no-caller": 2, - "no-cond-assign": [ - 2, - "except-parens" - ], + "no-cond-assign": [2, "except-parens"], "no-debugger": 2, + "no-dupe-args": 2, + "no-dupe-keys": 2, "no-empty": 2, "no-eval": 2, "no-extend-native": 2, + "no-extra-bind": 2, "no-extra-parens": 0, + "no-extra-semi": 2, + "no-func-assign": 2, + "no-implied-eval": 2, + "no-invalid-regexp": 2, "no-irregular-whitespace": 1, "no-iterator": 2, "no-loop-func": 2, "no-mixed-requires": 0, "no-multi-str": 2, - "no-multi-spaces": 0, + "no-multi-spaces": 1, + "no-native-reassign": 2, "no-new": 2, + "no-param-reassign": 2, "no-proto": 2, + "no-redeclare": 2, "no-script-url": 2, + "no-self-assign": 2, + "no-self-compare": 2, "no-sequences": 2, "no-shadow": 2, "no-undef": 2, "no-underscore-dangle": 1, - "no-unused-vars": 2, + "no-unreachable": 1, + "no-unused-vars": 1, + "no-use-before-define": 1, + "no-useless-call": 2, + "no-useless-concat": 2, "no-with": 2, - "quotes": [ - 0, - "single" - ], - "semi": [ - 0, - "never" - ], + "quotes": [0, "single"], + "radix": 2, + "semi": [0, "never"], "strict": 0, + "space-before-blocks": 1, + "space-before-function-paren": [1, { + "anonymous": "always", + "named": "never" + }], + "space-infix-ops": 1, "valid-typeof": 2, - "wrap-iife": [ - 2, - "inside" - ] + "vars-on-top": 0, + "wrap-iife": [2, "inside"] } } From fae00ec743ad4c9f003392366c27b1ba3d480953 Mon Sep 17 00:00:00 2001 From: New Geoff Date: Sat, 27 Feb 2016 11:24:27 -0600 Subject: [PATCH 07/37] Reformatted lineage_hunter.js to pass lint --- builder/lineage_hunter.js | 146 +++++++++++++++++++------------------- 1 file changed, 74 insertions(+), 72 deletions(-) diff --git a/builder/lineage_hunter.js b/builder/lineage_hunter.js index 7325a5fde..6d3c8cf3e 100644 --- a/builder/lineage_hunter.js +++ b/builder/lineage_hunter.js @@ -1,76 +1,78 @@ -/* - * patternlab-node - v1.1.3 - 2016 - * +/* + * patternlab-node - v1.1.3 - 2016 + * * 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. * */ -(function () { - "use strict"; - - var lineage_hunter = function(){ - - function findlineage(pattern, patternlab){ - - var pa = require('./pattern_assembler'); - var pattern_assembler = new pa(); - - //find the {{> template-name }} within patterns - var matches = pattern_assembler.find_pattern_partials(pattern); - if(matches !== null){ - matches.forEach(function(match, index, matches){ - //strip out the template cruft - var foundPatternKey = 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(foundPatternKey.indexOf('(') > 0){ - foundPatternKey = foundPatternKey.substring(0, foundPatternKey.indexOf('(')); - } - - //remove any potential stylemodifiers. - foundPatternKey = foundPatternKey.split(':')[0]; - - //get the ancestorPattern - var ancestorPattern = pattern_assembler.get_pattern_by_key(foundPatternKey, patternlab); - - if (ancestorPattern && pattern.lineageIndex.indexOf(ancestorPattern.key) === -1){ - - //add it since it didnt exist - pattern.lineageIndex.push(ancestorPattern.key); - //create the more complex patternLineage object too - var l = { - "lineagePattern": ancestorPattern.key, - "lineagePath": "../../patterns/" + ancestorPattern.patternLink - }; - pattern.lineage.push(JSON.stringify(l)); - - //also, add the lineageR entry if it doesn't exist - if (ancestorPattern.lineageRIndex.indexOf(pattern.key) === -1){ - ancestorPattern.lineageRIndex.push(pattern.key); - - //create the more complex patternLineage object in reverse - var lr = { - "lineagePattern": pattern.key, - "lineagePath": "../../patterns/" + pattern.patternLink - }; - ancestorPattern.lineageR.push(JSON.stringify(lr)); - } - } - }); - } - } - - return { - find_lineage: function(pattern, patternlab){ - findlineage(pattern, patternlab); - } - }; - - }; - - module.exports = lineage_hunter; - -}()); +"use strict"; + +var lineage_hunter = function () { + + function findlineage(pattern, patternlab) { + + var pa = require('./pattern_assembler'); + var pattern_assembler = new pa(); + + //find the {{> template-name }} within patterns + var matches = pattern_assembler.find_pattern_partials(pattern); + if(matches !== null) { + matches.forEach(function (match) { + //strip out the template cruft + var foundPatternKey = 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(foundPatternKey.indexOf('(') > 0) { + foundPatternKey = foundPatternKey.substring(0, foundPatternKey.indexOf('(')); + } + + //remove any potential stylemodifiers. + foundPatternKey = foundPatternKey.split(':')[0]; + + //get the ancestorPattern + var ancestorPattern = pattern_assembler.get_pattern_by_key(foundPatternKey, patternlab); + + if (ancestorPattern && pattern.lineageIndex.indexOf(ancestorPattern.key) === -1) { + + //add it since it didnt exist + pattern.lineageIndex.push(ancestorPattern.key); + //create the more complex patternLineage object too + var l = { + "lineagePattern": ancestorPattern.key, + "lineagePath": "../../patterns/" + ancestorPattern.patternLink + }; + pattern.lineage.push(JSON.stringify(l)); + + //also, add the lineageR entry if it doesn't exist + if (ancestorPattern.lineageRIndex.indexOf(pattern.key) === -1) { + ancestorPattern.lineageRIndex.push(pattern.key); + + //create the more complex patternLineage object in reverse + var lr = { + "lineagePattern": pattern.key, + "lineagePath": "../../patterns/" + pattern.patternLink + }; + ancestorPattern.lineageR.push(JSON.stringify(lr)); + } + } + }); + } + } + + return { + find_lineage: function (pattern, patternlab) { + findlineage(pattern, patternlab); + } + }; + +}; + +module.exports = lineage_hunter; From 31b94bd0b240b86eaf95398c3f98e78dfa01dcff Mon Sep 17 00:00:00 2001 From: New Geoff Date: Sat, 27 Feb 2016 11:53:16 -0600 Subject: [PATCH 08/37] add keyword spacing rule and update lineage_hunter to match --- .eslintrc | 1 + builder/lineage_hunter.js | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.eslintrc b/.eslintrc index d8f2a98e5..05ba56ae1 100644 --- a/.eslintrc +++ b/.eslintrc @@ -15,6 +15,7 @@ "guard-for-in": 2, "indent": [2, 2, {"SwitchCase": 2, "VariableDeclarator": 2}], "key-spacing": 0, + "keyword-spacing": 2, "new-cap": 0, "no-alert": 2, "no-bitwise": 2, diff --git a/builder/lineage_hunter.js b/builder/lineage_hunter.js index 6d3c8cf3e..65a0e35cc 100644 --- a/builder/lineage_hunter.js +++ b/builder/lineage_hunter.js @@ -19,7 +19,7 @@ var lineage_hunter = function () { //find the {{> template-name }} within patterns var matches = pattern_assembler.find_pattern_partials(pattern); - if(matches !== null) { + if (matches !== null) { matches.forEach(function (match) { //strip out the template cruft var foundPatternKey = match @@ -30,7 +30,7 @@ var lineage_hunter = function () { // 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(foundPatternKey.indexOf('(') > 0) { + if (foundPatternKey.indexOf('(') > 0) { foundPatternKey = foundPatternKey.substring(0, foundPatternKey.indexOf('(')); } @@ -44,6 +44,7 @@ var lineage_hunter = function () { //add it since it didnt exist pattern.lineageIndex.push(ancestorPattern.key); + //create the more complex patternLineage object too var l = { "lineagePattern": ancestorPattern.key, From 6db75a91edc298f1b51d8ad9c7bf58e9c5c883b7 Mon Sep 17 00:00:00 2001 From: New Geoff Date: Sat, 27 Feb 2016 15:23:16 -0600 Subject: [PATCH 09/37] more rule refinements --- .eslintrc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.eslintrc b/.eslintrc index 05ba56ae1..bcef947ef 100644 --- a/.eslintrc +++ b/.eslintrc @@ -7,15 +7,23 @@ "rules": { "block-scoped-var": 2, "camelcase": 0, + "comma-spacing": [1, {"before": false, "after": true}], "consistent-return": 2, "curly": [2, "all"], "dot-notation": [1, { "allowKeywords": true }], "eqeqeq": [2, "allow-null"], "global-strict": [0, "never"], "guard-for-in": 2, - "indent": [2, 2, {"SwitchCase": 2, "VariableDeclarator": 2}], + "indent": [2, 2, {"SwitchCase": 1, "VariableDeclarator": 2}], + "lines-around-comment": [2, { + "beforeBlockComment": true, + "beforeLineComment": true, + "allowBlockStart": true, + "allowObjectStart": true, + "allowArrayStart": true + }], "key-spacing": 0, - "keyword-spacing": 2, + "keyword-spacing": 1, "new-cap": 0, "no-alert": 2, "no-bitwise": 2, @@ -50,7 +58,7 @@ "no-sequences": 2, "no-shadow": 2, "no-undef": 2, - "no-underscore-dangle": 1, + "no-underscore-dangle": 0, "no-unreachable": 1, "no-unused-vars": 1, "no-use-before-define": 1, @@ -66,6 +74,7 @@ "anonymous": "always", "named": "never" }], + "space-in-parens": [1, "never"], "space-infix-ops": 1, "valid-typeof": 2, "vars-on-top": 0, From 8f27e792f6e33002440ec315610417ce06dc322e Mon Sep 17 00:00:00 2001 From: New Geoff Date: Sat, 27 Feb 2016 15:23:26 -0600 Subject: [PATCH 10/37] more reformatting and tweaks --- builder/list_item_hunter.js | 225 ++++++------ builder/media_hunter.js | 84 +++-- builder/object_factory.js | 110 +++--- builder/parameter_hunter.js | 167 ++++----- builder/pattern_assembler.js | 673 ++++++++++++++++++----------------- 5 files changed, 626 insertions(+), 633 deletions(-) diff --git a/builder/list_item_hunter.js b/builder/list_item_hunter.js index 93aa57890..62e8f5538 100644 --- a/builder/list_item_hunter.js +++ b/builder/list_item_hunter.js @@ -1,120 +1,115 @@ -/* - * patternlab-node - v1.1.3 - 2016 - * +/* + * patternlab-node - v1.1.3 - 2016 + * * 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. * */ -(function () { - "use strict"; - - var list_item_hunter = function(){ - - var extend = require('util')._extend, - pa = require('./pattern_assembler'), - smh = require('./style_modifier_hunter'), - mustache = require('mustache'), - pattern_assembler = new pa(), - style_modifier_hunter = new smh(), - items = [ 'zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen','twenty']; - - function processListItemPartials(pattern, patternlab){ - //find any listitem blocks - var matches = pattern_assembler.find_list_items(pattern, patternlab); - if(matches !== null){ - matches.forEach(function(liMatch, index, matches){ - - if(patternlab.config.debug){ - console.log('found listItem of size ' + liMatch + ' inside ' + pattern.key); - } - - //find the boundaries of the block - var loopNumberString = liMatch.split('.')[1].split('}')[0].trim(); - var end = liMatch.replace('#', '/'); - var patternBlock = pattern.template.substring(pattern.template.indexOf(liMatch) + liMatch.length, pattern.template.indexOf(end)).trim(); - //build arrays that repeat the block, however large we need to - var repeatedBlockTemplate = []; - var repeatedBlockHtml = ''; - for(var i = 0; i < items.indexOf(loopNumberString); i++){ - repeatedBlockTemplate.push(patternBlock); - } - - //check for a local listitems.json file - var listData = JSON.parse(JSON.stringify(patternlab.listitems)); - listData = pattern_assembler.merge_data(listData, pattern.listitems); - - //iterate over each copied block, rendering its contents along with pattenlab.listitems[i] - for(var i = 0; i < repeatedBlockTemplate.length; i++){ - - var thisBlockTemplate = repeatedBlockTemplate[i]; - var thisBlockHTML = ""; - - //combine listItem data with pattern data with global data - var itemData = listData['' + items.indexOf(loopNumberString)]; //this is a property like "2" - var globalData = JSON.parse(JSON.stringify(patternlab.data)); - var localData = JSON.parse(JSON.stringify(pattern.jsonFileData)); - - var allData = pattern_assembler.merge_data(globalData, localData); - allData = pattern_assembler.merge_data(allData, itemData != undefined ? itemData[i] : {}); //itemData could be undefined if the listblock contains no partial, just markup - allData.link = extend({}, patternlab.data.link); - - //check for partials within the repeated block - var foundPartials = pattern_assembler.find_pattern_partials({ 'template' : thisBlockTemplate }); - - if(foundPartials && foundPartials.length > 0){ - - for(var j = 0; j < foundPartials.length; j++){ - - //get the partial - var partialName = foundPartials[j].match(/([\w\-\.\/~]+)/g)[0]; - var partialPattern = pattern_assembler.get_pattern_by_key(partialName, patternlab); - - //create a copy of the partial so as to not pollute it after the get_pattern_by_key call. - var cleanPartialPattern = JSON.parse(JSON.stringify(partialPattern)); - - //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); - } - - //replace its reference within the block with the extended template - thisBlockTemplate = thisBlockTemplate.replace(foundPartials[j], cleanPartialPattern.extendedTemplate); - } - - //render with data - thisBlockHTML = pattern_assembler.renderPattern(thisBlockTemplate, allData, patternlab.partials); - - } else{ - //just render with mergedData - thisBlockHTML = pattern_assembler.renderPattern(thisBlockTemplate, allData, patternlab.partials); - } - - //add the rendered HTML to our string - repeatedBlockHtml = repeatedBlockHtml + thisBlockHTML; - } - - //replace the block with our generated HTML - var repeatingBlock = pattern.extendedTemplate.substring(pattern.extendedTemplate.indexOf(liMatch), pattern.extendedTemplate.indexOf(end) + end.length); - pattern.extendedTemplate = pattern.extendedTemplate.replace(repeatingBlock, repeatedBlockHtml); - - //update the extendedTemplate in the partials object in case this pattern is consumed later - patternlab.partials[pattern.key] = pattern.extendedTemplate; - - }); - } - } - - return { - process_list_item_partials: function(pattern, patternlab){ - processListItemPartials(pattern, patternlab); - } - }; - - }; - - module.exports = list_item_hunter; -}()); +"use strict"; + +var list_item_hunter = function () { + + var extend = require('util')._extend, + pa = require('./pattern_assembler'), + smh = require('./style_modifier_hunter'), + pattern_assembler = new pa(), + style_modifier_hunter = new smh(), + items = [ 'zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen','twenty']; + + function processListItemPartials(pattern, patternlab) { + //find any listitem blocks + var matches = pattern_assembler.find_list_items(pattern, patternlab); + if (matches !== null) { + matches.forEach(function (liMatch) { + + if (patternlab.config.debug) { + console.log('found listItem of size ' + liMatch + ' inside ' + pattern.key); + } + + //find the boundaries of the block + var loopNumberString = liMatch.split('.')[1].split('}')[0].trim(); + var end = liMatch.replace('#', '/'); + var patternBlock = pattern.template.substring(pattern.template.indexOf(liMatch) + liMatch.length, pattern.template.indexOf(end)).trim(); + //build arrays that repeat the block, however large we need to + var repeatedBlockTemplate = []; + var repeatedBlockHtml = ''; + var i; // for loops + + for (i = 0; i < items.indexOf(loopNumberString); i++) { + repeatedBlockTemplate.push(patternBlock); + } + + //check for a local listitems.json file + var listData = JSON.parse(JSON.stringify(patternlab.listitems)); + listData = pattern_assembler.merge_data(listData, pattern.listitems); + + //iterate over each copied block, rendering its contents along with pattenlab.listitems[i] + for (i = 0; i < repeatedBlockTemplate.length; i++) { + var thisBlockTemplate = repeatedBlockTemplate[i]; + var thisBlockHTML = ""; + + //combine listItem data with pattern data with global data + var itemData = listData['' + items.indexOf(loopNumberString)]; //this is a property like "2" + var globalData = JSON.parse(JSON.stringify(patternlab.data)); + var localData = JSON.parse(JSON.stringify(pattern.jsonFileData)); + + var allData = pattern_assembler.merge_data(globalData, localData); + allData = pattern_assembler.merge_data(allData, itemData !== undefined ? itemData[i] : {}); //itemData could be undefined if the listblock contains no partial, just markup + allData.link = extend({}, patternlab.data.link); + + //check for partials within the repeated block + var foundPartials = pattern_assembler.find_pattern_partials({ 'template' : thisBlockTemplate }); + + if (foundPartials && foundPartials.length > 0) { + for (var j = 0; j < foundPartials.length; j++) { + //get the partial + var partialName = foundPartials[j].match(/([\w\-\.\/~]+)/g)[0]; + var partialPattern = pattern_assembler.get_pattern_by_key(partialName, patternlab); + + //create a copy of the partial so as to not pollute it after the get_pattern_by_key call. + var cleanPartialPattern = JSON.parse(JSON.stringify(partialPattern)); + + //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); + } + + //replace its reference within the block with the extended template + thisBlockTemplate = thisBlockTemplate.replace(foundPartials[j], cleanPartialPattern.extendedTemplate); + } + + //render with data + thisBlockHTML = pattern_assembler.renderPattern(thisBlockTemplate, allData, patternlab.partials); + } else { + //just render with mergedData + thisBlockHTML = pattern_assembler.renderPattern(thisBlockTemplate, allData, patternlab.partials); + } + + //add the rendered HTML to our string + repeatedBlockHtml = repeatedBlockHtml + thisBlockHTML; + } + + //replace the block with our generated HTML + var repeatingBlock = pattern.extendedTemplate.substring(pattern.extendedTemplate.indexOf(liMatch), pattern.extendedTemplate.indexOf(end) + end.length); + pattern.extendedTemplate = pattern.extendedTemplate.replace(repeatingBlock, repeatedBlockHtml); + + //update the extendedTemplate in the partials object in case this pattern is consumed later + patternlab.partials[pattern.key] = pattern.extendedTemplate; + + }); + } + } + + return { + process_list_item_partials: function (pattern, patternlab) { + processListItemPartials(pattern, patternlab); + } + }; + +}; + +module.exports = list_item_hunter; diff --git a/builder/media_hunter.js b/builder/media_hunter.js index 3ee48f4fe..7aa12e10c 100644 --- a/builder/media_hunter.js +++ b/builder/media_hunter.js @@ -8,46 +8,44 @@ * */ -(function () { - "use strict"; - - var diveSync = require('diveSync'), - path = require('path'), - fs = require('fs-extra'); - - var media_hunter = function(){ - - function findMediaQueries(dir, patternlab){ - patternlab.mediaQueries = []; - - diveSync(dir, function(err, file){ - if(path.extname(file) === '.css'){ - var contents = fs.readFileSync(file, 'utf8'); - var safeContents = contents.replace("\r", " ").replace("\n", " "); - var matches = safeContents.match(/\((min|max)-width:([ ]+)?(([0-9]{1,5})(\.[0-9]{1,20}|)(px|em))/g); - for(var i = 0; i < matches.length; i++){ - var breakpoint = matches[i].substring(matches[i].indexOf(':') + 1).trimLeft(); - if(patternlab.mediaQueries.indexOf(breakpoint) === -1){ - patternlab.mediaQueries.push(breakpoint); - } - } - } - }); - 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(dir, patternlab){ - findMediaQueries(dir, patternlab); - } - }; - - }; - - module.exports = media_hunter; - -}()); +"use strict"; + +var diveSync = require('diveSync'), + path = require('path'), + fs = require('fs-extra'); + +var media_hunter = function () { + + function findMediaQueries(dir, patternlab) { + patternlab.mediaQueries = []; + + diveSync(dir, function (err, file) { + if (path.extname(file) === '.css') { + var contents = fs.readFileSync(file, 'utf8'); + var safeContents = contents.replace("\r", " ").replace("\n", " "); + var matches = safeContents.match(/\((min|max)-width:([ ]+)?(([0-9]{1,5})(\.[0-9]{1,20}|)(px|em))/g); + for (var i = 0; i < matches.length; i++) { + var breakpoint = matches[i].substring(matches[i].indexOf(':') + 1).trimLeft(); + if (patternlab.mediaQueries.indexOf(breakpoint) === -1) { + patternlab.mediaQueries.push(breakpoint); + } + } + } + }); + 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 (dir, patternlab) { + findMediaQueries(dir, patternlab); + } + }; + +}; + +module.exports = media_hunter; + diff --git a/builder/object_factory.js b/builder/object_factory.js index 5526bdc18..c1e44ac38 100644 --- a/builder/object_factory.js +++ b/builder/object_factory.js @@ -8,65 +8,63 @@ * */ -(function () { - "use strict"; +"use strict"; - var oPattern = function(abspath, subdir, filename, data){ - this.fileName = filename.substring(0, filename.indexOf('.')); - this.abspath = abspath; - this.subdir = subdir; - this.name = subdir.replace(/[\/\\]/g, '-') + '-' + this.fileName; //this is the unique name with the subDir - this.jsonFileData = data || {}; - this.patternName = this.fileName.replace(/^\d*\-/, ''); - this.patternDisplayName = this.patternName.split('-').reduce(function(val, working){ - return val.charAt(0).toUpperCase() + val.slice(1) + ' ' + working.charAt(0).toUpperCase() + working.slice(1); - }, '').trim(); //this is the display name for the ui. strip numeric + hyphen prefixes - this.patternLink = this.name + '/' + this.name + '.html'; - this.patternGroup = this.name.substring(this.name.indexOf('-') + 1, this.name.indexOf('-', 4) + 1 - this.name.indexOf('-') + 1); - this.patternSubGroup = subdir.substring(subdir.indexOf('/') + 4); - this.flatPatternPath = subdir.replace(/[\/\\]/g, '-'); - this.key = this.patternGroup + '-' + this.patternName; - this.template = ''; - this.patternPartial = ''; - this.lineage = []; - this.lineageIndex = []; - this.lineageR = []; - this.lineageRIndex = []; - }; +var oPattern = function (abspath, subdir, filename, data) { + this.fileName = filename.substring(0, filename.indexOf('.')); + this.abspath = abspath; + this.subdir = subdir; + this.name = subdir.replace(/[\/\\]/g, '-') + '-' + this.fileName; //this is the unique name with the subDir + this.jsonFileData = data || {}; + this.patternName = this.fileName.replace(/^\d*\-/, ''); + this.patternDisplayName = this.patternName.split('-').reduce(function (val, working) { + return val.charAt(0).toUpperCase() + val.slice(1) + ' ' + working.charAt(0).toUpperCase() + working.slice(1); + }, '').trim(); //this is the display name for the ui. strip numeric + hyphen prefixes + this.patternLink = this.name + '/' + this.name + '.html'; + this.patternGroup = this.name.substring(this.name.indexOf('-') + 1, this.name.indexOf('-', 4) + 1 - this.name.indexOf('-') + 1); + this.patternSubGroup = subdir.substring(subdir.indexOf('/') + 4); + this.flatPatternPath = subdir.replace(/[\/\\]/g, '-'); + this.key = this.patternGroup + '-' + this.patternName; + this.template = ''; + this.patternPartial = ''; + this.lineage = []; + this.lineageIndex = []; + this.lineageR = []; + this.lineageRIndex = []; +}; - var oBucket = function(name){ - this.bucketNameLC = name; - this.bucketNameUC = name.split('-').reduce(function(val, working){ - return val.charAt(0).toUpperCase() + val.slice(1) + ' ' + working.charAt(0).toUpperCase() + working.slice(1); - }, '').trim(); - this.navItems = []; - this.navItemsIndex = []; - this.patternItems = []; - this.patternItemsIndex = []; - }; +var oBucket = function (name) { + this.bucketNameLC = name; + this.bucketNameUC = name.split('-').reduce(function (val, working) { + return val.charAt(0).toUpperCase() + val.slice(1) + ' ' + working.charAt(0).toUpperCase() + working.slice(1); + }, '').trim(); + this.navItems = []; + this.navItemsIndex = []; + this.patternItems = []; + this.patternItemsIndex = []; +}; - var oNavItem = function(name){ - this.sectionNameLC = name; - this.sectionNameUC = name.split('-').reduce(function(val, working){ - return val.charAt(0).toUpperCase() + val.slice(1) + ' ' + working.charAt(0).toUpperCase() + working.slice(1); - }, '').trim(); - this.navSubItems = []; - this.navSubItemsIndex = []; - }; +var oNavItem = function (name) { + this.sectionNameLC = name; + this.sectionNameUC = name.split('-').reduce(function (val, working) { + return val.charAt(0).toUpperCase() + val.slice(1) + ' ' + working.charAt(0).toUpperCase() + working.slice(1); + }, '').trim(); + this.navSubItems = []; + this.navSubItemsIndex = []; +}; - var oNavSubItem = function(name){ - this.patternPath = ''; - this.patternPartial = ''; - this.patternName = name.split(' ').reduce(function(val, working){ - return val.charAt(0).toUpperCase() + val.slice(1) + ' ' + working.charAt(0).toUpperCase() + working.slice(1); - }, '').trim(); - }; +var oNavSubItem = function (name) { + this.patternPath = ''; + this.patternPartial = ''; + this.patternName = name.split(' ').reduce(function (val, working) { + return val.charAt(0).toUpperCase() + val.slice(1) + ' ' + working.charAt(0).toUpperCase() + working.slice(1); + }, '').trim(); +}; - module.exports = { - oPattern: oPattern, - oBucket: oBucket, - oNavItem: oNavItem, - oNavSubItem: oNavSubItem - }; +module.exports = { + oPattern: oPattern, + oBucket: oBucket, + oNavItem: oNavItem, + oNavSubItem: oNavSubItem +}; -}()); diff --git a/builder/parameter_hunter.js b/builder/parameter_hunter.js index a3f574951..1c683780e 100644 --- a/builder/parameter_hunter.js +++ b/builder/parameter_hunter.js @@ -8,86 +8,87 @@ * */ -(function () { - "use strict"; - - var parameter_hunter = function(){ - - var extend = require('util')._extend, - pa = require('./pattern_assembler'), - mustache = require('mustache'), - smh = require('./style_modifier_hunter'), - style_modifier_hunter = new smh(), - pattern_assembler = new pa(); - - function findparameters(pattern, patternlab){ - - if(pattern.parameteredPartials && pattern.parameteredPartials.length > 0){ - //compile this partial immeadiately, essentially consuming it. - pattern.parameteredPartials.forEach(function(pMatch, index, matches){ - //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); - } - - //strip out the additional data, convert string to JSON. - var leftParen = pMatch.indexOf('('); - var rightParen = pMatch.indexOf(')'); - var paramString = '{' + pMatch.substring(leftParen + 1, rightParen) + '}'; - //if param keys are wrapped in single quotes, replace with double quotes. - var paramStringWellFormed = paramString.replace(/(')([^']+)(')(\s*\:)/g, '"$2"$4'); - //if params keys are not wrapped in any quotes, wrap in double quotes. - var paramStringWellFormed = paramStringWellFormed.replace(/([\{|,]\s*)([^\s"'\:]+)(\s*\:)/g, '$1"$2"$3'); - //if param values are wrapped in single quotes, replace with double quotes. - var paramStringWellFormed = paramStringWellFormed.replace(/(\:\s*)(')([^']+)(')/g, '$1"$3"'); - - var paramData = {}; - var globalData = {}; - var localData = {}; - - try { - paramData = JSON.parse(paramStringWellFormed); - globalData = JSON.parse(JSON.stringify(patternlab.data)); - localData = JSON.parse(JSON.stringify(pattern.jsonFileData || {})); - } catch(e){ - console.log(e); - } - - var allData = pattern_assembler.merge_data(globalData, localData); - allData = pattern_assembler.merge_data(allData, paramData); - - //if partial has style modifier data, replace the styleModifier value - if(pattern.stylePartials && pattern.stylePartials.length > 0){ - style_modifier_hunter.consume_style_modifier(partialPattern, pMatch, patternlab); - } - - //extend pattern data links into link for pattern link shortcuts to work. we do this locally and globally - allData.link = extend({}, patternlab.data.link); - - var renderedPartial = pattern_assembler.renderPattern(partialPattern.extendedTemplate, allData, patternlab.partials); - - //remove the parameter from the partial and replace it with the rendered partial + paramData - pattern.extendedTemplate = pattern.extendedTemplate.replace(pMatch, renderedPartial); - - //update the extendedTemplate in the partials object in case this pattern is consumed later - patternlab.partials[pattern.key] = pattern.extendedTemplate; - }); - } - } - - return { - find_parameters: function(pattern, patternlab){ - findparameters(pattern, patternlab); - } - }; - - }; - - module.exports = parameter_hunter; - -}()); +"use strict"; + +var parameter_hunter = function () { + + var extend = require('util')._extend, + pa = require('./pattern_assembler'), + smh = require('./style_modifier_hunter'), + style_modifier_hunter = new smh(), + pattern_assembler = new pa(); + + function findparameters(pattern, patternlab) { + if (pattern.parameteredPartials && pattern.parameteredPartials.length > 0) { + //compile this partial immeadiately, essentially consuming it. + + pattern.parameteredPartials.forEach(function (pMatch) { + //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); + } + + //strip out the additional data, convert string to JSON. + var leftParen = pMatch.indexOf('('); + var rightParen = pMatch.indexOf(')'); + var paramString = '{' + pMatch.substring(leftParen + 1, rightParen) + '}'; + + //if param keys are wrapped in single quotes, replace with double quotes. + var paramStringWellFormed = paramString.replace(/(')([^']+)(')(\s*\:)/g, '"$2"$4'); + + //if params keys are not wrapped in any quotes, wrap in double quotes. + paramStringWellFormed = paramStringWellFormed.replace(/([\{|,]\s*)([^\s"'\:]+)(\s*\:)/g, '$1"$2"$3'); + + //if param values are wrapped in single quotes, replace with double quotes. + paramStringWellFormed = paramStringWellFormed.replace(/(\:\s*)(')([^']+)(')/g, '$1"$3"'); + + var paramData = {}; + var globalData = {}; + var localData = {}; + + try { + paramData = JSON.parse(paramStringWellFormed); + globalData = JSON.parse(JSON.stringify(patternlab.data)); + localData = JSON.parse(JSON.stringify(pattern.jsonFileData || {})); + } catch (e) { + console.log(e); + } + + var allData = pattern_assembler.merge_data(globalData, localData); + allData = pattern_assembler.merge_data(allData, paramData); + + //if partial has style modifier data, replace the styleModifier value + if (pattern.stylePartials && pattern.stylePartials.length > 0) { + style_modifier_hunter.consume_style_modifier(partialPattern, pMatch, patternlab); + } + + //extend pattern data links into link for pattern link shortcuts to work. we do this locally and globally + allData.link = extend({}, patternlab.data.link); + + var renderedPartial = pattern_assembler.renderPattern(partialPattern.extendedTemplate, allData, patternlab.partials); + + //remove the parameter from the partial and replace it with the rendered partial + paramData + pattern.extendedTemplate = pattern.extendedTemplate.replace(pMatch, renderedPartial); + + //update the extendedTemplate in the partials object in case this pattern is consumed later + patternlab.partials[pattern.key] = pattern.extendedTemplate; + }); + } + } + + return { + find_parameters: function (pattern, patternlab) { + findparameters(pattern, patternlab); + } + }; + +}; + +module.exports = parameter_hunter; + + diff --git a/builder/pattern_assembler.js b/builder/pattern_assembler.js index d200f059d..3fc32d036 100644 --- a/builder/pattern_assembler.js +++ b/builder/pattern_assembler.js @@ -8,418 +8,419 @@ * */ -(function () { - "use strict"; - var pattern_assembler = function(){ +"use strict"; - function isObjectEmpty(obj) { - for(var prop in obj) { - if(obj.hasOwnProperty(prop)) - return false; - } +var pattern_assembler = function () { - return true; + function isObjectEmpty(obj) { + for (var prop in obj) { + if (obj.hasOwnProperty(prop)) { return false; } } - - // 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); - return matches; + return true; + } + + // 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); + 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); + return matches; + } + + //find and return any {{> template-name* }} within pattern + function findPartials(pattern) { + var matches = pattern.template.match(/{{>([ ])?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-_|]+)?(?:(| )\(.*)?([ ])?}}/g); + return matches; + } + + function findListItems(pattern) { + var matches = pattern.template.match(/({{#( )?)(list(I|i)tems.)(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty)( )?}}/g); + return matches; + } + + function setState(pattern, patternlab) { + if (patternlab.config.patternStates && patternlab.config.patternStates[pattern.patternName]) { + pattern.patternState = patternlab.config.patternStates[pattern.patternName]; + } else { + pattern.patternState = ""; } - - // 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); - return matches; + } + + function addPattern(pattern, patternlab) { + //add the link to the global object + patternlab.data.link[pattern.patternGroup + '-' + pattern.patternName] = '/patterns/' + pattern.patternLink; + + //only push to array if the array doesn't contain this pattern + var isNew = true, i; + for (i = 0; i < patternlab.patterns.length; i++) { + //so we need the identifier to be unique, which patterns[i].abspath is + if (pattern.abspath === patternlab.patterns[i].abspath) { + //if abspath already exists, overwrite that element + patternlab.patterns[i] = pattern; + patternlab.partials[pattern.key] = pattern.extendedTemplate || pattern.template; + isNew = false; + break; + } } - - //find and return any {{> template-name* }} within pattern - function findPartials(pattern){ - var matches = pattern.template.match(/{{>([ ])?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-_|]+)?(?:(| )\(.*)?([ ])?}}/g); - return matches; + + //if the pattern is new, just push to the array + if (isNew) { + patternlab.patterns.push(pattern); + patternlab.partials[pattern.key] = pattern.extendedTemplate || pattern.template; } + } - function findListItems(pattern){ - var matches = pattern.template.match(/({{#( )?)(list(I|i)tems.)(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty)( )?}}/g); - return matches; - } + function renderPattern(template, data, partials) { + var mustache = require('mustache'); - function setState(pattern, patternlab){ - if(patternlab.config.patternStates && patternlab.config.patternStates[pattern.patternName]){ - pattern.patternState = patternlab.config.patternStates[pattern.patternName]; - } else{ - pattern.patternState = ""; - } + if (partials) { + return mustache.render(template, data, partials); + } else { + return mustache.render(template, data); } + } - function addPattern(pattern, patternlab){ - //add the link to the global object - patternlab.data.link[pattern.patternGroup + '-' + pattern.patternName] = '/patterns/' + pattern.patternLink; - - //only push to array if the array doesn't contain this pattern - var isNew = true; - for(var i = 0; i < patternlab.patterns.length; i++){ - //so we need the identifier to be unique, which patterns[i].abspath is - if(pattern.abspath === patternlab.patterns[i].abspath){ - //if abspath already exists, overwrite that element - patternlab.patterns[i] = pattern; - patternlab.partials[pattern.key] = pattern.extendedTemplate || pattern.template; - isNew = false; - break; - } - } - //if the pattern is new, just push to the array - if(isNew){ - patternlab.patterns.push(pattern); - patternlab.partials[pattern.key] = pattern.extendedTemplate || pattern.template; - } - } + function processPatternIterative(file, patternlab) { + var fs = require('fs-extra'), + of = require('./object_factory'), + path = require('path'); - function renderPattern(template, data, partials) { + //extract some information + var subdir = path.dirname(path.relative(patternlab.config.paths.source.patterns, file)).replace('\\', '/'); + var filename = path.basename(file); + var ext = path.extname(filename); - var mustache = require('mustache'); - - if(partials) { - return mustache.render(template, data, partials); - } else{ - return mustache.render(template, data); - } + //ignore dotfiles, underscored files, and non-variant .json files + if (filename.charAt(0) === '.' || (ext === '.json' && filename.indexOf('~') === -1)) { + return; } - function processPatternIterative(file, patternlab){ - var fs = require('fs-extra'), - of = require('./object_factory'), - path = require('path'); + //make a new Pattern Object + var currentPattern = new of.oPattern(file, subdir, filename); - //extract some information - var subdir = path.dirname(path.relative(patternlab.config.paths.source.patterns, file)).replace('\\', '/'); - var filename = path.basename(file); - var ext = path.extname(filename); + //if file is named in the syntax for variants, no need to process further + //processPatternRecursive() will run find_pseudopatterns() and look at each pattern for a variant + if (ext === '.json' && filename.indexOf('~') > -1) { + return; + } - //ignore dotfiles, underscored files, and non-variant .json files - if(filename.charAt(0) === '.' || (ext === '.json' && filename.indexOf('~') === -1)){ - return; - } + //can ignore all non-mustache files at this point + if (ext !== '.mustache') { + return; + } - //make a new Pattern Object - var currentPattern = new of.oPattern(file, subdir, filename); + //see if this file has a state + setState(currentPattern, patternlab); - //if file is named in the syntax for variants, no need to process further - //processPatternRecursive() will run find_pseudopatterns() and look at each pattern for a variant - if(ext === '.json' && filename.indexOf('~') > -1){ - return; + //look for a json file for this template + try { + var jsonFilename = path.resolve(patternlab.config.paths.source.patterns, currentPattern.subdir, currentPattern.fileName + ".json"); + currentPattern.jsonFileData = fs.readJSONSync(jsonFilename); + if (patternlab.config.debug) { + console.log('found pattern-specific data.json for ' + currentPattern.key); } + } + catch (error) { + // do nothing + } - //can ignore all non-mustache files at this point - if(ext !== '.mustache'){ - return; + //look for a listitems.json file for this template + try { + var listJsonFileName = path.resolve(patternlab.config.paths.source.patterns, currentPattern.subdir, currentPattern.fileName + ".listitems.json"); + currentPattern.listitems = fs.readJSONSync(listJsonFileName); + buildListItems(currentPattern); + if (patternlab.config.debug) { + console.log('found pattern-specific listitems.json for ' + currentPattern.key); } + } + catch (err) { + // do nothing + } - //see if this file has a state - setState(currentPattern, patternlab); + //add the raw template to memory + currentPattern.template = fs.readFileSync(file, 'utf8'); - //look for a json file for this template - try { - var jsonFilename = path.resolve(patternlab.config.paths.source.patterns, currentPattern.subdir, currentPattern.fileName + ".json"); - currentPattern.jsonFileData = fs.readJSONSync(jsonFilename); - if(patternlab.config.debug){ - console.log('found pattern-specific data.json for ' + currentPattern.key); - } - } - catch(e) { - } + //find any stylemodifiers that may be in the current pattern + currentPattern.stylePartials = findPartialsWithStyleModifiers(currentPattern); - //look for a listitems.json file for this template - try { - var listJsonFileName = path.resolve(patternlab.config.paths.source.patterns, currentPattern.subdir,currentPattern.fileName + ".listitems.json"); - currentPattern.listitems = fs.readJSONSync(listJsonFileName); - buildListItems(currentPattern); - if(patternlab.config.debug){ - console.log('found pattern-specific listitems.json for ' + currentPattern.key); - } - } - catch(e) { - } + //find any pattern parameters that may be in the current pattern + currentPattern.parameteredPartials = findPartialsWithPatternParameters(currentPattern); - //add the raw template to memory - currentPattern.template = fs.readFileSync(file, 'utf8'); + //add currentPattern to patternlab.patterns array + addPattern(currentPattern, patternlab); + } - //find any stylemodifiers that may be in the current pattern - currentPattern.stylePartials = findPartialsWithStyleModifiers(currentPattern); + function processPatternRecursive(file, patternlab) { + var lh = require('./lineage_hunter'), + ph = require('./parameter_hunter'), + pph = require('./pseudopattern_hunter'), + lih = require('./list_item_hunter'), + smh = require('./style_modifier_hunter'); - //find any pattern parameters that may be in the current pattern - currentPattern.parameteredPartials = findPartialsWithPatternParameters(currentPattern); + var parameter_hunter = new ph(), + lineage_hunter = new lh(), + list_item_hunter = new lih(), + style_modifier_hunter = new smh(), + pseudopattern_hunter = new pph(); - //add currentPattern to patternlab.patterns array - addPattern(currentPattern, patternlab); - } + //find current pattern in patternlab object using var file as a key + var currentPattern, + i; - function processPatternRecursive(file, patternlab, additionalData){ - - var fs = require('fs-extra'), - mustache = require('mustache'), - lh = require('./lineage_hunter'), - ph = require('./parameter_hunter'), - pph = require('./pseudopattern_hunter'), - lih = require('./list_item_hunter'), - smh = require('./style_modifier_hunter'), - path = require('path'); - - var parameter_hunter = new ph(), - lineage_hunter = new lh(), - list_item_hunter = new lih(), - style_modifier_hunter = new smh(), - pseudopattern_hunter = new pph(); - - //find current pattern in patternlab object using var file as a key - var currentPattern, - i; - - for(i = 0; i < patternlab.patterns.length; i++){ - if(patternlab.patterns[i].abspath === file){ - currentPattern = patternlab.patterns[i]; - break; - } + for (i = 0; i < patternlab.patterns.length; i++) { + if (patternlab.patterns[i].abspath === file) { + currentPattern = patternlab.patterns[i]; + break; } + } - //return if processing an ignored file - if(typeof currentPattern === 'undefined'){ - return; - } + //return if processing an ignored file + if (typeof currentPattern === 'undefined') { + return; + } - currentPattern.extendedTemplate = currentPattern.template; + currentPattern.extendedTemplate = currentPattern.template; - //find how many partials there may be for the given pattern - var foundPatternPartials = findPartials(currentPattern); + //find how many partials there may be for the given pattern + var foundPatternPartials = findPartials(currentPattern); - if(foundPatternPartials !== null && foundPatternPartials.length > 0){ + if (foundPatternPartials !== null && foundPatternPartials.length > 0) { - if(patternlab.config.debug){ - console.log('found partials for ' + currentPattern.key); - } + if (patternlab.config.debug) { + console.log('found partials for ' + currentPattern.key); + } - //find any listItem blocks - list_item_hunter.process_list_item_partials(currentPattern, patternlab); + //find any listItem blocks + list_item_hunter.process_list_item_partials(currentPattern, patternlab); - //determine if the template contains any pattern parameters. if so they must be immediately consumed - parameter_hunter.find_parameters(currentPattern, patternlab); + //determine if the template contains any pattern parameters. if so they must be immediately consumed + parameter_hunter.find_parameters(currentPattern, patternlab); - //do something with the regular old partials - for(i = 0; i < foundPatternPartials.length; i++){ - var partialKey = foundPatternPartials[i].replace(/{{>([ ])?([\w\-\.\/~]+)(:[A-z0-9-_|]+)?(?:\:[A-Za-z0-9-_]+)?(?:(| )\(.*)?([ ])?}}/g, '$2'); + //do something with the regular old partials + for (i = 0; i < foundPatternPartials.length; i++) { + var partialKey = foundPatternPartials[i].replace(/{{>([ ])?([\w\-\.\/~]+)(:[A-z0-9-_|]+)?(?:\:[A-Za-z0-9-_]+)?(?:(| )\(.*)?([ ])?}}/g, '$2'); - var partialPath; + var partialPath; - //identify which pattern this partial corresponds to - for(var j = 0; j < patternlab.patterns.length; j++){ - if(patternlab.patterns[j].key === partialKey || - patternlab.patterns[j].abspath.indexOf(partialKey) > -1) - { - partialPath = patternlab.patterns[j].abspath; - } + //identify which pattern this partial corresponds tou + for (var j = 0; j < patternlab.patterns.length; j++) { + if (patternlab.patterns[j].key === partialKey || + patternlab.patterns[j].abspath.indexOf(partialKey) > -1) { + partialPath = patternlab.patterns[j].abspath; } + } - //recurse through nested partials to fill out this extended template. - processPatternRecursive(partialPath, patternlab); - - //complete assembly of extended template - var partialPattern = getpatternbykey(partialKey, patternlab); + //recurse through nested partials to fill out this extended template. + processPatternRecursive(partialPath, patternlab); - //if partial has style modifier data, replace the styleModifier value - if(currentPattern.stylePartials && currentPattern.stylePartials.length > 0){ - style_modifier_hunter.consume_style_modifier(partialPattern, foundPatternPartials[i], patternlab); - } + //complete assembly of extended template + var partialPattern = getpatternbykey(partialKey, patternlab); - currentPattern.extendedTemplate = currentPattern.extendedTemplate.replace(foundPatternPartials[i], partialPattern.extendedTemplate); - - //update the extendedTemplate in the partials object in case this pattern is consumed later - patternlab.partials[currentPattern.key] = currentPattern.extendedTemplate; + //if partial has style modifier data, replace the styleModifier value + if (currentPattern.stylePartials && currentPattern.stylePartials.length > 0) { + style_modifier_hunter.consume_style_modifier(partialPattern, foundPatternPartials[i], patternlab); } - } else{ - //find any listItem blocks that within the pattern, even if there are no partials - list_item_hunter.process_list_item_partials(currentPattern, patternlab); - } - - //find pattern lineage - lineage_hunter.find_lineage(currentPattern, patternlab); + currentPattern.extendedTemplate = currentPattern.extendedTemplate.replace(foundPatternPartials[i], partialPattern.extendedTemplate); - //add to patternlab object so we can look these up later. - addPattern(currentPattern, patternlab); + //update the extendedTemplate in the partials object in case this pattern is consumed later + patternlab.partials[currentPattern.key] = currentPattern.extendedTemplate; + } - //look for a pseudo pattern by checking if there is a file containing same name, with ~ in it, ending in .json - pseudopattern_hunter.find_pseudopatterns(currentPattern, patternlab); + } else { + //find any listItem blocks that within the pattern, even if there are no partials + list_item_hunter.process_list_item_partials(currentPattern, patternlab); } - function getpatternbykey(key, patternlab){ + //find pattern lineage + lineage_hunter.find_lineage(currentPattern, patternlab); - //look for exact key matches - for(var i = 0; i < patternlab.patterns.length; i++){ - if(patternlab.patterns[i].key === key){ - return patternlab.patterns[i]; - } - } + //add to patternlab object so we can look these up later. + addPattern(currentPattern, patternlab); - //else look by verbose syntax - for(var i = 0; i < patternlab.patterns.length; i++){ - switch(key){ - case patternlab.patterns[i].subdir + '/' + patternlab.patterns[i].fileName: - case patternlab.patterns[i].subdir + '/' + patternlab.patterns[i].fileName + '.mustache': - return patternlab.patterns[i]; - } + //look for a pseudo pattern by checking if there is a file containing same name, with ~ in it, ending in .json + pseudopattern_hunter.find_pseudopatterns(currentPattern, patternlab); + } + + function getpatternbykey(key, patternlab) { + var i; // for the for loops + + //look for exact key matches + for (i = 0; i < patternlab.patterns.length; i++) { + if (patternlab.patterns[i].key === key) { + return patternlab.patterns[i]; } + } - //return the fuzzy match if all else fails - for(var i = 0; i < patternlab.patterns.length; i++){ - var keyParts = key.split('-'), - keyType = keyParts[0], - keyName = keyParts.slice(1).join('-'); - if(patternlab.patterns[i].key.split('-')[0] === keyType && patternlab.patterns[i].key.indexOf(keyName) > -1){ + //else look by verbose syntax + for (i = 0; i < patternlab.patterns.length; i++) { + switch (key) { + case patternlab.patterns[i].subdir + '/' + patternlab.patterns[i].fileName: + case patternlab.patterns[i].subdir + '/' + patternlab.patterns[i].fileName + '.mustache': return patternlab.patterns[i]; - } } - throw 'Could not find pattern with key ' + key; } - function mergeData(obj1, obj2){ - if(typeof obj2 === 'undefined'){ - obj2 = {}; + //return the fuzzy match if all else fails + for (i = 0; i < patternlab.patterns.length; i++) { + var keyParts = key.split('-'), + keyType = keyParts[0], + keyName = keyParts.slice(1).join('-'); + + if (patternlab.patterns[i].key.split('-')[0] === keyType && patternlab.patterns[i].key.indexOf(keyName) > -1) { + return patternlab.patterns[i]; } - for(var p in obj1){ - try { - // Only recurse if obj1[p] is an object. - if(obj1[p].constructor === Object){ - // Requires 2 objects as params; create obj2[p] if undefined. - if(typeof obj2[p] === 'undefined'){ - obj2[p] = {}; - } - obj2[p] = mergeData(obj1[p], obj2[p]); + } + throw 'Could not find pattern with key ' + key; + } + + function mergeData(obj1, obj2) { + /*eslint-disable guard-for-in, no-param-reassign*/ + if (typeof obj2 === 'undefined') { + obj2 = {}; + } + for (var p in obj1) { + try { + // Only recurse if obj1[p] is an object. + if (obj1[p].constructor === Object) { + // Requires 2 objects as params; create obj2[p] if undefined. + if (typeof obj2[p] === 'undefined') { + obj2[p] = {}; + } + obj2[p] = mergeData(obj1[p], obj2[p]); + // Pop when recursion meets a non-object. If obj1[p] is a non-object, // only copy to undefined obj2[p]. This way, obj2 maintains priority. - } else if(typeof obj2[p] === 'undefined'){ - obj2[p] = obj1[p]; - } - } catch(e) { - // Property in destination object not set; create it and set its value. - if(typeof obj2[p] === 'undefined'){ - obj2[p] = obj1[p]; - } + } else if (typeof obj2[p] === 'undefined') { + obj2[p] = obj1[p]; + } + } catch (e) { + // Property in destination object not set; create it and set its value. + if (typeof obj2[p] === 'undefined') { + obj2[p] = obj1[p]; } } - return obj2; } - - function buildListItems(container){ - //combine all list items into one structure - var list = []; - for (var item in container.listitems) { - if( container.listitems.hasOwnProperty(item)) { - list.push(container.listitems[item]); - } + return obj2; + } + + function buildListItems(container) { + //combine all list items into one structure + var list = []; + for (var item in container.listitems) { + if (container.listitems.hasOwnProperty(item)) { + list.push(container.listitems[item]); } - container.listItemArray = shuffle(list); - - for(var i = 1; i <= container.listItemArray.length; i++){ - var tempItems = []; - if( i === 1){ - tempItems.push(container.listItemArray[0]); + } + container.listItemArray = shuffle(list); + + for (var i = 1; i <= container.listItemArray.length; i++) { + var tempItems = []; + if (i === 1) { + tempItems.push(container.listItemArray[0]); + container.listitems['' + i ] = tempItems; + } else { + for (var c = 1; c <= i; c++) { + tempItems.push(container.listItemArray[c - 1]); container.listitems['' + i ] = tempItems; - } else{ - for(var c = 1; c <= i; c++){ - tempItems.push(container.listItemArray[c - 1]); - container.listitems['' + i ] = tempItems; - } } } } - - //http://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array-in-javascript - function shuffle(o){ - for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); - return o; - } - - function parseDataLinksHelper (patternlab, obj, key) { - var linkRE, dataObjAsString, linkMatches, expandedLink; - - linkRE = /link\.[A-z0-9-_]+/g - dataObjAsString = JSON.stringify(obj); - linkMatches = dataObjAsString.match(linkRE) - - if(linkMatches) { - for (var i = 0; i < linkMatches.length; i++) { - expandedLink = patternlab.data.link[linkMatches[i].split('.')[1]]; - if (expandedLink) { - if(patternlab.config.debug){ - console.log('expanded data link from ' + linkMatches[i] + ' to ' + expandedLink + ' inside ' + key); - } - dataObjAsString = dataObjAsString.replace(linkMatches[i], expandedLink); + } + + //http://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array-in-javascript + function shuffle(o) { + /*eslint-disable curly*/ + for (var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); + return o; + } + + function parseDataLinksHelper(patternlab, obj, key) { + var linkRE, dataObjAsString, linkMatches, expandedLink; + + linkRE = /link\.[A-z0-9-_]+/g; + dataObjAsString = JSON.stringify(obj); + linkMatches = dataObjAsString.match(linkRE); + + if (linkMatches) { + for (var i = 0; i < linkMatches.length; i++) { + expandedLink = patternlab.data.link[linkMatches[i].split('.')[1]]; + if (expandedLink) { + if (patternlab.config.debug) { + console.log('expanded data link from ' + linkMatches[i] + ' to ' + expandedLink + ' inside ' + key); } + dataObjAsString = dataObjAsString.replace(linkMatches[i], expandedLink); } } - return JSON.parse(dataObjAsString) } - //look for pattern links included in data files. - //these will be in the form of link.* WITHOUT {{}}, which would still be there from direct pattern inclusion - function parseDataLinks(patternlab) { - //look for link.* such as link.pages-blog as a value - - patternlab.data = parseDataLinksHelper(patternlab, patternlab.data, 'data.json') - - //loop through all patterns - for (var i = 0; i < patternlab.patterns.length; i++) { - patternlab.patterns[i].jsonFileData = parseDataLinksHelper(patternlab, patternlab.patterns[i].jsonFileData, patternlab.patterns[i].key) - } + return JSON.parse(dataObjAsString); + } + + //look for pattern links included in data files. + //these will be in the form of link.* WITHOUT {{}}, which would still be there from direct pattern inclusion + function parseDataLinks(patternlab) { + //look for link.* such as link.pages-blog as a value + + patternlab.data = parseDataLinksHelper(patternlab, patternlab.data, 'data.json'); + + //loop through all patterns + for (var i = 0; i < patternlab.patterns.length; i++) { + patternlab.patterns[i].jsonFileData = parseDataLinksHelper(patternlab, patternlab.patterns[i].jsonFileData, patternlab.patterns[i].key); } + } + + return { + find_pattern_partials: function (pattern) { + return findPartials(pattern); + }, + find_pattern_partials_with_style_modifiers: function (pattern) { + return findPartialsWithStyleModifiers(pattern); + }, + find_pattern_partials_with_parameters: function (pattern) { + return findPartialsWithPatternParameters(pattern); + }, + find_list_items: function (pattern) { + return findListItems(pattern); + }, + setPatternState: function (pattern, patternlab) { + setState(pattern, patternlab); + }, + addPattern: function (pattern, patternlab) { + addPattern(pattern, patternlab); + }, + renderPattern: function (template, data, partials) { + return renderPattern(template, data, partials); + }, + process_pattern_iterative: function (file, patternlab) { + processPatternIterative(file, patternlab); + }, + process_pattern_recursive: function (file, patternlab, additionalData) { + processPatternRecursive(file, patternlab, additionalData); + }, + get_pattern_by_key: function (key, patternlab) { + return getpatternbykey(key, patternlab); + }, + merge_data: function (existingData, newData) { + return mergeData(existingData, newData); + }, + combine_listItems: function (patternlab) { + buildListItems(patternlab); + }, + is_object_empty: function (obj) { + return isObjectEmpty(obj); + }, + parse_data_links: function (patternlab) { + parseDataLinks(patternlab); + } + }; - return { - find_pattern_partials: function(pattern){ - return findPartials(pattern); - }, - find_pattern_partials_with_style_modifiers: function(pattern){ - return findPartialsWithStyleModifiers(pattern); - }, - find_pattern_partials_with_parameters: function(pattern){ - return findPartialsWithPatternParameters(pattern); - }, - find_list_items: function(pattern){ - return findListItems(pattern) - }, - setPatternState: function(pattern, patternlab){ - setState(pattern, patternlab); - }, - addPattern: function(pattern, patternlab){ - addPattern(pattern, patternlab); - }, - renderPattern: function(template, data, partials){ - return renderPattern(template, data, partials); - }, - process_pattern_iterative: function(file, patternlab){ - processPatternIterative(file, patternlab); - }, - process_pattern_recursive: function(file, patternlab, additionalData){ - processPatternRecursive(file, patternlab, additionalData); - }, - get_pattern_by_key: function(key, patternlab){ - return getpatternbykey(key, patternlab); - }, - merge_data: function(existingData, newData){ - return mergeData(existingData, newData); - }, - combine_listItems: function(patternlab){ - buildListItems(patternlab); - }, - is_object_empty: function(obj){ - return isObjectEmpty(obj); - }, - parse_data_links: function(patternlab){ - parseDataLinks(patternlab); - } - }; +}; - }; +module.exports = pattern_assembler; - module.exports = pattern_assembler; -}()); From d2ff6ea4c1fc1d93c9db5a220695bce8c7957a7c Mon Sep 17 00:00:00 2001 From: New Geoff Date: Sat, 27 Feb 2016 15:40:40 -0600 Subject: [PATCH 11/37] most of the rest of the builder JS, reformatted --- builder/pattern_exporter.js | 51 ++++---- builder/patternlab.js | 197 +++++++++++++++---------------- builder/patternlab_grunt.js | 50 ++++---- builder/patternlab_gulp.js | 13 +- builder/pseudopattern_hunter.js | 139 +++++++++++----------- builder/style_modifier_hunter.js | 54 ++++----- 6 files changed, 240 insertions(+), 264 deletions(-) diff --git a/builder/pattern_exporter.js b/builder/pattern_exporter.js index 3d04658d3..a7a70c05b 100644 --- a/builder/pattern_exporter.js +++ b/builder/pattern_exporter.js @@ -8,38 +8,33 @@ * */ -(function () { - "use strict"; - - var fs = require('fs-extra'), - path = require('path'); - - var pattern_exporter = function(){ - - function exportPatterns(patternlab){ - - //read the config export options - var exportKeys = patternlab.config.patternExportKeys; - - //find the chosen patterns to export - for (var i = 0; i < exportKeys.length; i++){ - for (var j = 0; j < patternlab.patterns.length; j++){ - if(exportKeys[i] === patternlab.patterns[j].key){ - //write matches to the desired location - fs.outputFileSync(patternlab.config.patternExportDirectory + patternlab.patterns[j].key + '.html', patternlab.patterns[j].patternPartial); - } +"use strict"; + +var fs = require('fs-extra'); + +var pattern_exporter = function () { + + function exportPatterns(patternlab) { + //read the config export options + var exportKeys = patternlab.config.patternExportKeys; + + //find the chosen patterns to export + for (var i = 0; i < exportKeys.length; i++) { + for (var j = 0; j < patternlab.patterns.length; j++) { + if (exportKeys[i] === patternlab.patterns[j].key) { + //write matches to the desired location + fs.outputFileSync(patternlab.config.patternExportDirectory + patternlab.patterns[j].key + '.html', patternlab.patterns[j].patternPartial); } } } + } - return { - export_patterns: function(patternlab){ - exportPatterns(patternlab); - } - }; - + return { + export_patterns: function (patternlab) { + exportPatterns(patternlab); + } }; - module.exports = pattern_exporter; +}; -}()); +module.exports = pattern_exporter; diff --git a/builder/patternlab.js b/builder/patternlab.js index aae791f23..d1745567b 100644 --- a/builder/patternlab.js +++ b/builder/patternlab.js @@ -12,17 +12,14 @@ var patternlab_engine = function (config) { 'use strict'; var path = require('path'), - fs = require('fs-extra'), - extend = require('util')._extend, - diveSync = require('diveSync'), - mustache = require('mustache'), - glob = require('glob'), - of = require('./object_factory'), - pa = require('./pattern_assembler'), - mh = require('./media_hunter'), - pe = require('./pattern_exporter'), - he = require('html-entities').AllHtmlEntities, - patternlab = {}; + fs = require('fs-extra'), + diveSync = require('diveSync'), + of = require('./object_factory'), + pa = require('./pattern_assembler'), + mh = require('./media_hunter'), + pe = require('./pattern_exporter'), + he = require('html-entities').AllHtmlEntities, + patternlab = {}; patternlab.package = fs.readJSONSync('./package.json'); patternlab.config = config || fs.readJSONSync(path.resolve(__dirname, '../config.json')); @@ -34,7 +31,7 @@ var patternlab_engine = function (config) { console.log(patternlab.package.version); } - function help(){ + function help() { console.log('Patternlab Node Help'); console.log('==============================='); console.log('Command Line Arguments'); @@ -51,13 +48,13 @@ var patternlab_engine = function (config) { function printDebug() { //debug file can be written by setting flag on config.json - if(patternlab.config.debug){ + if (patternlab.config.debug) { console.log('writing patternlab debug file to ./patternlab.json'); fs.outputFileSync('./patternlab.json', JSON.stringify(patternlab, null, 3)); } } - function buildPatterns(deletePatternDir){ + function buildPatterns(deletePatternDir) { patternlab.data = fs.readJSONSync(path.resolve(paths.source.data, 'data.json')); patternlab.listitems = fs.readJSONSync(path.resolve(paths.source.data, 'listitems.json')); patternlab.header = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'pattern-header-footer/header.html'), 'utf8'); @@ -67,47 +64,52 @@ var patternlab_engine = function (config) { patternlab.data.link = {}; var pattern_assembler = new pa(), - entity_encoder = new he(), - pattern_exporter = new pe(), - patterns_dir = paths.source.patterns; + entity_encoder = new he(), + pattern_exporter = new pe(), + patterns_dir = paths.source.patterns; pattern_assembler.combine_listItems(patternlab); //diveSync once to perform iterative populating of patternlab object - diveSync(patterns_dir, { - filter: function(path, dir) { - if(dir){ - var remainingPath = path.replace(patterns_dir, ''); - var isValidPath = remainingPath.indexOf('/_') === -1; - return isValidPath; - } + diveSync( + patterns_dir, + { + filter: function (filePath, dir) { + if (dir) { + var remainingPath = filePath.replace(patterns_dir, ''); + var isValidPath = remainingPath.indexOf('/_') === -1; + return isValidPath; + } return true; } }, - function(err, file){ + function (err, file) { //log any errors - if(err){ + if (err) { console.log(err); return; } pattern_assembler.process_pattern_iterative(path.resolve(file), patternlab); - }); + } + ); //diveSync again to recursively include partials, filling out the //extendedTemplate property of the patternlab.patterns elements - diveSync(patterns_dir, { - filter: function(path, dir) { - if(dir){ - var remainingPath = path.replace(patterns_dir, ''); - var isValidPath = remainingPath.indexOf('/_') === -1; - return isValidPath; - } + diveSync( + patterns_dir, + { + filter: function (filePath, dir) { + if (dir) { + var remainingPath = filePath.replace(patterns_dir, ''); + var isValidPath = remainingPath.indexOf('/_') === -1; + return isValidPath; + } return true; } }, - function(err, file){ + function (err, file) { //log any errors - if(err){ + if (err) { console.log(err); return; } @@ -120,15 +122,15 @@ var patternlab_engine = function (config) { pattern_assembler.parse_data_links(patternlab); //delete the contents of config.patterns.public before writing - if(deletePatternDir){ + if (deletePatternDir) { fs.emptyDirSync(paths.public.patterns); } //render all patterns last, so lineageR works - patternlab.patterns.forEach(function(pattern, index, patterns){ + patternlab.patterns.forEach(function (pattern) { //render the pattern, but first consolidate any data we may have - var allData = JSON.parse(JSON.stringify(patternlab.data)); + var allData = JSON.parse(JSON.stringify(patternlab.data)); allData = pattern_assembler.merge_data(allData, pattern.jsonFileData); //render the extendedTemplate with all data @@ -149,27 +151,25 @@ var patternlab_engine = function (config) { //export patterns if necessary pattern_exporter.export_patterns(patternlab); - } - function buildFrontEnd(){ + function buildFrontEnd() { var pattern_assembler = new pa(), media_hunter = new mh(), styleGuideExcludes = patternlab.config.styleGuideExcludes, - styleguidePatterns = []; + styleguidePatterns = [], + i; // for loops + patternlab.buckets = []; patternlab.bucketIndex = []; patternlab.patternPaths = {}; patternlab.viewAllPaths = {}; //sort all patterns explicitly. - patternlab.patterns = patternlab.patterns.sort(function(a,b){ - if (a.name > b.name) { - return 1; - } - if (a.name < b.name) { - return -1; - } + patternlab.patterns = patternlab.patterns.sort(function (a, b) { + if (a.name > b.name) { return 1; } + if (a.name < b.name) { return -1; } + // a must be equal to b return 0; }); @@ -179,41 +179,41 @@ var patternlab_engine = function (config) { // check if patterns are excluded, if not add them to styleguidePatterns if (styleGuideExcludes && styleGuideExcludes.length) { - for (i = 0; i < patternlab.patterns.length; i++) { + for (i = 0; i < patternlab.patterns.length; i++) { - // skip underscore-prefixed files - if(isPatternExcluded(patternlab.patterns[i])){ - if(patternlab.config.debug){ - console.log('Omitting ' + patternlab.patterns[i].key + " from styleguide pattern exclusion."); - } - continue; + // skip underscore-prefixed files + if (isPatternExcluded(patternlab.patterns[i])) { + if (patternlab.config.debug) { + console.log('Omitting ' + patternlab.patterns[i].key + " from styleguide pattern exclusion."); } + continue; + } - var key = patternlab.patterns[i].key; - var typeKey = key.substring(0, key.indexOf('-')); - var isExcluded = (styleGuideExcludes.indexOf(typeKey) > -1); - if (!isExcluded) { - styleguidePatterns.push(patternlab.patterns[i]); - } + var key = patternlab.patterns[i].key; + var typeKey = key.substring(0, key.indexOf('-')); + var isExcluded = (styleGuideExcludes.indexOf(typeKey) > -1); + if (!isExcluded) { + styleguidePatterns.push(patternlab.patterns[i]); } + } } else { styleguidePatterns = patternlab.patterns; } //build the styleguide var styleguideTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'styleguide.mustache'), 'utf8'), - styleguideHtml = pattern_assembler.renderPattern(styleguideTemplate, {partials: styleguidePatterns}); + styleguideHtml = pattern_assembler.renderPattern(styleguideTemplate, {partials: styleguidePatterns}); + fs.outputFileSync(path.resolve(paths.public.styleguide, 'html/styleguide.html'), styleguideHtml); //build the viewall pages var prevSubdir = '', - prevGroup = '', - i; + prevGroup = ''; for (i = 0; i < patternlab.patterns.length; i++) { // skip underscore-prefixed files - if(isPatternExcluded(patternlab.patterns[i])){ - if(patternlab.config.debug){ + if (isPatternExcluded(patternlab.patterns[i])) { + if (patternlab.config.debug) { console.log('Omitting ' + patternlab.patterns[i].key + " from view all rendering."); } continue; @@ -223,7 +223,7 @@ var patternlab_engine = function (config) { //create the view all for the section // check if the current section is different from the previous one - if (pattern.patternGroup != prevGroup){ + if (pattern.patternGroup !== prevGroup) { prevGroup = pattern.patternGroup; var viewAllPatterns = [], @@ -233,8 +233,8 @@ var patternlab_engine = function (config) { for (j = 0; j < patternlab.patterns.length; j++) { if (patternlab.patterns[j].patternGroup === pattern.patternGroup) { //again, skip any sibling patterns to the current one that may have underscores - if(isPatternExcluded(patternlab.patterns[j])){ - if(patternlab.config.debug){ + if (isPatternExcluded(patternlab.patterns[j])) { + if (patternlab.config.debug) { console.log('Omitting ' + patternlab.patterns[j].key + " from view all sibling rendering."); } continue; @@ -249,25 +249,24 @@ var patternlab_engine = function (config) { fs.outputFileSync(paths.public.patterns + pattern.subdir.slice(0, pattern.subdir.indexOf(pattern.patternGroup) + pattern.patternGroup.length) + '/index.html', viewAllHtml); } - //create the view all for the subsection + // create the view all for the subsection // check if the current sub section is different from the previous one if (pattern.subdir !== prevSubdir) { prevSubdir = pattern.subdir; var viewAllPatterns = [], - patternPartial = "viewall-" + pattern.patternGroup + "-" + pattern.patternSubGroup, - j; + patternPartial = "viewall-" + pattern.patternGroup + "-" + pattern.patternSubGroup, + j; for (j = 0; j < patternlab.patterns.length; j++) { if (patternlab.patterns[j].subdir === pattern.subdir) { //again, skip any sibling patterns to the current one that may have underscores - if(isPatternExcluded(patternlab.patterns[j])){ - if(patternlab.config.debug){ + if (isPatternExcluded(patternlab.patterns[j])) { + if (patternlab.config.debug) { console.log('Omitting ' + patternlab.patterns[j].key + " from view all sibling rendering."); } continue; } - viewAllPatterns.push(patternlab.patterns[j]); } } @@ -283,17 +282,17 @@ var patternlab_engine = function (config) { //loop through all patterns.to build the navigation //todo: refactor this someday - for(var i = 0; i < patternlab.patterns.length; i++){ + for (i = 0; i < patternlab.patterns.length; i++) { var pattern = patternlab.patterns[i]; var bucketName = pattern.name.replace(/\\/g, '-').split('-')[1]; //check if the bucket already exists var bucketIndex = patternlab.bucketIndex.indexOf(bucketName); - if(bucketIndex === -1){ + if (bucketIndex === -1) { // skip underscore-prefixed files. don't create a bucket on account of an underscored pattern - if(isPatternExcluded(pattern)){ + if (isPatternExcluded(pattern)) { continue; } @@ -313,7 +312,7 @@ var patternlab_engine = function (config) { //test whether the pattern struture is flat or not - usually due to a template or page var flatPatternItem = false; - if(navItemName === bucketName){ + if (navItemName === bucketName) { flatPatternItem = true; } @@ -331,15 +330,13 @@ var patternlab_engine = function (config) { } //if it is flat - we should not add the pattern to patternPaths - if(flatPatternItem){ - + if (flatPatternItem) { bucket.patternItems.push(navSubItem); //add to patternPaths addToPatternPaths(bucketName, pattern); - } else{ - + } else { bucket.navItems.push(navItem); bucket.navItemsIndex.push(navItemName); navItem.navSubItems.push(navSubItem); @@ -355,7 +352,6 @@ var patternlab_engine = function (config) { bucket.patternItems.push(navViewAllItem); patternlab.viewAllPaths[bucketName]['viewall'] = pattern.subdir.slice(0, pattern.subdir.indexOf(pattern.patternGroup) + pattern.patternGroup.length); - } //add the bucket. @@ -364,7 +360,7 @@ var patternlab_engine = function (config) { //done - } else{ + } else { //find the bucket var bucket = patternlab.buckets[bucketIndex]; @@ -383,21 +379,21 @@ var patternlab_engine = function (config) { navSubItem.patternPartial = bucketName + "-" + pattern.patternName; //add the hyphenated name //add the patternState if it exists - if(pattern.patternState){ + if (pattern.patternState) { navSubItem.patternState = pattern.patternState; } //test whether the pattern struture is flat or not - usually due to a template or page var flatPatternItem = false; - if(navItemName === bucketName){ + if (navItemName === bucketName) { flatPatternItem = true; } //if it is flat - we should not add the pattern to patternPaths - if(flatPatternItem){ + if (flatPatternItem) { // skip underscore-prefixed files - if(isPatternExcluded(pattern)){ + if (isPatternExcluded(pattern)) { continue; } @@ -407,14 +403,13 @@ var patternlab_engine = function (config) { //add to patternPaths addToPatternPaths(bucketName, pattern); - } else{ + } else { // only do this if pattern is included - if(!isPatternExcluded(pattern)){ + if (!isPatternExcluded(pattern)) { //check to see if navItem exists var navItemIndex = bucket.navItemsIndex.indexOf(navItemName); - if(navItemIndex === -1){ - + if (navItemIndex === -1) { var navItem = new of.oNavItem(navItemName); //add the navItem and navSubItem @@ -423,7 +418,7 @@ var patternlab_engine = function (config) { bucket.navItems.push(navItem); bucket.navItemsIndex.push(navItemName); - } else{ + } else { //add the navSubItem var navItem = bucket.navItems[navItemIndex]; navItem.navSubItems.push(navSubItem); @@ -482,30 +477,30 @@ var patternlab_engine = function (config) { fs.outputFileSync(path.resolve(paths.public.root, 'index.html'), patternlabSiteHtml); } - function addToPatternPaths(bucketName, pattern){ + function addToPatternPaths(bucketName, pattern) { //this is messy, could use a refactor. patternlab.patternPaths[bucketName][pattern.patternName] = pattern.subdir.replace(/\\/g, '/') + "/" + pattern.fileName; } //todo: refactor this as a method on the pattern object itself once we merge dev with pattern-engines branch - function isPatternExcluded(pattern){ + function isPatternExcluded(pattern) { // returns whether or not the first character of the pattern filename is an underscore, or excluded return pattern.fileName.charAt(0) === '_'; } return { - version: function(){ + version: function () { return getVersion(); }, - build: function(deletePatternDir){ + build: function (deletePatternDir) { buildPatterns(deletePatternDir); buildFrontEnd(); printDebug(); }, - help: function(){ + help: function () { help(); }, - build_patterns_only: function(deletePatternDir){ + build_patterns_only: function (deletePatternDir) { buildPatterns(deletePatternDir); printDebug(); } diff --git a/builder/patternlab_grunt.js b/builder/patternlab_grunt.js index 93b50b1e7..69085c291 100644 --- a/builder/patternlab_grunt.js +++ b/builder/patternlab_grunt.js @@ -10,31 +10,29 @@ var patternlab_engine = require('./patternlab.js'); -module.exports = function(grunt) { - grunt.registerTask('patternlab', 'create design systems with atomic design', function(arg) { - - var patternlab = patternlab_engine(); - - if(arguments.length === 0){ - patternlab.build(true); - } - - if(arg && arg === 'v'){ - patternlab.version(); - } - - if(arg && arg === "only_patterns"){ - patternlab.build_patterns_only(true); - } - - if(arg && arg === "help"){ - patternlab.help(); - } - - if(arg && (arg !== "v" && arg !=="only_patterns" && arg !=="help")){ - patternlab.help(); - } - - }); +module.exports = function (grunt) { + grunt.registerTask('patternlab', 'create design systems with atomic design', function (arg) { + var patternlab = patternlab_engine(); + + if (arguments.length === 0) { + patternlab.build(true); + } + + if (arg && arg === 'v') { + patternlab.version(); + } + + if (arg && arg === "only_patterns") { + patternlab.build_patterns_only(true); + } + + if (arg && arg === "help") { + patternlab.help(); + } + + if (arg && (arg !== "v" && arg !== "only_patterns" && arg !== "help")) { + patternlab.help(); + } + }); }; diff --git a/builder/patternlab_gulp.js b/builder/patternlab_gulp.js index e036b1bb5..291940b30 100644 --- a/builder/patternlab_gulp.js +++ b/builder/patternlab_gulp.js @@ -10,27 +10,26 @@ var patternlab_engine = require('./patternlab.js'); -module.exports = function(gulp) { - - gulp.task('patternlab', ['clean'], function(cb){ +module.exports = function (gulp) { + + gulp.task('patternlab', ['clean'], function (cb) { var patternlab = patternlab_engine(); patternlab.build(false); cb(); }); - gulp.task('patternlab:version', function(){ + gulp.task('patternlab:version', function () { var patternlab = patternlab_engine(); patternlab.version(); }); - gulp.task('patternlab:only_patterns', ['clean'], function(){ + gulp.task('patternlab:only_patterns', ['clean'], function () { var patternlab = patternlab_engine(); patternlab.build_patterns_only(false); }); - gulp.task('patternlab:help', function(){ + gulp.task('patternlab:help', function () { var patternlab = patternlab_engine(); patternlab.help(); }); - }; diff --git a/builder/pseudopattern_hunter.js b/builder/pseudopattern_hunter.js index 77773040e..0f0907ea1 100644 --- a/builder/pseudopattern_hunter.js +++ b/builder/pseudopattern_hunter.js @@ -8,76 +8,69 @@ * */ -(function () { - "use strict"; - - var pseudopattern_hunter = function(){ - - function findpseudopatterns(currentPattern, patternlab){ - - var glob = require('glob'), - fs = require('fs-extra'), - pa = require('./pattern_assembler'), - lh = require('./lineage_hunter'), - of = require('./object_factory'), - path = require('path'); - - var pattern_assembler = new pa(); - var lineage_hunter = new lh(); - var paths = patternlab.config.paths; - - //look for a pseudo pattern by checking if there is a file containing same name, with ~ in it, ending in .json - var needle = currentPattern.subdir + '/' + currentPattern.fileName + '~*.json'; - var pseudoPatterns = glob.sync(needle, { - cwd: paths.source.patterns, - debug: false, - nodir: true, - }); - - if(pseudoPatterns.length > 0){ - - for(var i = 0; i < pseudoPatterns.length; i++){ - - if(patternlab.config.debug){ - console.log('found pseudoPattern variant of ' + currentPattern.key); - } - - //we want to do everything we normally would here, except instead read the pseudoPattern data - var variantFileData = fs.readJSONSync(path.resolve(paths.source.patterns, pseudoPatterns[i])); - - //extend any existing data with variant data - variantFileData = pattern_assembler.merge_data(currentPattern.jsonFileData, variantFileData); - - var variantName = pseudoPatterns[i].substring(pseudoPatterns[i].indexOf('~') + 1).split('.')[0]; - var variantFilePath = path.resolve(paths.source.patterns, currentPattern.subdir, currentPattern.fileName + '~' + variantName + '.json'); - var variantFileName = currentPattern.fileName + '-' + variantName + '.'; - var patternVariant = new of.oPattern(variantFilePath, currentPattern.subdir, variantFileName, variantFileData); - - //see if this file has a state - pattern_assembler.setPatternState(patternVariant, patternlab); - - //use the same template as the non-variant - patternVariant.template = currentPattern.template; - patternVariant.extendedTemplate = currentPattern.extendedTemplate; - - //find pattern lineage - lineage_hunter.find_lineage(patternVariant, patternlab); - - //add to patternlab object so we can look these up later. - pattern_assembler.addPattern(patternVariant, patternlab); - } - } - - } - - return { - find_pseudopatterns: function(pattern, patternlab){ - findpseudopatterns(pattern, patternlab); - } - }; - - }; - - module.exports = pseudopattern_hunter; - -}()); +"use strict"; + +var pseudopattern_hunter = function () { + + function findpseudopatterns(currentPattern, patternlab) { + var glob = require('glob'), + fs = require('fs-extra'), + pa = require('./pattern_assembler'), + lh = require('./lineage_hunter'), + of = require('./object_factory'), + path = require('path'); + + var pattern_assembler = new pa(); + var lineage_hunter = new lh(); + var paths = patternlab.config.paths; + + //look for a pseudo pattern by checking if there is a file containing same name, with ~ in it, ending in .json + var needle = currentPattern.subdir + '/' + currentPattern.fileName + '~*.json'; + var pseudoPatterns = glob.sync(needle, { + cwd: paths.source.patterns, + debug: false, + nodir: true + }); + + if (pseudoPatterns.length > 0) { + for (var i = 0; i < pseudoPatterns.length; i++) { + if (patternlab.config.debug) { + console.log('found pseudoPattern variant of ' + currentPattern.key); + } + + //we want to do everything we normally would here, except instead read the pseudoPattern data + var variantFileData = fs.readJSONSync(path.resolve(paths.source.patterns, pseudoPatterns[i])); + + //extend any existing data with variant data + variantFileData = pattern_assembler.merge_data(currentPattern.jsonFileData, variantFileData); + + var variantName = pseudoPatterns[i].substring(pseudoPatterns[i].indexOf('~') + 1).split('.')[0]; + var variantFilePath = path.resolve(paths.source.patterns, currentPattern.subdir, currentPattern.fileName + '~' + variantName + '.json'); + var variantFileName = currentPattern.fileName + '-' + variantName + '.'; + var patternVariant = new of.oPattern(variantFilePath, currentPattern.subdir, variantFileName, variantFileData); + + //see if this file has a state + pattern_assembler.setPatternState(patternVariant, patternlab); + + //use the same template as the non-variant + patternVariant.template = currentPattern.template; + patternVariant.extendedTemplate = currentPattern.extendedTemplate; + + //find pattern lineage + lineage_hunter.find_lineage(patternVariant, patternlab); + + //add to patternlab object so we can look these up later. + pattern_assembler.addPattern(patternVariant, patternlab); + } + } + } + + return { + find_pseudopatterns: function (pattern, patternlab) { + findpseudopatterns(pattern, patternlab); + } + }; + +}; + +module.exports = pseudopattern_hunter; diff --git a/builder/style_modifier_hunter.js b/builder/style_modifier_hunter.js index a19fbf081..b9b616b86 100644 --- a/builder/style_modifier_hunter.js +++ b/builder/style_modifier_hunter.js @@ -8,40 +8,36 @@ * */ -(function () { - "use strict"; + "use strict"; - var style_modifier_hunter = function(){ + var style_modifier_hunter = function () { - function consumestylemodifier(pattern, partial, patternlab){ + 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; + + if (styleModifier) { + //replace the special character pipe | used to separate multiple classes with a space + styleModifier = styleModifier.replace(/\|/g, ' '); - //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; - if(styleModifier){ + if (patternlab.config.debug) { + console.log('found partial styleModifier within pattern ' + pattern.key); + } - //replace the special character pipe | used to separate multiple classes with a space - styleModifier = styleModifier.replace(/\|/g, ' '); + //replace the stylemodifier placeholder with the class name + pattern.extendedTemplate = pattern.extendedTemplate.replace(/{{[ ]?styleModifier[ ]?}}/i, styleModifier); - if(patternlab.config.debug){ - console.log('found partial styleModifier within pattern ' + pattern.key); - } + //update the extendedTemplate in the partials object in case this pattern is consumed later + patternlab.partials[pattern.key] = pattern.extendedTemplate; + } + } - //replace the stylemodifier placeholder with the class name - pattern.extendedTemplate = pattern.extendedTemplate.replace(/{{[ ]?styleModifier[ ]?}}/i, styleModifier); + return { + consume_style_modifier: function (pattern, partial, patternlab) { + consumestylemodifier(pattern, partial, patternlab); + } + }; - //update the extendedTemplate in the partials object in case this pattern is consumed later - patternlab.partials[pattern.key] = pattern.extendedTemplate; - } - } + }; - return { - consume_style_modifier: function(pattern, partial, patternlab){ - consumestylemodifier(pattern, partial, patternlab); - } - }; - - }; - - module.exports = style_modifier_hunter; - -}()); + module.exports = style_modifier_hunter; From 7863fefa7f6e22046f126adfc1198417f7d41835 Mon Sep 17 00:00:00 2001 From: New Geoff Date: Sat, 27 Feb 2016 15:50:24 -0600 Subject: [PATCH 12/37] config and task runner cleanup --- Gruntfile.js | 300 +++++++++++++++++++++++++-------------------------- config.json | 54 +++++----- gulpfile.js | 37 +++---- 3 files changed, 196 insertions(+), 195 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 06c6cf6d2..51452919f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,161 +1,161 @@ -module.exports = function(grunt) { +module.exports = function (grunt) { - var path = require('path'); + var path = require('path'); - // Project configuration. - grunt.initConfig({ - pkg: grunt.file.readJSON('package.json'), - concat: { - options: { - stripBanners: true, - banner: '/* \n * <%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy") %> \n * \n * <%= pkg.author %>, and the web community.\n * Licensed under the <%= pkg.license %> license. \n * \n * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. \n *\n */\n\n', - }, - patternlab: { - src: './builder/patternlab.js', - dest: './builder/patternlab.js' - }, - object_factory: { - src: './builder/object_factory.js', - dest: './builder/object_factory.js' - }, - lineage: { - src: './builder/lineage_hunter.js', - dest: './builder/lineage_hunter.js' - }, - media_hunter: { - src: './builder/media_hunter.js', - dest: './builder/media_hunter.js' - }, - patternlab_grunt: { - src: './builder/patternlab_grunt.js', - dest: './builder/patternlab_grunt.js' - }, - patternlab_gulp: { - src: './builder/patternlab_gulp.js', - dest: './builder/patternlab_gulp.js' - }, - parameter_hunter: { - src: './builder/parameter_hunter.js', - dest: './builder/parameter_hunter.js' - }, - pattern_exporter: { - src: './builder/pattern_exporter.js', - dest: './builder/pattern_exporter.js' - }, - pattern_assembler: { - src: './builder/pattern_assembler.js', - dest: './builder/pattern_assembler.js' - }, - pseudopattern_hunter: { - src: './builder/pseudopattern_hunter.js', - dest: './builder/pseudopattern_hunter.js' - }, - list_item_hunter: { - src: './builder/list_item_hunter.js', - dest: './builder/list_item_hunter.js' - }, - style_modifier_hunter: { - src: './builder/style_modifier_hunter.js', - dest: './builder/style_modifier_hunter.js' - } - }, - copy: { - main: { - files: [ - { expand: true, cwd: path.resolve(paths().source.js), src: '*.js', dest: path.resolve(paths().public.js) }, - { expand: true, cwd: path.resolve(paths().source.css), src: '*.css', dest: path.resolve(paths().public.css) }, - { expand: true, cwd: path.resolve(paths().source.images), src: ['**/*.png', '**/*.jpg', '**/*.gif', '**/*.jpeg'], dest: path.resolve(paths().public.images) }, - { expand: true, cwd: path.resolve(paths().source.fonts), src: '*', dest: path.resolve(paths().public.fonts) }, - { expand: true, cwd: path.resolve(paths().source.data), src: 'annotations.js', dest: path.resolve(paths().public.data) } - ] - }, - styleguide: { - files: [ - { expand: true, cwd: path.resolve(paths().source.styleguide), src: ['*.*', '**/*.*'], dest: path.resolve(paths().public.styleguide) } - ] - } - }, - watch: { - all: { - files: [ - path.resolve(paths().source.css + '**/*.css'), - path.resolve(paths().source.styleguide + 'css/*.css'), - path.resolve(paths().source.patterns + '**/*.mustache'), - path.resolve(paths().source.patterns + '**/*.json'), - path.resolve(paths().source.fonts + '/*'), - path.resolve(paths().source.images + '/*'), - path.resolve(paths().source.data + '*.json') - ], - tasks: ['default', 'bsReload:css'] - } - }, - nodeunit: { - all: ['test/*_tests.js'] - }, - browserSync: { - dev: { - options: { - server: path.resolve(paths().public.root), - watchTask: true, - watchOptions: { - ignoreInitial: true, - ignored: '*.html' - }, - snippetOptions: { - // Ignore all HTML files within the templates folder - blacklist: ['/index.html', '/'] - }, - plugins: [ - { - module: 'bs-html-injector', - options: { - files: [path.resolve(paths().public.root + '/index.html'), path.resolve(paths().public.styleguide + '/styleguide.html')] - } - } - ], - notify: { - styles: [ - 'display: none', - 'padding: 15px', - 'font-family: sans-serif', - 'position: fixed', - 'font-size: 1em', - 'z-index: 9999', - 'bottom: 0px', - 'right: 0px', - 'border-top-left-radius: 5px', - 'background-color: #1B2032', - 'opacity: 0.4', - 'margin: 0', - 'color: white', - 'text-align: center' - ] - } - } - } - }, - bsReload: { - css: path.resolve(paths().public.root + '**/*.css') - } - }); + function paths() { + return require('./config.json').paths; + } - function paths () { - return require('./config.json').paths; - } + // Project configuration. + grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + concat: { + options: { + stripBanners: true, + banner: '/* \n * <%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy") %> \n * \n * <%= pkg.author %>, and the web community.\n * Licensed under the <%= pkg.license %> license. \n * \n * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. \n *\n */\n\n' + }, + patternlab: { + src: './builder/patternlab.js', + dest: './builder/patternlab.js' + }, + object_factory: { + src: './builder/object_factory.js', + dest: './builder/object_factory.js' + }, + lineage: { + src: './builder/lineage_hunter.js', + dest: './builder/lineage_hunter.js' + }, + media_hunter: { + src: './builder/media_hunter.js', + dest: './builder/media_hunter.js' + }, + patternlab_grunt: { + src: './builder/patternlab_grunt.js', + dest: './builder/patternlab_grunt.js' + }, + patternlab_gulp: { + src: './builder/patternlab_gulp.js', + dest: './builder/patternlab_gulp.js' + }, + parameter_hunter: { + src: './builder/parameter_hunter.js', + dest: './builder/parameter_hunter.js' + }, + pattern_exporter: { + src: './builder/pattern_exporter.js', + dest: './builder/pattern_exporter.js' + }, + pattern_assembler: { + src: './builder/pattern_assembler.js', + dest: './builder/pattern_assembler.js' + }, + pseudopattern_hunter: { + src: './builder/pseudopattern_hunter.js', + dest: './builder/pseudopattern_hunter.js' + }, + list_item_hunter: { + src: './builder/list_item_hunter.js', + dest: './builder/list_item_hunter.js' + }, + style_modifier_hunter: { + src: './builder/style_modifier_hunter.js', + dest: './builder/style_modifier_hunter.js' + } + }, + copy: { + main: { + files: [ + { expand: true, cwd: path.resolve(paths().source.js), src: '*.js', dest: path.resolve(paths().public.js) }, + { expand: true, cwd: path.resolve(paths().source.css), src: '*.css', dest: path.resolve(paths().public.css) }, + { expand: true, cwd: path.resolve(paths().source.images), src: ['**/*.png', '**/*.jpg', '**/*.gif', '**/*.jpeg'], dest: path.resolve(paths().public.images) }, + { expand: true, cwd: path.resolve(paths().source.fonts), src: '*', dest: path.resolve(paths().public.fonts) }, + { expand: true, cwd: path.resolve(paths().source.data), src: 'annotations.js', dest: path.resolve(paths().public.data) } + ] + }, + styleguide: { + files: [ + { expand: true, cwd: path.resolve(paths().source.styleguide), src: ['*.*', '**/*.*'], dest: path.resolve(paths().public.styleguide) } + ] + } + }, + watch: { + all: { + files: [ + path.resolve(paths().source.css + '**/*.css'), + path.resolve(paths().source.styleguide + 'css/*.css'), + path.resolve(paths().source.patterns + '**/*.mustache'), + path.resolve(paths().source.patterns + '**/*.json'), + path.resolve(paths().source.fonts + '/*'), + path.resolve(paths().source.images + '/*'), + path.resolve(paths().source.data + '*.json') + ], + tasks: ['default', 'bsReload:css'] + } + }, + nodeunit: { + all: ['test/*_tests.js'] + }, + browserSync: { + dev: { + options: { + server: path.resolve(paths().public.root), + watchTask: true, + watchOptions: { + ignoreInitial: true, + ignored: '*.html' + }, + snippetOptions: { + // Ignore all HTML files within the templates folder + blacklist: ['/index.html', '/'] + }, + plugins: [ + { + module: 'bs-html-injector', + options: { + files: [path.resolve(paths().public.root + '/index.html'), path.resolve(paths().public.styleguide + '/styleguide.html')] + } + } + ], + notify: { + styles: [ + 'display: none', + 'padding: 15px', + 'font-family: sans-serif', + 'position: fixed', + 'font-size: 1em', + 'z-index: 9999', + 'bottom: 0px', + 'right: 0px', + 'border-top-left-radius: 5px', + 'background-color: #1B2032', + 'opacity: 0.4', + 'margin: 0', + 'color: white', + 'text-align: center' + ] + } + } + } + }, + bsReload: { + css: path.resolve(paths().public.root + '**/*.css') + } + }); - // load all grunt tasks - require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); + // load all grunt tasks + require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); - //load the patternlab task - grunt.task.loadTasks('./builder/'); + //load the patternlab task + grunt.task.loadTasks('./builder/'); - grunt.registerTask('default', ['patternlab', 'copy:main', 'copy:styleguide']); + grunt.registerTask('default', ['patternlab', 'copy:main', 'copy:styleguide']); - //travis CI task - grunt.registerTask('travis', ['nodeunit', 'patternlab']); + //travis CI task + grunt.registerTask('travis', ['nodeunit', 'patternlab']); - grunt.registerTask('serve', ['patternlab', 'copy:main', 'copy:styleguide', 'browserSync', 'watch:all']); + grunt.registerTask('serve', ['patternlab', 'copy:main', 'copy:styleguide', 'browserSync', 'watch:all']); - grunt.registerTask('build', ['nodeunit', 'concat']); + grunt.registerTask('build', ['nodeunit', 'concat']); }; diff --git a/config.json b/config.json index 0ca6ef1f0..187e8955d 100644 --- a/config.json +++ b/config.json @@ -22,36 +22,36 @@ "css" : "./public/css" } }, - "styleGuideExcludes": [ - "templates", - "pages" - ], - "ignored-extensions" : ["scss", "DS_Store", "less"], - "ignored-directories" : ["scss"], - "debug": false, - "ishControlsVisible": { - "s": true, - "m": true, - "l": true, - "full": true, - "random": true, - "disco": true, - "hay": true, - "mqs": true, - "find": true, - "views-all": true, - "views-annotations": true, - "views-code": true, - "views-new": true, - "tools-all": true, - "tools-sync": true, - "tools-shortcuts": true, - "tools-docs": true - }, + "styleGuideExcludes": [ + "templates", + "pages" + ], + "ignored-extensions" : ["scss", "DS_Store", "less"], + "ignored-directories" : ["scss"], + "debug": false, + "ishControlsVisible": { + "s": true, + "m": true, + "l": true, + "full": true, + "random": true, + "disco": true, + "hay": true, + "mqs": true, + "find": true, + "views-all": true, + "views-annotations": true, + "views-code": true, + "views-new": true, + "tools-all": true, + "tools-sync": true, + "tools-shortcuts": true, + "tools-docs": true + }, "patternStates": { "homepage-emergency" : "inprogress" }, "patternExportKeys": [], "patternExportDirectory": "./pattern_exports/", "baseurl" : "" - } +} diff --git a/gulpfile.js b/gulpfile.js index fb15e1439..8e93df2b0 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,4 +1,5 @@ -// Special thanks to oscar-g (https://github.com/oscar-g) for starting this at https://github.com/oscar-g/patternlab-node/tree/dev-gulp +// Special thanks to oscar-g (https://github.com/oscar-g) for starting this at +// https://github.com/oscar-g/patternlab-node/tree/dev-gulp var pkg = require('./package.json'), gulp = require('gulp'), @@ -20,21 +21,21 @@ var banner = [ '/** ', ' * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.', ' * ', ' **/'].join(eol); -function paths () { +function paths() { return require('./config.json').paths; } //load patternlab-node tasks -gulp.loadTasks(__dirname+'/builder/patternlab_gulp.js'); +gulp.loadTasks(__dirname + '/builder/patternlab_gulp.js'); //clean patterns dir -gulp.task('clean', function(cb){ +gulp.task('clean', function (cb) { del.sync([path.resolve(paths().public.patterns, '*')], {force: true}); cb(); }); //build the banner -gulp.task('banner', function(){ +gulp.task('banner', function () { return gulp.src([ './builder/patternlab.js', './builder/object_factory.js', @@ -50,7 +51,7 @@ gulp.task('banner', function(){ './builder/style_modifier_hunter.js' ]) .pipe(strip_banner()) - .pipe(header( banner, { + .pipe(header(banner, { pkg : pkg, today : new Date().getFullYear() } )) @@ -61,40 +62,40 @@ gulp.task('banner', function(){ // COPY TASKS // JS copy -gulp.task('cp:js', function(){ - return gulp.src('**/*.js', {cwd: path.resolve(paths().source.js)} ) +gulp.task('cp:js', function () { + return gulp.src('**/*.js', {cwd: path.resolve(paths().source.js)}) .pipe(gulp.dest(path.resolve(paths().public.js))); }); // Images copy -gulp.task('cp:img', function(){ +gulp.task('cp:img', function () { return gulp.src( - [ '**/*.gif', '**/*.png', '**/*.jpg', '**/*.jpeg' ], - {cwd: path.resolve(paths().source.images)} ) + ['**/*.gif', '**/*.png', '**/*.jpg', '**/*.jpeg'], + {cwd: path.resolve(paths().source.images)}) .pipe(gulp.dest(path.resolve(paths().public.images))); }); // Fonts copy -gulp.task('cp:font', function(){ +gulp.task('cp:font', function () { return gulp.src('*', {cwd: path.resolve(paths().source.fonts)}) .pipe(gulp.dest(path.resolve(paths().public.fonts))); }); // Data copy -gulp.task('cp:data', function(){ +gulp.task('cp:data', function () { return gulp.src('annotations.js', {cwd: path.resolve(paths().source.data)}) .pipe(gulp.dest(path.resolve(paths().public.data))); }); // CSS Copy -gulp.task('cp:css', function(){ +gulp.task('cp:css', function () { return gulp.src(path.resolve(paths().source.css, 'style.css')) .pipe(gulp.dest(path.resolve(paths().public.css))) .pipe(browserSync.stream()); }); // Styleguide Copy -gulp.task('cp:styleguide', function(){ +gulp.task('cp:styleguide', function () { return gulp.src( ['**/*'], {cwd: path.resolve(paths().source.styleguide)}) @@ -151,13 +152,13 @@ gulp.task('connect', ['lab'], function () { }); //unit test -gulp.task('nodeunit', function(){ +gulp.task('nodeunit', function () { return gulp.src('./test/**/*_tests.js') .pipe(nodeunit()); }); -gulp.task('lab-pipe', ['lab'], function(cb){ +gulp.task('lab-pipe', ['lab'], function (cb) { cb(); browserSync.reload(); }); @@ -166,7 +167,7 @@ gulp.task('default', ['lab']); gulp.task('assets', ['cp:js', 'cp:img', 'cp:font', 'cp:data', 'cp:css', 'cp:styleguide' ]); gulp.task('prelab', ['clean', 'assets']); -gulp.task('lab', ['prelab', 'patternlab'], function(cb){cb();}); +gulp.task('lab', ['prelab', 'patternlab'], function (cb) { cb(); }); gulp.task('patterns', ['patternlab:only_patterns']); gulp.task('serve', ['lab', 'connect']); gulp.task('travis', ['lab', 'nodeunit']); From 2f57f65a819214c3311adad42b88316cea098ab1 Mon Sep 17 00:00:00 2001 From: e2tha-e Date: Sat, 27 Feb 2016 17:16:58 -0500 Subject: [PATCH 13/37] more robust parameter to json conversion --- builder/parameter_hunter.js | 94 +++++++++++++++++++++++++++++++--- test/parameter_hunter_tests.js | 24 ++++----- 2 files changed, 100 insertions(+), 18 deletions(-) diff --git a/builder/parameter_hunter.js b/builder/parameter_hunter.js index a3f574951..da08eee92 100644 --- a/builder/parameter_hunter.js +++ b/builder/parameter_hunter.js @@ -20,6 +20,93 @@ style_modifier_hunter = new smh(), pattern_assembler = new pa(); + function paramToJson(paramString) { + var paramStringWellFormed = ''; + var paramStringTmp; + var colonPos; + var delimitPos; + var quotePos; + + do { + //if param key is wrapped in single quotes, replace with double quotes. + paramString = paramString.replace(/(^\s*[\{|\,]\s*)'([^']+)'(\s*\:)/, '$1"$2"$3'); + //if params key is not wrapped in any quotes, wrap in double quotes. + paramString = paramString.replace(/(^\s*[\{|\,]\s*)([^\s"'\:]+)(\s*\:)/, '$1"$2"$3'); + //move param key to paramStringWellFormed var. + colonPos = paramString.indexOf(':'); + //except to prevent infinite loops. + if (colonPos === -1) { + colonPos = paramString.length - 1; + } + else { + colonPos += 1; + } + paramStringWellFormed += paramString.substring(0, colonPos); + paramString = paramString.substring(colonPos, paramString.length).trim(); + + //if param value is wrapped in single quotes, replace with double quotes. + if (paramString[0] === '\'') { + quotePos = paramString.search(/[^\\]'/); + //except for unclosed quotes to prevent infinite loops. + if (quotePos === -1) { + quotePos = paramString.length - 1; + } + else { + quotePos += 2; + } + //prepare param value for move to paramStringWellFormed var. + paramStringTmp = paramString.substring(0, quotePos); + //unescape any escaped single quotes. + paramStringTmp = paramStringTmp.replace(/\\'/g, '\''); + //escape any double quotes. + paramStringTmp = paramStringTmp.replace(/"/g, '\\"'); + //replace the delimiting single quotes with double quotes. + paramStringTmp = paramStringTmp.replace(/^'/, '"'); + paramStringTmp = paramStringTmp.replace(/'$/, '"'); + //move param key to paramStringWellFormed var. + paramStringWellFormed += paramStringTmp; + paramString = paramString.substring(quotePos, paramString.length).trim(); + } + //if param value is wrapped in double quotes, just move to paramStringWellFormed var. + else if (paramString[0] === '"') { + quotePos = paramString.search(/[^\\]"/); + //except for unclosed quotes to prevent infinite loops. + if (quotePos === -1) { + quotePos = paramString.length - 1; + } + else { + quotePos += 2; + } + //move param key to paramStringWellFormed var. + paramStringWellFormed += paramString.substring(0, quotePos); + paramString = paramString.substring(quotePos, paramString.length).trim(); + } + //if param value is not wrapped in quotes, move everthing up to the delimiting comma to paramStringWellFormed var. + else { + delimitPos = paramString.indexOf(','); + //except to prevent infinite loops. + if (delimitPos === -1) { + delimitPos = paramString.length - 1; + } + else { + delimitPos += 1; + } + paramStringWellFormed += paramString.substring(0, delimitPos); + paramString = paramString.substring(delimitPos, paramString.length).trim(); + } + + //break at the end. + if (paramString.length === 1) { + paramStringWellFormed += paramString.trim(); + paramString = ''; + break; + } + + } while(paramString); + + return paramStringWellFormed; + } + function findparameters(pattern, patternlab){ if(pattern.parameteredPartials && pattern.parameteredPartials.length > 0){ @@ -39,12 +126,7 @@ var leftParen = pMatch.indexOf('('); var rightParen = pMatch.indexOf(')'); var paramString = '{' + pMatch.substring(leftParen + 1, rightParen) + '}'; - //if param keys are wrapped in single quotes, replace with double quotes. - var paramStringWellFormed = paramString.replace(/(')([^']+)(')(\s*\:)/g, '"$2"$4'); - //if params keys are not wrapped in any quotes, wrap in double quotes. - var paramStringWellFormed = paramStringWellFormed.replace(/([\{|,]\s*)([^\s"'\:]+)(\s*\:)/g, '$1"$2"$3'); - //if param values are wrapped in single quotes, replace with double quotes. - var paramStringWellFormed = paramStringWellFormed.replace(/(\:\s*)(')([^']+)(')/g, '$1"$3"'); + var paramStringWellFormed = paramToJson(paramString); var paramData = {}; var globalData = {}; diff --git a/test/parameter_hunter_tests.js b/test/parameter_hunter_tests.js index 069986553..3672a4a79 100644 --- a/test/parameter_hunter_tests.js +++ b/test/parameter_hunter_tests.js @@ -158,32 +158,32 @@ test.done(); }, - 'parameter hunter parses parameters with single-quoted keys and single-quoted values' : function(test){ + 'parameter hunter parses parameters with single-quoted keys and single-quoted values wrapping internal escaped single-quotes' : function(test){ var currentPattern = currentPatternClosure(); var patternlab = patternlabClosure(); var parameter_hunter = new ph(); - currentPattern.template = "{{> molecules-single-comment('description': 'true') }}"; + currentPattern.template = "{{> molecules-single-comment('description': 'true not,\\'true\\'') }}"; currentPattern.extendedTemplate = currentPattern.template; currentPattern.parameteredPartials[0] = currentPattern.template; parameter_hunter.find_parameters(currentPattern, patternlab); - test.equals(currentPattern.extendedTemplate, '

true

'); + test.equals(currentPattern.extendedTemplate, '

true not,'true'

'); test.done(); }, - 'parameter hunter parses parameters with single-quoted keys and double-quoted values' : function(test){ + 'parameter hunter parses parameters with single-quoted keys and double-quoted values wrapping internal single-quotes' : function(test){ var currentPattern = currentPatternClosure(); var patternlab = patternlabClosure(); var parameter_hunter = new ph(); - currentPattern.template = "{{> molecules-single-comment('description': \"true\") }}"; + currentPattern.template = "{{> molecules-single-comment('description': \"true not:'true'\") }}"; currentPattern.extendedTemplate = currentPattern.template; currentPattern.parameteredPartials[0] = currentPattern.template; parameter_hunter.find_parameters(currentPattern, patternlab); - test.equals(currentPattern.extendedTemplate, '

true

'); + test.equals(currentPattern.extendedTemplate, '

true not:'true'

'); test.done(); }, @@ -203,32 +203,32 @@ test.done(); }, - 'parameter hunter parses parameters with double-quoted keys and single-quoted values' : function(test){ + 'parameter hunter parses parameters with double-quoted keys and single-quoted values wrapping internal double-quotes' : function(test){ var currentPattern = currentPatternClosure(); var patternlab = patternlabClosure(); var parameter_hunter = new ph(); - currentPattern.template = "{{> molecules-single-comment(\"description\": 'true') }}"; + currentPattern.template = "{{> molecules-single-comment(\"description\": 'true not{\"true\"') }}"; currentPattern.extendedTemplate = currentPattern.template; currentPattern.parameteredPartials[0] = currentPattern.template; parameter_hunter.find_parameters(currentPattern, patternlab); - test.equals(currentPattern.extendedTemplate, '

true

'); + test.equals(currentPattern.extendedTemplate, '

true not{"true"

'); test.done(); }, - 'parameter hunter parses parameters with double-quoted keys and double-quoted values' : function(test){ + 'parameter hunter parses parameters with double-quoted keys and double-quoted values wrapping internal escaped double-quotes' : function(test){ var currentPattern = currentPatternClosure(); var patternlab = patternlabClosure(); var parameter_hunter = new ph(); - currentPattern.template = "{{> molecules-single-comment(\"description\": \"true\") }}"; + currentPattern.template = "{{> molecules-single-comment(\"description\": \"true not}\\\"true\\\"\") }}"; currentPattern.extendedTemplate = currentPattern.template; currentPattern.parameteredPartials[0] = currentPattern.template; parameter_hunter.find_parameters(currentPattern, patternlab); - test.equals(currentPattern.extendedTemplate, '

true

'); + test.equals(currentPattern.extendedTemplate, '

true not}"true"

'); test.done(); } From bf270833e7627c35dc52aef2f0f22fc8389cac2f Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Sat, 27 Feb 2016 23:00:29 -0600 Subject: [PATCH 14/37] added eslint to devDependencies. removed dead function --- builder/list_item_hunter.js | 1 - builder/pattern_assembler.js | 32 +++++++++++--------------------- package.gulp.json | 1 + package.json | 3 ++- 4 files changed, 14 insertions(+), 23 deletions(-) diff --git a/builder/list_item_hunter.js b/builder/list_item_hunter.js index 62e8f5538..1474769dd 100644 --- a/builder/list_item_hunter.js +++ b/builder/list_item_hunter.js @@ -8,7 +8,6 @@ * */ - "use strict"; var list_item_hunter = function () { diff --git a/builder/pattern_assembler.js b/builder/pattern_assembler.js index 3fc32d036..72ddf7364 100644 --- a/builder/pattern_assembler.js +++ b/builder/pattern_assembler.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v1.1.3 - 2016 - * +/* + * patternlab-node - v1.1.3 - 2016 + * * 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. * */ @@ -13,13 +13,6 @@ var pattern_assembler = function () { - function isObjectEmpty(obj) { - for (var prop in obj) { - if (obj.hasOwnProperty(prop)) { return false; } - } - return true; - } - // 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); @@ -67,7 +60,7 @@ var pattern_assembler = function () { break; } } - + //if the pattern is new, just push to the array if (isNew) { patternlab.patterns.push(pattern); @@ -249,7 +242,7 @@ var pattern_assembler = function () { function getpatternbykey(key, patternlab) { var i; // for the for loops - + //look for exact key matches for (i = 0; i < patternlab.patterns.length; i++) { if (patternlab.patterns[i].key === key) { @@ -271,7 +264,7 @@ var pattern_assembler = function () { var keyParts = key.split('-'), keyType = keyParts[0], keyName = keyParts.slice(1).join('-'); - + if (patternlab.patterns[i].key.split('-')[0] === keyType && patternlab.patterns[i].key.indexOf(keyName) > -1) { return patternlab.patterns[i]; } @@ -293,7 +286,7 @@ var pattern_assembler = function () { obj2[p] = {}; } obj2[p] = mergeData(obj1[p], obj2[p]); - + // Pop when recursion meets a non-object. If obj1[p] is a non-object, // only copy to undefined obj2[p]. This way, obj2 maintains priority. } else if (typeof obj2[p] === 'undefined') { @@ -360,7 +353,7 @@ var pattern_assembler = function () { } return JSON.parse(dataObjAsString); } - + //look for pattern links included in data files. //these will be in the form of link.* WITHOUT {{}}, which would still be there from direct pattern inclusion function parseDataLinks(patternlab) { @@ -411,9 +404,6 @@ var pattern_assembler = function () { combine_listItems: function (patternlab) { buildListItems(patternlab); }, - is_object_empty: function (obj) { - return isObjectEmpty(obj); - }, parse_data_links: function (patternlab) { parseDataLinks(patternlab); } diff --git a/package.gulp.json b/package.gulp.json index 7bdc7cb2c..3f2663854 100644 --- a/package.gulp.json +++ b/package.gulp.json @@ -13,6 +13,7 @@ }, "devDependencies": { "browser-sync": "^2.11.1", + "eslint": "^2.2.0", "gulp": "^3.9.0", "gulp-connect": "^2.3.1", "gulp-copy": "0.0.2", diff --git a/package.json b/package.json index 4cfbf8671..5ea2de257 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,10 @@ }, "devDependencies": { "bs-html-injector": "^3.0.0", + "eslint": "^2.2.0", "grunt": "~0.4.5", - "grunt-contrib-concat": "^0.5.1", "grunt-browser-sync": "^2.2.0", + "grunt-contrib-concat": "^0.5.1", "grunt-contrib-copy": "^0.8.2", "grunt-contrib-nodeunit": "^0.4.1", "grunt-contrib-watch": "^0.6.1" From c7609d7d42cf033f897e723c1bef4730490c30f4 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Sat, 27 Feb 2016 23:26:17 -0600 Subject: [PATCH 15/37] loosen rules on block scope "violations" and redeclares. --- .eslintrc | 4 +- builder/list_item_hunter.js | 3 +- builder/media_hunter.js | 16 ++--- builder/parameter_hunter.js | 24 ++++---- builder/pattern_assembler.js | 112 +++++++++++++++++------------------ builder/patternlab.js | 44 +++++++------- 6 files changed, 102 insertions(+), 101 deletions(-) diff --git a/.eslintrc b/.eslintrc index bcef947ef..3c2d195a1 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,7 +5,7 @@ }, "globals": {}, "rules": { - "block-scoped-var": 2, + "block-scoped-var": 1, "camelcase": 0, "comma-spacing": [1, {"before": false, "after": true}], "consistent-return": 2, @@ -51,7 +51,7 @@ "no-new": 2, "no-param-reassign": 2, "no-proto": 2, - "no-redeclare": 2, + "no-redeclare": 1, "no-script-url": 2, "no-self-assign": 2, "no-self-compare": 2, diff --git a/builder/list_item_hunter.js b/builder/list_item_hunter.js index 1474769dd..453e3c44b 100644 --- a/builder/list_item_hunter.js +++ b/builder/list_item_hunter.js @@ -17,7 +17,7 @@ var list_item_hunter = function () { smh = require('./style_modifier_hunter'), pattern_assembler = new pa(), style_modifier_hunter = new smh(), - items = [ 'zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen','twenty']; + items = [ 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty']; function processListItemPartials(pattern, patternlab) { //find any listitem blocks @@ -33,6 +33,7 @@ var list_item_hunter = function () { var loopNumberString = liMatch.split('.')[1].split('}')[0].trim(); var end = liMatch.replace('#', '/'); var patternBlock = pattern.template.substring(pattern.template.indexOf(liMatch) + liMatch.length, pattern.template.indexOf(end)).trim(); + //build arrays that repeat the block, however large we need to var repeatedBlockTemplate = []; var repeatedBlockHtml = ''; diff --git a/builder/media_hunter.js b/builder/media_hunter.js index 7aa12e10c..0422c27bb 100644 --- a/builder/media_hunter.js +++ b/builder/media_hunter.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v1.1.3 - 2016 - * +/* + * patternlab-node - v1.1.3 - 2016 + * * 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. * */ @@ -33,8 +33,8 @@ var media_hunter = function () { } }); patternlab.mediaQueries.sort(function (a, b) { - var integerPartA = a.match(/(?:\d*\.)?\d+/g); - var integerPartB = b.match(/(?:\d*\.)?\d+/g); + a.match(/(?:\d*\.)?\d+/g); + b.match(/(?:\d*\.)?\d+/g); return parseInt(a, 10) > parseInt(b, 10); }); } diff --git a/builder/parameter_hunter.js b/builder/parameter_hunter.js index 1c683780e..b0a92c0a9 100644 --- a/builder/parameter_hunter.js +++ b/builder/parameter_hunter.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v1.1.3 - 2016 - * +/* + * patternlab-node - v1.1.3 - 2016 + * * 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. * */ @@ -20,13 +20,13 @@ var parameter_hunter = function () { function findparameters(pattern, patternlab) { if (pattern.parameteredPartials && pattern.parameteredPartials.length > 0) { - //compile this partial immeadiately, essentially consuming it. - + //compile this partial immediately, essentially consuming it. + pattern.parameteredPartials.forEach(function (pMatch) { //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) { @@ -37,13 +37,13 @@ var parameter_hunter = function () { var leftParen = pMatch.indexOf('('); var rightParen = pMatch.indexOf(')'); var paramString = '{' + pMatch.substring(leftParen + 1, rightParen) + '}'; - + //if param keys are wrapped in single quotes, replace with double quotes. var paramStringWellFormed = paramString.replace(/(')([^']+)(')(\s*\:)/g, '"$2"$4'); - + //if params keys are not wrapped in any quotes, wrap in double quotes. paramStringWellFormed = paramStringWellFormed.replace(/([\{|,]\s*)([^\s"'\:]+)(\s*\:)/g, '$1"$2"$3'); - + //if param values are wrapped in single quotes, replace with double quotes. paramStringWellFormed = paramStringWellFormed.replace(/(\:\s*)(')([^']+)(')/g, '$1"$3"'); diff --git a/builder/pattern_assembler.js b/builder/pattern_assembler.js index 72ddf7364..c719ff25e 100644 --- a/builder/pattern_assembler.js +++ b/builder/pattern_assembler.js @@ -78,6 +78,62 @@ var pattern_assembler = function () { } } + function buildListItems(container) { + //combine all list items into one structure + var list = []; + for (var item in container.listitems) { + if (container.listitems.hasOwnProperty(item)) { + list.push(container.listitems[item]); + } + } + container.listItemArray = shuffle(list); + + for (var i = 1; i <= container.listItemArray.length; i++) { + var tempItems = []; + if (i === 1) { + tempItems.push(container.listItemArray[0]); + container.listitems['' + i ] = tempItems; + } else { + for (var c = 1; c <= i; c++) { + tempItems.push(container.listItemArray[c - 1]); + container.listitems['' + i ] = tempItems; + } + } + } + } + + function getpatternbykey(key, patternlab) { + var i; // for the for loops + + //look for exact key matches + for (i = 0; i < patternlab.patterns.length; i++) { + if (patternlab.patterns[i].key === key) { + return patternlab.patterns[i]; + } + } + + //else look by verbose syntax + for (i = 0; i < patternlab.patterns.length; i++) { + switch (key) { + case patternlab.patterns[i].subdir + '/' + patternlab.patterns[i].fileName: + case patternlab.patterns[i].subdir + '/' + patternlab.patterns[i].fileName + '.mustache': + return patternlab.patterns[i]; + } + } + + //return the fuzzy match if all else fails + for (i = 0; i < patternlab.patterns.length; i++) { + var keyParts = key.split('-'), + keyType = keyParts[0], + keyName = keyParts.slice(1).join('-'); + + if (patternlab.patterns[i].key.split('-')[0] === keyType && patternlab.patterns[i].key.indexOf(keyName) > -1) { + return patternlab.patterns[i]; + } + } + throw 'Could not find pattern with key ' + key; + } + function processPatternIterative(file, patternlab) { var fs = require('fs-extra'), of = require('./object_factory'), @@ -240,38 +296,6 @@ var pattern_assembler = function () { pseudopattern_hunter.find_pseudopatterns(currentPattern, patternlab); } - function getpatternbykey(key, patternlab) { - var i; // for the for loops - - //look for exact key matches - for (i = 0; i < patternlab.patterns.length; i++) { - if (patternlab.patterns[i].key === key) { - return patternlab.patterns[i]; - } - } - - //else look by verbose syntax - for (i = 0; i < patternlab.patterns.length; i++) { - switch (key) { - case patternlab.patterns[i].subdir + '/' + patternlab.patterns[i].fileName: - case patternlab.patterns[i].subdir + '/' + patternlab.patterns[i].fileName + '.mustache': - return patternlab.patterns[i]; - } - } - - //return the fuzzy match if all else fails - for (i = 0; i < patternlab.patterns.length; i++) { - var keyParts = key.split('-'), - keyType = keyParts[0], - keyName = keyParts.slice(1).join('-'); - - if (patternlab.patterns[i].key.split('-')[0] === keyType && patternlab.patterns[i].key.indexOf(keyName) > -1) { - return patternlab.patterns[i]; - } - } - throw 'Could not find pattern with key ' + key; - } - function mergeData(obj1, obj2) { /*eslint-disable guard-for-in, no-param-reassign*/ if (typeof obj2 === 'undefined') { @@ -302,30 +326,6 @@ var pattern_assembler = function () { return obj2; } - function buildListItems(container) { - //combine all list items into one structure - var list = []; - for (var item in container.listitems) { - if (container.listitems.hasOwnProperty(item)) { - list.push(container.listitems[item]); - } - } - container.listItemArray = shuffle(list); - - for (var i = 1; i <= container.listItemArray.length; i++) { - var tempItems = []; - if (i === 1) { - tempItems.push(container.listItemArray[0]); - container.listitems['' + i ] = tempItems; - } else { - for (var c = 1; c <= i; c++) { - tempItems.push(container.listItemArray[c - 1]); - container.listitems['' + i ] = tempItems; - } - } - } - } - //http://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array-in-javascript function shuffle(o) { /*eslint-disable curly*/ diff --git a/builder/patternlab.js b/builder/patternlab.js index d1745567b..cec23d10d 100644 --- a/builder/patternlab.js +++ b/builder/patternlab.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v1.1.3 - 2016 - * +/* + * patternlab-node - v1.1.3 - 2016 + * * 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. * */ @@ -153,13 +153,24 @@ var patternlab_engine = function (config) { pattern_exporter.export_patterns(patternlab); } + function addToPatternPaths(bucketName, pattern) { + //this is messy, could use a refactor. + patternlab.patternPaths[bucketName][pattern.patternName] = pattern.subdir.replace(/\\/g, '/') + "/" + pattern.fileName; + } + + //todo: refactor this as a method on the pattern object itself once we merge dev with pattern-engines branch + function isPatternExcluded(pattern) { + // returns whether or not the first character of the pattern filename is an underscore, or excluded + return pattern.fileName.charAt(0) === '_'; + } + function buildFrontEnd() { var pattern_assembler = new pa(), media_hunter = new mh(), styleGuideExcludes = patternlab.config.styleGuideExcludes, styleguidePatterns = [], i; // for loops - + patternlab.buckets = []; patternlab.bucketIndex = []; patternlab.patternPaths = {}; @@ -169,7 +180,7 @@ var patternlab_engine = function (config) { patternlab.patterns = patternlab.patterns.sort(function (a, b) { if (a.name > b.name) { return 1; } if (a.name < b.name) { return -1; } - + // a must be equal to b return 0; }); @@ -203,7 +214,7 @@ var patternlab_engine = function (config) { //build the styleguide var styleguideTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'styleguide.mustache'), 'utf8'), styleguideHtml = pattern_assembler.renderPattern(styleguideTemplate, {partials: styleguidePatterns}); - + fs.outputFileSync(path.resolve(paths.public.styleguide, 'html/styleguide.html'), styleguideHtml); //build the viewall pages @@ -325,7 +336,7 @@ var patternlab_engine = function (config) { navSubItem.patternPartial = bucketName + "-" + pattern.patternName; //add the hyphenated name //add the patternState if it exists - if(pattern.patternState){ + if (pattern.patternState) { navSubItem.patternState = pattern.patternState; } @@ -351,7 +362,7 @@ var patternlab_engine = function (config) { navViewAllItem.patternPartial = "viewall-" + pattern.patternGroup; bucket.patternItems.push(navViewAllItem); - patternlab.viewAllPaths[bucketName]['viewall'] = pattern.subdir.slice(0, pattern.subdir.indexOf(pattern.patternGroup) + pattern.patternGroup.length); + patternlab.viewAllPaths[bucketName].viewall = pattern.subdir.slice(0, pattern.subdir.indexOf(pattern.patternGroup) + pattern.patternGroup.length); } //add the bucket. @@ -477,17 +488,6 @@ var patternlab_engine = function (config) { fs.outputFileSync(path.resolve(paths.public.root, 'index.html'), patternlabSiteHtml); } - function addToPatternPaths(bucketName, pattern) { - //this is messy, could use a refactor. - patternlab.patternPaths[bucketName][pattern.patternName] = pattern.subdir.replace(/\\/g, '/') + "/" + pattern.fileName; - } - - //todo: refactor this as a method on the pattern object itself once we merge dev with pattern-engines branch - function isPatternExcluded(pattern) { - // returns whether or not the first character of the pattern filename is an underscore, or excluded - return pattern.fileName.charAt(0) === '_'; - } - return { version: function () { return getVersion(); From 07148557ef990fd9319dc56b7e7075f55241fe9f Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Sat, 27 Feb 2016 23:47:06 -0600 Subject: [PATCH 16/37] shortened the eslint consecutive variable declaration indent- because editorconfig did not seem to support it, so the two tools would create contention. I can live with "misaligned" variables. ask me about work sometime --- .eslintrc | 2 +- builder/media_hunter.js | 4 +-- builder/parameter_hunter.js | 8 ++--- builder/pattern_assembler.js | 28 +++++++-------- builder/pattern_exporter.js | 14 ++++---- builder/patternlab.js | 42 +++++++++++----------- builder/patternlab_gulp.js | 14 ++++---- builder/pseudopattern_hunter.js | 22 ++++++------ builder/style_modifier_hunter.js | 60 ++++++++++++++++---------------- 9 files changed, 97 insertions(+), 97 deletions(-) diff --git a/.eslintrc b/.eslintrc index 3c2d195a1..fcea5476b 100644 --- a/.eslintrc +++ b/.eslintrc @@ -14,7 +14,7 @@ "eqeqeq": [2, "allow-null"], "global-strict": [0, "never"], "guard-for-in": 2, - "indent": [2, 2, {"SwitchCase": 1, "VariableDeclarator": 2}], + "indent": [2, 2, {"SwitchCase": 1, "VariableDeclarator": 1}], "lines-around-comment": [2, { "beforeBlockComment": true, "beforeLineComment": true, diff --git a/builder/media_hunter.js b/builder/media_hunter.js index 0422c27bb..e8de9a81f 100644 --- a/builder/media_hunter.js +++ b/builder/media_hunter.js @@ -11,8 +11,8 @@ "use strict"; var diveSync = require('diveSync'), - path = require('path'), - fs = require('fs-extra'); + path = require('path'), + fs = require('fs-extra'); var media_hunter = function () { diff --git a/builder/parameter_hunter.js b/builder/parameter_hunter.js index b0a92c0a9..72f8d7603 100644 --- a/builder/parameter_hunter.js +++ b/builder/parameter_hunter.js @@ -13,10 +13,10 @@ var parameter_hunter = function () { var extend = require('util')._extend, - pa = require('./pattern_assembler'), - smh = require('./style_modifier_hunter'), - style_modifier_hunter = new smh(), - pattern_assembler = new pa(); + pa = require('./pattern_assembler'), + smh = require('./style_modifier_hunter'), + style_modifier_hunter = new smh(), + pattern_assembler = new pa(); function findparameters(pattern, patternlab) { if (pattern.parameteredPartials && pattern.parameteredPartials.length > 0) { diff --git a/builder/pattern_assembler.js b/builder/pattern_assembler.js index c719ff25e..757844c24 100644 --- a/builder/pattern_assembler.js +++ b/builder/pattern_assembler.js @@ -92,11 +92,11 @@ var pattern_assembler = function () { var tempItems = []; if (i === 1) { tempItems.push(container.listItemArray[0]); - container.listitems['' + i ] = tempItems; + container.listitems['' + i] = tempItems; } else { for (var c = 1; c <= i; c++) { tempItems.push(container.listItemArray[c - 1]); - container.listitems['' + i ] = tempItems; + container.listitems['' + i] = tempItems; } } } @@ -136,8 +136,8 @@ var pattern_assembler = function () { function processPatternIterative(file, patternlab) { var fs = require('fs-extra'), - of = require('./object_factory'), - path = require('path'); + of = require('./object_factory'), + path = require('path'); //extract some information var subdir = path.dirname(path.relative(patternlab.config.paths.source.patterns, file)).replace('\\', '/'); @@ -206,20 +206,20 @@ var pattern_assembler = function () { function processPatternRecursive(file, patternlab) { var lh = require('./lineage_hunter'), - ph = require('./parameter_hunter'), - pph = require('./pseudopattern_hunter'), - lih = require('./list_item_hunter'), - smh = require('./style_modifier_hunter'); + ph = require('./parameter_hunter'), + pph = require('./pseudopattern_hunter'), + lih = require('./list_item_hunter'), + smh = require('./style_modifier_hunter'); var parameter_hunter = new ph(), - lineage_hunter = new lh(), - list_item_hunter = new lih(), - style_modifier_hunter = new smh(), - pseudopattern_hunter = new pph(); + lineage_hunter = new lh(), + list_item_hunter = new lih(), + style_modifier_hunter = new smh(), + pseudopattern_hunter = new pph(); //find current pattern in patternlab object using var file as a key var currentPattern, - i; + i; for (i = 0; i < patternlab.patterns.length; i++) { if (patternlab.patterns[i].abspath === file) { @@ -259,7 +259,7 @@ var pattern_assembler = function () { //identify which pattern this partial corresponds tou for (var j = 0; j < patternlab.patterns.length; j++) { if (patternlab.patterns[j].key === partialKey || - patternlab.patterns[j].abspath.indexOf(partialKey) > -1) { + patternlab.patterns[j].abspath.indexOf(partialKey) > -1) { partialPath = patternlab.patterns[j].abspath; } } diff --git a/builder/pattern_exporter.js b/builder/pattern_exporter.js index a7a70c05b..23c9777a4 100644 --- a/builder/pattern_exporter.js +++ b/builder/pattern_exporter.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v1.1.3 - 2016 - * +/* + * patternlab-node - v1.1.3 - 2016 + * * 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. * */ @@ -13,7 +13,7 @@ var fs = require('fs-extra'); var pattern_exporter = function () { - + function exportPatterns(patternlab) { //read the config export options var exportKeys = patternlab.config.patternExportKeys; diff --git a/builder/patternlab.js b/builder/patternlab.js index cec23d10d..b4705deaf 100644 --- a/builder/patternlab.js +++ b/builder/patternlab.js @@ -12,14 +12,14 @@ var patternlab_engine = function (config) { 'use strict'; var path = require('path'), - fs = require('fs-extra'), - diveSync = require('diveSync'), - of = require('./object_factory'), - pa = require('./pattern_assembler'), - mh = require('./media_hunter'), - pe = require('./pattern_exporter'), - he = require('html-entities').AllHtmlEntities, - patternlab = {}; + fs = require('fs-extra'), + diveSync = require('diveSync'), + of = require('./object_factory'), + pa = require('./pattern_assembler'), + mh = require('./media_hunter'), + pe = require('./pattern_exporter'), + he = require('html-entities').AllHtmlEntities, + patternlab = {}; patternlab.package = fs.readJSONSync('./package.json'); patternlab.config = config || fs.readJSONSync(path.resolve(__dirname, '../config.json')); @@ -64,9 +64,9 @@ var patternlab_engine = function (config) { patternlab.data.link = {}; var pattern_assembler = new pa(), - entity_encoder = new he(), - pattern_exporter = new pe(), - patterns_dir = paths.source.patterns; + entity_encoder = new he(), + pattern_exporter = new pe(), + patterns_dir = paths.source.patterns; pattern_assembler.combine_listItems(patternlab); @@ -166,10 +166,10 @@ var patternlab_engine = function (config) { function buildFrontEnd() { var pattern_assembler = new pa(), - media_hunter = new mh(), - styleGuideExcludes = patternlab.config.styleGuideExcludes, - styleguidePatterns = [], - i; // for loops + media_hunter = new mh(), + styleGuideExcludes = patternlab.config.styleGuideExcludes, + styleguidePatterns = [], + i; // for loops patternlab.buckets = []; patternlab.bucketIndex = []; @@ -213,13 +213,13 @@ var patternlab_engine = function (config) { //build the styleguide var styleguideTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'styleguide.mustache'), 'utf8'), - styleguideHtml = pattern_assembler.renderPattern(styleguideTemplate, {partials: styleguidePatterns}); + styleguideHtml = pattern_assembler.renderPattern(styleguideTemplate, {partials: styleguidePatterns}); fs.outputFileSync(path.resolve(paths.public.styleguide, 'html/styleguide.html'), styleguideHtml); //build the viewall pages var prevSubdir = '', - prevGroup = ''; + prevGroup = ''; for (i = 0; i < patternlab.patterns.length; i++) { // skip underscore-prefixed files @@ -238,8 +238,8 @@ var patternlab_engine = function (config) { prevGroup = pattern.patternGroup; var viewAllPatterns = [], - patternPartial = "viewall-" + pattern.patternGroup, - j; + patternPartial = "viewall-" + pattern.patternGroup, + j; for (j = 0; j < patternlab.patterns.length; j++) { if (patternlab.patterns[j].patternGroup === pattern.patternGroup) { @@ -266,8 +266,8 @@ var patternlab_engine = function (config) { prevSubdir = pattern.subdir; var viewAllPatterns = [], - patternPartial = "viewall-" + pattern.patternGroup + "-" + pattern.patternSubGroup, - j; + patternPartial = "viewall-" + pattern.patternGroup + "-" + pattern.patternSubGroup, + j; for (j = 0; j < patternlab.patterns.length; j++) { if (patternlab.patterns[j].subdir === pattern.subdir) { diff --git a/builder/patternlab_gulp.js b/builder/patternlab_gulp.js index 291940b30..82cf2a4ce 100644 --- a/builder/patternlab_gulp.js +++ b/builder/patternlab_gulp.js @@ -1,17 +1,17 @@ -/* - * patternlab-node - v1.1.3 - 2016 - * +/* + * patternlab-node - v1.1.3 - 2016 + * * 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. * */ var patternlab_engine = require('./patternlab.js'); module.exports = function (gulp) { - + gulp.task('patternlab', ['clean'], function (cb) { var patternlab = patternlab_engine(); patternlab.build(false); diff --git a/builder/pseudopattern_hunter.js b/builder/pseudopattern_hunter.js index 0f0907ea1..6366be9e8 100644 --- a/builder/pseudopattern_hunter.js +++ b/builder/pseudopattern_hunter.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v1.1.3 - 2016 - * +/* + * patternlab-node - v1.1.3 - 2016 + * * 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. * */ @@ -14,11 +14,11 @@ var pseudopattern_hunter = function () { function findpseudopatterns(currentPattern, patternlab) { var glob = require('glob'), - fs = require('fs-extra'), - pa = require('./pattern_assembler'), - lh = require('./lineage_hunter'), - of = require('./object_factory'), - path = require('path'); + fs = require('fs-extra'), + pa = require('./pattern_assembler'), + lh = require('./lineage_hunter'), + of = require('./object_factory'), + path = require('path'); var pattern_assembler = new pa(); var lineage_hunter = new lh(); diff --git a/builder/style_modifier_hunter.js b/builder/style_modifier_hunter.js index b9b616b86..742009ce4 100644 --- a/builder/style_modifier_hunter.js +++ b/builder/style_modifier_hunter.js @@ -1,43 +1,43 @@ -/* - * patternlab-node - v1.1.3 - 2016 - * +/* + * patternlab-node - v1.1.3 - 2016 + * * 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. * */ - "use strict"; - - var style_modifier_hunter = function () { +"use strict"; - 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; - - if (styleModifier) { - //replace the special character pipe | used to separate multiple classes with a space - styleModifier = styleModifier.replace(/\|/g, ' '); +var style_modifier_hunter = function () { - if (patternlab.config.debug) { - console.log('found partial styleModifier within pattern ' + pattern.key); - } + 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; - //replace the stylemodifier placeholder with the class name - pattern.extendedTemplate = pattern.extendedTemplate.replace(/{{[ ]?styleModifier[ ]?}}/i, styleModifier); + if (styleModifier) { + //replace the special character pipe | used to separate multiple classes with a space + styleModifier = styleModifier.replace(/\|/g, ' '); - //update the extendedTemplate in the partials object in case this pattern is consumed later - patternlab.partials[pattern.key] = pattern.extendedTemplate; + if (patternlab.config.debug) { + console.log('found partial styleModifier within pattern ' + pattern.key); } - } - return { - consume_style_modifier: function (pattern, partial, patternlab) { - consumestylemodifier(pattern, partial, patternlab); - } - }; + //replace the stylemodifier placeholder with the class name + pattern.extendedTemplate = pattern.extendedTemplate.replace(/{{[ ]?styleModifier[ ]?}}/i, styleModifier); + //update the extendedTemplate in the partials object in case this pattern is consumed later + patternlab.partials[pattern.key] = pattern.extendedTemplate; + } + } + + return { + consume_style_modifier: function (pattern, partial, patternlab) { + consumestylemodifier(pattern, partial, patternlab); + } }; - module.exports = style_modifier_hunter; +}; + +module.exports = style_modifier_hunter; From 7fab92b10c6cd4b021c7ec8f860fb81309fbc690 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Sat, 27 Feb 2016 23:49:09 -0600 Subject: [PATCH 17/37] missed reformatting this file --- builder/list_item_hunter.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/builder/list_item_hunter.js b/builder/list_item_hunter.js index 453e3c44b..7fcf3d188 100644 --- a/builder/list_item_hunter.js +++ b/builder/list_item_hunter.js @@ -13,11 +13,11 @@ var list_item_hunter = function () { var extend = require('util')._extend, - pa = require('./pattern_assembler'), - smh = require('./style_modifier_hunter'), - pattern_assembler = new pa(), - style_modifier_hunter = new smh(), - items = [ 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty']; + pa = require('./pattern_assembler'), + smh = require('./style_modifier_hunter'), + pattern_assembler = new pa(), + style_modifier_hunter = new smh(), + items = [ 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty']; function processListItemPartials(pattern, patternlab) { //find any listitem blocks From c304a78a8020e08cd5a7875e0d36c67b51e9851f Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Sun, 28 Feb 2016 08:20:58 -0600 Subject: [PATCH 18/37] turn off block scoped var rule --- .eslintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index fcea5476b..df838cd02 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,7 +5,7 @@ }, "globals": {}, "rules": { - "block-scoped-var": 1, + "block-scoped-var": 0, "camelcase": 0, "comma-spacing": [1, {"before": false, "after": true}], "consistent-return": 2, From 657ca995161d171db8d29dd85041a692a48b0cc3 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Sun, 28 Feb 2016 08:22:17 -0600 Subject: [PATCH 19/37] turn off redeclare --- .eslintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index df838cd02..434d9fe85 100644 --- a/.eslintrc +++ b/.eslintrc @@ -51,7 +51,7 @@ "no-new": 2, "no-param-reassign": 2, "no-proto": 2, - "no-redeclare": 1, + "no-redeclare": 0, "no-script-url": 2, "no-self-assign": 2, "no-self-compare": 2, From 79855cbbfee8ca6dd1475129cf0927ab18024443 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Sun, 28 Feb 2016 22:56:40 -0600 Subject: [PATCH 20/37] Added eslint tasks to build (both) and travis step (grunt only) deleted jslintrc file Addresses #274 --- .jslintrc | 36 ------------------------------------ Gruntfile.js | 10 ++++++++-- builder/pattern_assembler.js | 17 +++++++---------- gulpfile.js | 11 ++++++++++- package.gulp.json | 2 +- package.json | 4 ++-- 6 files changed, 28 insertions(+), 52 deletions(-) delete mode 100644 .jslintrc diff --git a/.jslintrc b/.jslintrc deleted file mode 100644 index 8ac6b2e37..000000000 --- a/.jslintrc +++ /dev/null @@ -1,36 +0,0 @@ -{ - "ass": false, - "bitwise": false, - "browser": false, - "closure": false, - "continue": false, - "couch": false, - "debug": false, - "devel": true, - "eqeq": false, - "eval": true, - "evil": false, - "forin": false, - "indent": 2, - "maxerr": 50, - "maxlen": false, - "newcap": false, - "node": true, - "nomen": false, - "passfail": false, - "plusplus": false, - "predef": [ - "node", - "$", - "require" - ], - "regexp": false, - "rhino": false, - "sloppy": false, - "stupid": false, - "sub": false, - "todo": false, - "unparam": true, - "vars": false, - "white": true -} diff --git a/Gruntfile.js b/Gruntfile.js index 51452919f..96f35a284 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -138,6 +138,12 @@ module.exports = function (grunt) { } } }, + eslint: { + options: { + configFile: './.eslintrc' + }, + target: ['./builder/*'] + }, bsReload: { css: path.resolve(paths().public.root + '**/*.css') } @@ -152,10 +158,10 @@ module.exports = function (grunt) { grunt.registerTask('default', ['patternlab', 'copy:main', 'copy:styleguide']); //travis CI task - grunt.registerTask('travis', ['nodeunit', 'patternlab']); + grunt.registerTask('travis', ['nodeunit', 'eslint', 'patternlab']); grunt.registerTask('serve', ['patternlab', 'copy:main', 'copy:styleguide', 'browserSync', 'watch:all']); - grunt.registerTask('build', ['nodeunit', 'concat']); + grunt.registerTask('build', ['nodeunit', 'eslint', 'concat']); }; diff --git a/builder/pattern_assembler.js b/builder/pattern_assembler.js index 757844c24..6f17f62e0 100644 --- a/builder/pattern_assembler.js +++ b/builder/pattern_assembler.js @@ -8,7 +8,6 @@ * */ - "use strict"; var pattern_assembler = function () { @@ -78,6 +77,12 @@ var pattern_assembler = function () { } } + //http://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array-in-javascript + function shuffle(o) { + for (var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); + return o; + } + function buildListItems(container) { //combine all list items into one structure var list = []; @@ -297,8 +302,7 @@ var pattern_assembler = function () { } function mergeData(obj1, obj2) { - /*eslint-disable guard-for-in, no-param-reassign*/ - if (typeof obj2 === 'undefined') { + if (typeof obj2 === 'undefined') { obj2 = {}; } for (var p in obj1) { @@ -326,13 +330,6 @@ var pattern_assembler = function () { return obj2; } - //http://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array-in-javascript - function shuffle(o) { - /*eslint-disable curly*/ - for (var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); - return o; - } - function parseDataLinksHelper(patternlab, obj, key) { var linkRE, dataObjAsString, linkMatches, expandedLink; diff --git a/gulpfile.js b/gulpfile.js index 8e93df2b0..6519b0213 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -9,6 +9,7 @@ var pkg = require('./package.json'), strip_banner = require('gulp-strip-banner'), header = require('gulp-header'), nodeunit = require('gulp-nodeunit'), + eslint = require('gulp-eslint'), browserSync = require('browser-sync').create(); require('gulp-load')(gulp); @@ -151,6 +152,14 @@ gulp.task('connect', ['lab'], function () { }); +//lint +gulp.task('eslint', function () { + return gulp.src(['./builder/*.js', '!node_modules/**']) + .pipe(eslint()) + .pipe(eslint.format()) + .pipe(eslint.failAfterError()); +}); + //unit test gulp.task('nodeunit', function () { return gulp.src('./test/**/*_tests.js') @@ -170,7 +179,7 @@ gulp.task('prelab', ['clean', 'assets']); gulp.task('lab', ['prelab', 'patternlab'], function (cb) { cb(); }); gulp.task('patterns', ['patternlab:only_patterns']); gulp.task('serve', ['lab', 'connect']); -gulp.task('travis', ['lab', 'nodeunit']); +gulp.task('build', ['eslint', 'nodeunit', 'banner']); gulp.task('version', ['patternlab:version']); gulp.task('help', ['patternlab:help']); diff --git a/package.gulp.json b/package.gulp.json index 3f2663854..87a4d0044 100644 --- a/package.gulp.json +++ b/package.gulp.json @@ -13,10 +13,10 @@ }, "devDependencies": { "browser-sync": "^2.11.1", - "eslint": "^2.2.0", "gulp": "^3.9.0", "gulp-connect": "^2.3.1", "gulp-copy": "0.0.2", + "gulp-eslint": "^2.0.0", "gulp-header": "^1.7.1", "gulp-load": "^0.1.1", "gulp-nodeunit": "0.0.5", diff --git a/package.json b/package.json index 5ea2de257..a62664b52 100644 --- a/package.json +++ b/package.json @@ -13,13 +13,13 @@ }, "devDependencies": { "bs-html-injector": "^3.0.0", - "eslint": "^2.2.0", "grunt": "~0.4.5", "grunt-browser-sync": "^2.2.0", "grunt-contrib-concat": "^0.5.1", "grunt-contrib-copy": "^0.8.2", "grunt-contrib-nodeunit": "^0.4.1", - "grunt-contrib-watch": "^0.6.1" + "grunt-contrib-watch": "^0.6.1", + "grunt-eslint": "^18.0.0" }, "keywords": [ "Pattern Lab", From c638157271f1244fac398a615f74c55bcdf441b1 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Sun, 28 Feb 2016 23:23:30 -0600 Subject: [PATCH 21/37] add note about our new standardization tools in CONTRIBUTING.md closes #274 --- .github/CONTRIBUTING.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 7edd1a3d0..8598cddb2 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -1,5 +1,5 @@ # Contributing to Patternlab Node -If you'd like to contribute to Pattern Lab Node, please do so! There is always a lot of ground to cover and something for your wheelhouse. +If you'd like to contribute to Pattern Lab Node, please do so! There is always a lot of ground to cover and something for your wheelhouse. 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, or add some more unit tests. @@ -9,4 +9,7 @@ No pull request is too small. Check out any [up for grabs issues](https://github 3. If you can, add some unit tests using the existing patterns in the `./test` directory ##Coding style -Regarding code style like indentation and whitespace, follow the conventions you see used in the source already. Add enough source code comments to help the next person. +Two files combine within the project to define and maintain our coding style. + +* The `.editorconfig` controls spaces / tabs within supported editors. Check out their [site](http://editorconfig.org/). +* The `.eslintrc` defines our javascript standards. Some editors will evaluate this real-time - otherwise it's run using `grunt|gulp build` From 2e3236b911342ec47e6740be356410478afddec6 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Mon, 29 Feb 2016 00:33:24 -0600 Subject: [PATCH 22/37] fix a bad merge --- builder/parameter_hunter.js | 117 ++++++++++++++++++++++++++++++++--- builder/pattern_assembler.js | 3 +- 2 files changed, 108 insertions(+), 12 deletions(-) diff --git a/builder/parameter_hunter.js b/builder/parameter_hunter.js index 73c804de1..2f8738034 100644 --- a/builder/parameter_hunter.js +++ b/builder/parameter_hunter.js @@ -18,10 +18,114 @@ var parameter_hunter = function () { style_modifier_hunter = new smh(), pattern_assembler = new pa(); + function paramToJson(pString) { + var paramStringWellFormed = ''; + var paramStringTmp; + var colonPos; + var delimitPos; + var quotePos; + var paramString = pString; + + do { + + //if param key is wrapped in single quotes, replace with double quotes. + paramString = paramString.replace(/(^\s*[\{|\,]\s*)'([^']+)'(\s*\:)/, '$1"$2"$3'); + + //if params key is not wrapped in any quotes, wrap in double quotes. + paramString = paramString.replace(/(^\s*[\{|\,]\s*)([^\s"'\:]+)(\s*\:)/, '$1"$2"$3'); + + //move param key to paramStringWellFormed var. + colonPos = paramString.indexOf(':'); + + //except to prevent infinite loops. + if (colonPos === -1) { + colonPos = paramString.length - 1; + } + else { + colonPos += 1; + } + paramStringWellFormed += paramString.substring(0, colonPos); + paramString = paramString.substring(colonPos, paramString.length).trim(); + + //if param value is wrapped in single quotes, replace with double quotes. + if (paramString[0] === '\'') { + quotePos = paramString.search(/[^\\]'/); + + //except for unclosed quotes to prevent infinite loops. + if (quotePos === -1) { + quotePos = paramString.length - 1; + } + else { + quotePos += 2; + } + + //prepare param value for move to paramStringWellFormed var. + paramStringTmp = paramString.substring(0, quotePos); + + //unescape any escaped single quotes. + paramStringTmp = paramStringTmp.replace(/\\'/g, '\''); + + //escape any double quotes. + paramStringTmp = paramStringTmp.replace(/"/g, '\\"'); + + //replace the delimiting single quotes with double quotes. + paramStringTmp = paramStringTmp.replace(/^'/, '"'); + paramStringTmp = paramStringTmp.replace(/'$/, '"'); + + //move param key to paramStringWellFormed var. + paramStringWellFormed += paramStringTmp; + paramString = paramString.substring(quotePos, paramString.length).trim(); + } + + //if param value is wrapped in double quotes, just move to paramStringWellFormed var. + else if (paramString[0] === '"') { + quotePos = paramString.search(/[^\\]"/); + + //except for unclosed quotes to prevent infinite loops. + if (quotePos === -1) { + quotePos = paramString.length - 1; + } + else { + quotePos += 2; + } + + //move param key to paramStringWellFormed var. + paramStringWellFormed += paramString.substring(0, quotePos); + paramString = paramString.substring(quotePos, paramString.length).trim(); + } + + //if param value is not wrapped in quotes, move everthing up to the delimiting comma to paramStringWellFormed var. + else { + delimitPos = paramString.indexOf(','); + + //except to prevent infinite loops. + if (delimitPos === -1) { + delimitPos = paramString.length - 1; + } + else { + delimitPos += 1; + } + paramStringWellFormed += paramString.substring(0, delimitPos); + paramString = paramString.substring(delimitPos, paramString.length).trim(); + } + + //break at the end. + if (paramString.length === 1) { + paramStringWellFormed += paramString.trim(); + paramString = ''; + break; + } + + } while (paramString); + + return paramStringWellFormed; + } + function findparameters(pattern, patternlab) { + if (pattern.parameteredPartials && pattern.parameteredPartials.length > 0) { - //compile this partial immediately, essentially consuming it. + //compile this partial immeadiately, essentially consuming it. pattern.parameteredPartials.forEach(function (pMatch) { //find the partial's name and retrieve it var partialName = pMatch.match(/([\w\-\.\/~]+)/g)[0]; @@ -29,6 +133,7 @@ var parameter_hunter = function () { //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); } @@ -37,15 +142,7 @@ var parameter_hunter = function () { var leftParen = pMatch.indexOf('('); var rightParen = pMatch.indexOf(')'); var paramString = '{' + pMatch.substring(leftParen + 1, rightParen) + '}'; - - //if param keys are wrapped in single quotes, replace with double quotes. - var paramStringWellFormed = paramString.replace(/(')([^']+)(')(\s*\:)/g, '"$2"$4'); - - //if params keys are not wrapped in any quotes, wrap in double quotes. - paramStringWellFormed = paramStringWellFormed.replace(/([\{|,]\s*)([^\s"'\:]+)(\s*\:)/g, '$1"$2"$3'); - - //if param values are wrapped in single quotes, replace with double quotes. - paramStringWellFormed = paramStringWellFormed.replace(/(\:\s*)(')([^']+)(')/g, '$1"$3"'); + var paramStringWellFormed = paramToJson(paramString); var paramData = {}; var globalData = {}; diff --git a/builder/pattern_assembler.js b/builder/pattern_assembler.js index 9bf227de0..2d40c1544 100644 --- a/builder/pattern_assembler.js +++ b/builder/pattern_assembler.js @@ -303,8 +303,7 @@ var pattern_assembler = function () { function mergeData(obj1, obj2) { if (typeof obj2 === 'undefined') { - //noinspection Eslint - obj2 = {}; + obj2 = {}; //eslint-disable-line no-param-reassign } for (var p in obj1) { //eslint-disable-line guard-for-in From b746ff8b35c5b0c8a3fdc8bf8d5118916a942de5 Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Mon, 29 Feb 2016 09:50:08 -0600 Subject: [PATCH 23/37] oops, debugger statement --- builder/patternlab.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/builder/patternlab.js b/builder/patternlab.js index 9b99f3553..1cdd75a9a 100644 --- a/builder/patternlab.js +++ b/builder/patternlab.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v1.1.3 - 2016 - * +/* + * patternlab-node - v1.1.3 - 2016 + * * 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. * */ @@ -473,8 +473,6 @@ var patternlab_engine = function (config) { var viewAllPathsPartialHtml = pattern_assembler.renderPattern(viewAllPathsTemplate, {'viewallpaths': JSON.stringify(patternlab.viewAllPaths)}); //render the patternlab template, with all partials - debugger; - var patternlabSiteHtml = pattern_assembler.renderPattern(patternlabSiteTemplate, { defaultPattern: patternlab.config.defaultPattern || 'all' }, { From 211b2334c8443b6923772902ecf0dc2a358e1a1a Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Wed, 2 Mar 2016 09:39:15 -0600 Subject: [PATCH 24/37] moved builder/*.js files and fixed all references passing unit tests and building frontend #133 --- Gruntfile.js | 52 +++++++++---------- README.md | 4 +- {builder => core/lib}/lineage_hunter.js | 0 {builder => core/lib}/list_item_hunter.js | 0 {builder => core/lib}/media_hunter.js | 0 {builder => core/lib}/object_factory.js | 0 {builder => core/lib}/parameter_hunter.js | 0 {builder => core/lib}/pattern_assembler.js | 0 {builder => core/lib}/pattern_exporter.js | 0 {builder => core/lib}/patternlab.js | 2 +- {builder => core/lib}/patternlab_grunt.js | 0 {builder => core/lib}/patternlab_gulp.js | 0 {builder => core/lib}/pseudopattern_hunter.js | 0 .../lib}/style_modifier_hunter.js | 0 gulpfile.js | 30 +++++------ package.gulp.json | 2 +- package.json | 2 +- test/lineage_hunter_tests.js | 2 +- test/list_item_hunter_tests.js | 6 +-- test/media_hunter_tests.js | 2 +- test/object_factory_tests.js | 2 +- test/parameter_hunter_tests.js | 2 +- test/pattern_assembler_tests.js | 14 ++--- test/pseudopattern_hunter_tests.js | 6 +-- test/style_modifier_hunter_tests.js | 2 +- 25 files changed, 64 insertions(+), 64 deletions(-) rename {builder => core/lib}/lineage_hunter.js (100%) rename {builder => core/lib}/list_item_hunter.js (100%) rename {builder => core/lib}/media_hunter.js (100%) rename {builder => core/lib}/object_factory.js (100%) rename {builder => core/lib}/parameter_hunter.js (100%) rename {builder => core/lib}/pattern_assembler.js (100%) rename {builder => core/lib}/pattern_exporter.js (100%) rename {builder => core/lib}/patternlab.js (99%) rename {builder => core/lib}/patternlab_grunt.js (100%) rename {builder => core/lib}/patternlab_gulp.js (100%) rename {builder => core/lib}/pseudopattern_hunter.js (100%) rename {builder => core/lib}/style_modifier_hunter.js (100%) diff --git a/Gruntfile.js b/Gruntfile.js index 2dfa9be8a..2f5dc2ad3 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -15,52 +15,52 @@ module.exports = function (grunt) { banner: '/* \n * <%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy") %> \n * \n * <%= pkg.author %>, and the web community.\n * Licensed under the <%= pkg.license %> license. \n * \n * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. \n *\n */\n\n', }, patternlab: { - src: './builder/patternlab.js', - dest: './builder/patternlab.js' + src: './core/lib/patternlab.js', + dest: './core/lib/patternlab.js' }, object_factory: { - src: './builder/object_factory.js', - dest: './builder/object_factory.js' + src: './core/lib/object_factory.js', + dest: './core/lib/object_factory.js' }, lineage: { - src: './builder/lineage_hunter.js', - dest: './builder/lineage_hunter.js' + src: './core/lib/lineage_hunter.js', + dest: './core/lib/lineage_hunter.js' }, media_hunter: { - src: './builder/media_hunter.js', - dest: './builder/media_hunter.js' + src: './core/lib/media_hunter.js', + dest: './core/lib/media_hunter.js' }, patternlab_grunt: { - src: './builder/patternlab_grunt.js', - dest: './builder/patternlab_grunt.js' + src: './core/lib/patternlab_grunt.js', + dest: './core/lib/patternlab_grunt.js' }, patternlab_gulp: { - src: './builder/patternlab_gulp.js', - dest: './builder/patternlab_gulp.js' + src: './core/lib/patternlab_gulp.js', + dest: './core/lib/patternlab_gulp.js' }, parameter_hunter: { - src: './builder/parameter_hunter.js', - dest: './builder/parameter_hunter.js' + src: './core/lib/parameter_hunter.js', + dest: './core/lib/parameter_hunter.js' }, pattern_exporter: { - src: './builder/pattern_exporter.js', - dest: './builder/pattern_exporter.js' + src: './core/lib/pattern_exporter.js', + dest: './core/lib/pattern_exporter.js' }, pattern_assembler: { - src: './builder/pattern_assembler.js', - dest: './builder/pattern_assembler.js' + src: './core/lib/pattern_assembler.js', + dest: './core/lib/pattern_assembler.js' }, pseudopattern_hunter: { - src: './builder/pseudopattern_hunter.js', - dest: './builder/pseudopattern_hunter.js' + src: './core/lib/pseudopattern_hunter.js', + dest: './core/lib/pseudopattern_hunter.js' }, list_item_hunter: { - src: './builder/list_item_hunter.js', - dest: './builder/list_item_hunter.js' + src: './core/lib/list_item_hunter.js', + dest: './core/lib/list_item_hunter.js' }, style_modifier_hunter: { - src: './builder/style_modifier_hunter.js', - dest: './builder/style_modifier_hunter.js' + src: './core/lib/style_modifier_hunter.js', + dest: './core/lib/style_modifier_hunter.js' } }, copy: { @@ -142,7 +142,7 @@ module.exports = function (grunt) { options: { configFile: './.eslintrc' }, - target: ['./builder/*'] + target: ['./core/lib/*'] }, bsReload: { css: path.resolve(paths().public.root + '**/*.css') @@ -153,7 +153,7 @@ module.exports = function (grunt) { require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); //load the patternlab task - grunt.task.loadTasks('./builder/'); + grunt.task.loadTasks('./core/lib/'); grunt.registerTask('default', ['patternlab', 'copy:main', 'copy:styleguide']); diff --git a/README.md b/README.md index 156abd8ac..c934f0738 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,8 @@ This repository ships with two `package.json` files, a `Gruntfile.js`, and a `gu To run patternlab-node using grunt, do the following in the directory you downloaded and extracted the zipped release: 1. Run `npm install` from the command line -2. Optionally, delete `package.gulp.json`, `gulpfile.js`, and `builder/patternlab_gulp.js` files if you are certain you don't need it. -* Not deleting `builder/patternlab_gulp.js` may cause a harmless error when running grunt. Delete it. +2. Optionally, delete `package.gulp.json`, `gulpfile.js`, and `core/lib/patternlab_gulp.js` files if you are certain you don't need it. +* Not deleting `core/lib/patternlab_gulp.js` may cause a harmless error when running grunt. Delete it. 3. Run `grunt` or `grunt serve` from the command line This creates all patterns, the styleguide, and the pattern lab site. It's strongly recommended to run `grunt serve` to have BrowserSync spin up and serve the files to you. diff --git a/builder/lineage_hunter.js b/core/lib/lineage_hunter.js similarity index 100% rename from builder/lineage_hunter.js rename to core/lib/lineage_hunter.js diff --git a/builder/list_item_hunter.js b/core/lib/list_item_hunter.js similarity index 100% rename from builder/list_item_hunter.js rename to core/lib/list_item_hunter.js diff --git a/builder/media_hunter.js b/core/lib/media_hunter.js similarity index 100% rename from builder/media_hunter.js rename to core/lib/media_hunter.js diff --git a/builder/object_factory.js b/core/lib/object_factory.js similarity index 100% rename from builder/object_factory.js rename to core/lib/object_factory.js diff --git a/builder/parameter_hunter.js b/core/lib/parameter_hunter.js similarity index 100% rename from builder/parameter_hunter.js rename to core/lib/parameter_hunter.js diff --git a/builder/pattern_assembler.js b/core/lib/pattern_assembler.js similarity index 100% rename from builder/pattern_assembler.js rename to core/lib/pattern_assembler.js diff --git a/builder/pattern_exporter.js b/core/lib/pattern_exporter.js similarity index 100% rename from builder/pattern_exporter.js rename to core/lib/pattern_exporter.js diff --git a/builder/patternlab.js b/core/lib/patternlab.js similarity index 99% rename from builder/patternlab.js rename to core/lib/patternlab.js index b4705deaf..128d95009 100644 --- a/builder/patternlab.js +++ b/core/lib/patternlab.js @@ -22,7 +22,7 @@ var patternlab_engine = function (config) { patternlab = {}; patternlab.package = fs.readJSONSync('./package.json'); - patternlab.config = config || fs.readJSONSync(path.resolve(__dirname, '../config.json')); + patternlab.config = config || fs.readJSONSync(path.resolve(__dirname, '../../config.json')); var paths = patternlab.config.paths; diff --git a/builder/patternlab_grunt.js b/core/lib/patternlab_grunt.js similarity index 100% rename from builder/patternlab_grunt.js rename to core/lib/patternlab_grunt.js diff --git a/builder/patternlab_gulp.js b/core/lib/patternlab_gulp.js similarity index 100% rename from builder/patternlab_gulp.js rename to core/lib/patternlab_gulp.js diff --git a/builder/pseudopattern_hunter.js b/core/lib/pseudopattern_hunter.js similarity index 100% rename from builder/pseudopattern_hunter.js rename to core/lib/pseudopattern_hunter.js diff --git a/builder/style_modifier_hunter.js b/core/lib/style_modifier_hunter.js similarity index 100% rename from builder/style_modifier_hunter.js rename to core/lib/style_modifier_hunter.js diff --git a/gulpfile.js b/gulpfile.js index a00019f2d..85e157f15 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -27,7 +27,7 @@ function paths() { } //load patternlab-node tasks -gulp.loadTasks(__dirname + '/builder/patternlab_gulp.js'); +gulp.loadTasks(__dirname + '/core/lib/patternlab_gulp.js'); //clean patterns dir gulp.task('clean', function (cb) { @@ -38,25 +38,25 @@ gulp.task('clean', function (cb) { //build the banner gulp.task('banner', function () { return gulp.src([ - './builder/patternlab.js', - './builder/object_factory.js', - './builder/lineage_hunter.js', - './builder/media_hunter.js', - './builder/patternlab_grunt.js', - './builder/patternlab_gulp.js', - './builder/parameter_hunter.js', - './builder/pattern_exporter.js', - './builder/pattern_assembler.js', - './builder/pseudopattern_hunter.js', - './builder/list_item_hunter.js', - './builder/style_modifier_hunter.js' + './core/lib/patternlab.js', + './core/lib/object_factory.js', + './core/lib/lineage_hunter.js', + './core/lib/media_hunter.js', + './core/lib/patternlab_grunt.js', + './core/lib/patternlab_gulp.js', + './core/lib/parameter_hunter.js', + './core/lib/pattern_exporter.js', + './core/lib/pattern_assembler.js', + './core/lib/pseudopattern_hunter.js', + './core/lib/list_item_hunter.js', + './core/lib/style_modifier_hunter.js' ]) .pipe(strip_banner()) .pipe(header(banner, { pkg : pkg, today : new Date().getFullYear() } )) - .pipe(gulp.dest('./builder')); + .pipe(gulp.dest('./core/lib')); }); @@ -154,7 +154,7 @@ gulp.task('connect', ['lab'], function () { //lint gulp.task('eslint', function () { - return gulp.src(['./builder/*.js', '!node_modules/**']) + return gulp.src(['./core/lib/*.js', '!node_modules/**']) .pipe(eslint()) .pipe(eslint.format()) .pipe(eslint.failAfterError()); diff --git a/package.gulp.json b/package.gulp.json index 87a4d0044..3bb48a781 100644 --- a/package.gulp.json +++ b/package.gulp.json @@ -2,7 +2,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": "1.1.3", - "main": "./builder/patternlab.js", + "main": "./core/lib/patternlab.js", "dependencies": { "del": "^2.2.0", "diveSync": "^0.3.0", diff --git a/package.json b/package.json index a62664b52..68c810687 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,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": "1.1.3", - "main": "./builder/patternlab.js", + "main": "./core/lib/patternlab.js", "dependencies": { "diveSync": "^0.3.0", "fs-extra": "^0.26.2", diff --git a/test/lineage_hunter_tests.js b/test/lineage_hunter_tests.js index 0cd6a4aea..490c704ec 100644 --- a/test/lineage_hunter_tests.js +++ b/test/lineage_hunter_tests.js @@ -1,7 +1,7 @@ (function () { "use strict"; - var lh = require('../builder/lineage_hunter'); + var lh = require('../core/lib/lineage_hunter'); exports['lineage hunter '] = { 'find_lineage - finds lineage' : function(test){ diff --git a/test/list_item_hunter_tests.js b/test/list_item_hunter_tests.js index b2895b24d..eb3ade6cf 100644 --- a/test/list_item_hunter_tests.js +++ b/test/list_item_hunter_tests.js @@ -1,9 +1,9 @@ (function () { "use strict"; - var lih = require('../builder/list_item_hunter'); - var pa = require('../builder/pattern_assembler'); - var object_factory = require('../builder/object_factory'); + var lih = require('../core/lib/list_item_hunter'); + var pa = require('../core/lib/pattern_assembler'); + var object_factory = require('../core/lib/object_factory'); exports['list_item_hunter'] = { 'process_list_item_partials finds and outputs basic repeating blocks' : function(test){ diff --git a/test/media_hunter_tests.js b/test/media_hunter_tests.js index e41db5f88..05ce5926b 100644 --- a/test/media_hunter_tests.js +++ b/test/media_hunter_tests.js @@ -1,7 +1,7 @@ (function () { "use strict"; - var MediaHunter = require('../builder/media_hunter'); + var MediaHunter = require('../core/lib/media_hunter'); exports['media_query hunter basic support '] = { 'test media hunter finds query' : function(test){ diff --git a/test/object_factory_tests.js b/test/object_factory_tests.js index f58b2e664..c3e736690 100644 --- a/test/object_factory_tests.js +++ b/test/object_factory_tests.js @@ -1,7 +1,7 @@ (function () { "use strict"; - var of = require('../builder/object_factory'); + var of = require('../core/lib/object_factory'); exports['oPattern initialization'] = { 'test oPattern initializes correctly' : function(test){ diff --git a/test/parameter_hunter_tests.js b/test/parameter_hunter_tests.js index 3672a4a79..96d345792 100644 --- a/test/parameter_hunter_tests.js +++ b/test/parameter_hunter_tests.js @@ -1,7 +1,7 @@ (function () { "use strict"; - var ph = require('../builder/parameter_hunter'); + var ph = require('../core/lib/parameter_hunter'); //setup current pattern from what we would have during execution function currentPatternClosure() { diff --git a/test/pattern_assembler_tests.js b/test/pattern_assembler_tests.js index 5ba989a11..d1704895a 100644 --- a/test/pattern_assembler_tests.js +++ b/test/pattern_assembler_tests.js @@ -1,8 +1,8 @@ (function () { "use strict"; - var pa = require('../builder/pattern_assembler'); - var object_factory = require('../builder/object_factory'); + var pa = require('../core/lib/pattern_assembler'); + var object_factory = require('../core/lib/object_factory'); var path = require('path'); exports['pattern_assembler'] = { @@ -193,7 +193,7 @@ //prepare to diveSync var diveSync = require('diveSync'); var fs = require('fs-extra'); - var pa = require('../builder/pattern_assembler'); + var pa = require('../core/lib/pattern_assembler'); var pattern_assembler = new pa(); var patterns_dir = './test/files/_patterns'; var patternlab = {}; @@ -520,7 +520,7 @@ //arrange var diveSync = require('diveSync'); var fs = require('fs-extra'); - var pa = require('../builder/pattern_assembler'); + var pa = require('../core/lib/pattern_assembler'); var pattern_assembler = new pa(); var patterns_dir = './test/files/_patterns'; var patternlab = {}; @@ -571,7 +571,7 @@ }, 'setState - applies any patternState matching the pattern' : function(test){ //arrange - var pa = require('../builder/pattern_assembler'); + var pa = require('../core/lib/pattern_assembler'); var pattern_assembler = new pa(); var patternlab = {}; patternlab.config = {}; @@ -591,7 +591,7 @@ }, 'setState - does not apply any patternState if nothing matches the pattern' : function(test){ //arrange - var pa = require('../builder/pattern_assembler'); + var pa = require('../core/lib/pattern_assembler'); var pattern_assembler = new pa(); var patternlab = {}; patternlab.config = {}; @@ -613,7 +613,7 @@ //arrange var diveSync = require('diveSync'); var fs = require('fs-extra'); - var pa = require('../builder/pattern_assembler'); + var pa = require('../core/lib/pattern_assembler'); var pattern_assembler = new pa(); var patterns_dir = './test/files/_patterns/'; var patternlab = {}; diff --git a/test/pseudopattern_hunter_tests.js b/test/pseudopattern_hunter_tests.js index 9a0269482..3a97b773f 100644 --- a/test/pseudopattern_hunter_tests.js +++ b/test/pseudopattern_hunter_tests.js @@ -1,9 +1,9 @@ (function () { "use strict"; - var pha = require('../builder/pseudopattern_hunter'); - var pa = require('../builder/pattern_assembler'); - var object_factory = require('../builder/object_factory'); + var pha = require('../core/lib/pseudopattern_hunter'); + var pa = require('../core/lib/pattern_assembler'); + var object_factory = require('../core/lib/object_factory'); exports['pseudopattern_hunter'] = { 'pseudpattern found and added as a pattern' : function(test){ diff --git a/test/style_modifier_hunter_tests.js b/test/style_modifier_hunter_tests.js index 9a13a75e4..7a3562ad0 100644 --- a/test/style_modifier_hunter_tests.js +++ b/test/style_modifier_hunter_tests.js @@ -1,7 +1,7 @@ (function () { "use strict"; - var smh = require('../builder/style_modifier_hunter'); + var smh = require('../core/lib/style_modifier_hunter'); exports['consume_style_modifier'] = { 'uses the partial stylemodifer to modify the patterns extendedTemplate' : function(test){ From b5622afe7b1968eda32cc2b0ae225a23f4daad23 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Wed, 2 Mar 2016 10:06:59 -0600 Subject: [PATCH 25/37] move source/_patternlab-files/partials to core/templates move source/_patternlab-files/pattern-header-footer to core/source/_meta updated config entries #133 --- config.json | 2 +- core/lib/patternlab.js | 20 +++--- .../README => core/source/_meta/README.txt | 0 .../source/_meta}/footer.html | 0 .../source/_meta}/header.html | 0 .../README => core/templates/README.txt | 0 .../templates}/index.mustache | 0 core/templates/partials/ishControls.mustache | 64 +++++++++++++++++++ core/templates/partials/patternNav.mustache | 17 +++++ core/templates/partials/patternPaths.mustache | 3 + core/templates/partials/viewAllPaths.mustache | 3 + .../templates}/styleguide.mustache | 0 .../templates}/viewall.mustache | 0 test/pattern_assembler_tests.js | 12 ++-- 14 files changed, 104 insertions(+), 17 deletions(-) rename source/_patternlab-files/pattern-header-footer/README => core/source/_meta/README.txt (100%) rename {source/_patternlab-files/pattern-header-footer => core/source/_meta}/footer.html (100%) rename {source/_patternlab-files/pattern-header-footer => core/source/_meta}/header.html (100%) rename source/_patternlab-files/README => core/templates/README.txt (100%) rename {source/_patternlab-files => core/templates}/index.mustache (100%) create mode 100644 core/templates/partials/ishControls.mustache create mode 100644 core/templates/partials/patternNav.mustache create mode 100644 core/templates/partials/patternPaths.mustache create mode 100644 core/templates/partials/viewAllPaths.mustache rename {source/_patternlab-files => core/templates}/styleguide.mustache (100%) rename {source/_patternlab-files => core/templates}/viewall.mustache (100%) diff --git a/config.json b/config.json index 187e8955d..d9aec61cb 100644 --- a/config.json +++ b/config.json @@ -5,7 +5,7 @@ "patterns" : "./source/_patterns/", "data" : "./source/_data/", "styleguide" : "./core/styleguide/", - "patternlabFiles" : "./source/_patternlab-files/", + "patternlabFiles" : "./core/", "js" : "./source/js", "images" : "./source/images", "fonts" : "./source/fonts", diff --git a/core/lib/patternlab.js b/core/lib/patternlab.js index 128d95009..f4fb81a06 100644 --- a/core/lib/patternlab.js +++ b/core/lib/patternlab.js @@ -57,8 +57,8 @@ var patternlab_engine = function (config) { function buildPatterns(deletePatternDir) { patternlab.data = fs.readJSONSync(path.resolve(paths.source.data, 'data.json')); patternlab.listitems = fs.readJSONSync(path.resolve(paths.source.data, 'listitems.json')); - patternlab.header = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'pattern-header-footer/header.html'), 'utf8'); - patternlab.footer = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'pattern-header-footer/footer.html'), 'utf8'); + patternlab.header = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'source/_meta/header.html'), 'utf8'); + patternlab.footer = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'source/_meta/footer.html'), 'utf8'); patternlab.patterns = []; patternlab.partials = {}; patternlab.data.link = {}; @@ -212,7 +212,7 @@ var patternlab_engine = function (config) { } //build the styleguide - var styleguideTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'styleguide.mustache'), 'utf8'), + var styleguideTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'templates/styleguide.mustache'), 'utf8'), styleguideHtml = pattern_assembler.renderPattern(styleguideTemplate, {partials: styleguidePatterns}); fs.outputFileSync(path.resolve(paths.public.styleguide, 'html/styleguide.html'), styleguideHtml); @@ -255,7 +255,7 @@ var patternlab_engine = function (config) { } } - var viewAllTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'viewall.mustache'), 'utf8'); + var viewAllTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'templates/viewall.mustache'), 'utf8'); var viewAllHtml = pattern_assembler.renderPattern(viewAllTemplate, {partials: viewAllPatterns, patternPartial: patternPartial}); fs.outputFileSync(paths.public.patterns + pattern.subdir.slice(0, pattern.subdir.indexOf(pattern.patternGroup) + pattern.patternGroup.length) + '/index.html', viewAllHtml); } @@ -282,14 +282,14 @@ var patternlab_engine = function (config) { } } - var viewAllTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'viewall.mustache'), 'utf8'); + var viewAllTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'templates/viewall.mustache'), 'utf8'); var viewAllHtml = pattern_assembler.renderPattern(viewAllTemplate, {partials: viewAllPatterns, patternPartial: patternPartial}); fs.outputFileSync(paths.public.patterns + pattern.flatPatternPath + '/index.html', viewAllHtml); } } //build the patternlab website - var patternlabSiteTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'index.mustache'), 'utf8'); + var patternlabSiteTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'templates/index.mustache'), 'utf8'); //loop through all patterns.to build the navigation //todo: refactor this someday @@ -462,20 +462,20 @@ var patternlab_engine = function (config) { //the patternlab site requires a lot of partials to be rendered. //patternNav - var patternNavTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'partials/patternNav.mustache'), 'utf8'); + var patternNavTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'templates/partials/patternNav.mustache'), 'utf8'); var patternNavPartialHtml = pattern_assembler.renderPattern(patternNavTemplate, patternlab); //ishControls - var ishControlsTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'partials/ishControls.mustache'), 'utf8'); + var ishControlsTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'templates/partials/ishControls.mustache'), 'utf8'); patternlab.config.mqs = patternlab.mediaQueries; var ishControlsPartialHtml = pattern_assembler.renderPattern(ishControlsTemplate, patternlab.config); //patternPaths - var patternPathsTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'partials/patternPaths.mustache'), 'utf8'); + var patternPathsTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'templates/partials/patternPaths.mustache'), 'utf8'); var patternPathsPartialHtml = pattern_assembler.renderPattern(patternPathsTemplate, {'patternPaths': JSON.stringify(patternlab.patternPaths)}); //viewAllPaths - var viewAllPathsTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'partials/viewAllPaths.mustache'), 'utf8'); + var viewAllPathsTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'templates/partials/viewAllPaths.mustache'), 'utf8'); var viewAllPathsPartialHtml = pattern_assembler.renderPattern(viewAllPathsTemplate, {'viewallpaths': JSON.stringify(patternlab.viewAllPaths)}); //render the patternlab template, with all partials diff --git a/source/_patternlab-files/pattern-header-footer/README b/core/source/_meta/README.txt similarity index 100% rename from source/_patternlab-files/pattern-header-footer/README rename to core/source/_meta/README.txt diff --git a/source/_patternlab-files/pattern-header-footer/footer.html b/core/source/_meta/footer.html similarity index 100% rename from source/_patternlab-files/pattern-header-footer/footer.html rename to core/source/_meta/footer.html diff --git a/source/_patternlab-files/pattern-header-footer/header.html b/core/source/_meta/header.html similarity index 100% rename from source/_patternlab-files/pattern-header-footer/header.html rename to core/source/_meta/header.html diff --git a/source/_patternlab-files/README b/core/templates/README.txt similarity index 100% rename from source/_patternlab-files/README rename to core/templates/README.txt diff --git a/source/_patternlab-files/index.mustache b/core/templates/index.mustache similarity index 100% rename from source/_patternlab-files/index.mustache rename to core/templates/index.mustache diff --git a/core/templates/partials/ishControls.mustache b/core/templates/partials/ishControls.mustache new file mode 100644 index 000000000..6c0a70b68 --- /dev/null +++ b/core/templates/partials/ishControls.mustache @@ -0,0 +1,64 @@ + +
+
+
    +
  • +
    +
    + Size px / + em +
    +
    +
      + {{# ishControlsVisible.s }}
    • S
    • {{/ ishControlsVisible.s }} + {{# ishControlsVisible.m }}
    • M
    • {{/ ishControlsVisible.m }} + {{# ishControlsVisible.l }}
    • L
    • {{/ ishControlsVisible.l }} + {{# ishControlsVisible.full }}
    • Full
    • {{/ ishControlsVisible.full }} + {{# ishControlsVisible.random }}
    • Random
    • {{/ ishControlsVisible.random }} + {{# ishControlsVisible.disco }}
    • Disco
    • {{/ ishControlsVisible.disco }} + {{# ishControlsVisible.hay }}
    • Hay!
    • {{/ ishControlsVisible.hay }} +
    +
  • + {{# ishControlsVisible.mqs }} +
  • + MQ +
      + {{# mqs }} +
    • {{ . }}
    • + {{/ mqs }} +
    +
  • + {{/ ishControlsVisible.mqs }} + {{# ishControlsVisible.find }} +
  • + Search Patterns +
      +
    • +
    +
  • + {{/ ishControlsVisible.find }} + {{# ishControlsVisible.views-all }} +
  • + View +
      + {{# ishControlsVisible.views-annotations }}
    • Annotations
    • {{/ ishControlsVisible.views-annotations }} + {{# ishControlsVisible.views-code }}
    • Code
    • {{/ ishControlsVisible.views-code }} + {{# ishControlsVisible.views-new }}
    • Open in new window
    • {{/ ishControlsVisible.views-new }} +
    +
  • + {{/ ishControlsVisible.views-all }} + {{# ishControlsVisible.tools-all }} +
  • + Tools +
      + {{# ishControlsVisible.tools-sync }}
    • BrowserSync UI
    • {{/ ishControlsVisible.tools-sync }} + {{# ishControlsVisible.tools-shortcuts }}
    • Keyboard Shortcuts{{/ ishControlsVisible.tools-shortcuts }} + {{# ishControlsVisible.tools-docs }}
    • Pattern Lab Docs{{/ ishControlsVisible.tools-docs }} +
    +
  • + {{/ ishControlsVisible.tools-all }} +
+ +
+
+ diff --git a/core/templates/partials/patternNav.mustache b/core/templates/partials/patternNav.mustache new file mode 100644 index 000000000..86933aa55 --- /dev/null +++ b/core/templates/partials/patternNav.mustache @@ -0,0 +1,17 @@ +
    + {{# buckets }} +
  1. {{ bucketNameUC }}
      + {{# navItems }} +
    1. {{ sectionNameUC }}
        + {{# navSubItems }} +
      1. {{ patternName }}
      2. + {{/ navSubItems }} +
    2. + {{/ navItems }} + {{# patternItems }} +
    3. {{ patternName }}
    4. + {{/ patternItems }} +
  2. + {{/ buckets }} +
  3. All
  4. +
diff --git a/core/templates/partials/patternPaths.mustache b/core/templates/partials/patternPaths.mustache new file mode 100644 index 000000000..798744030 --- /dev/null +++ b/core/templates/partials/patternPaths.mustache @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/core/templates/partials/viewAllPaths.mustache b/core/templates/partials/viewAllPaths.mustache new file mode 100644 index 000000000..b0e044d97 --- /dev/null +++ b/core/templates/partials/viewAllPaths.mustache @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/source/_patternlab-files/styleguide.mustache b/core/templates/styleguide.mustache similarity index 100% rename from source/_patternlab-files/styleguide.mustache rename to core/templates/styleguide.mustache diff --git a/source/_patternlab-files/viewall.mustache b/core/templates/viewall.mustache similarity index 100% rename from source/_patternlab-files/viewall.mustache rename to core/templates/viewall.mustache diff --git a/test/pattern_assembler_tests.js b/test/pattern_assembler_tests.js index d1704895a..f28ea7c1c 100644 --- a/test/pattern_assembler_tests.js +++ b/test/pattern_assembler_tests.js @@ -202,8 +202,8 @@ patternlab.data = fs.readJSONSync(path.resolve(patternlab.config.paths.source.data, 'data.json')); patternlab.listitems = fs.readJSONSync(path.resolve(patternlab.config.paths.source.data, 'listitems.json')); - patternlab.header = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'pattern-header-footer/header.html'), 'utf8'); - patternlab.footer = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'pattern-header-footer/footer.html'), 'utf8'); + patternlab.header = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'source/_meta/header.html'), 'utf8'); + patternlab.footer = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'source/_meta/footer.html'), 'utf8'); patternlab.patterns = []; patternlab.data.link = {}; patternlab.partials = {}; @@ -530,8 +530,8 @@ patternlab.data = fs.readJSONSync(path.resolve(patternlab.config.paths.source.data, 'data.json')); patternlab.listitems = fs.readJSONSync(path.resolve(patternlab.config.paths.source.data, 'listitems.json')); - patternlab.header = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'pattern-header-footer/header.html'), 'utf8'); - patternlab.footer = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'pattern-header-footer/footer.html'), 'utf8'); + patternlab.header = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'source/_meta/header.html'), 'utf8'); + patternlab.footer = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'source/_meta/footer.html'), 'utf8'); patternlab.patterns = []; patternlab.data.link = {}; patternlab.partials = {}; @@ -622,8 +622,8 @@ patternlab.config.paths.source.patterns = patterns_dir; patternlab.data = fs.readJSONSync(path.resolve(patternlab.config.paths.source.data, 'data.json')); patternlab.listitems = fs.readJSONSync(path.resolve(patternlab.config.paths.source.data, 'listitems.json')); - patternlab.header = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'pattern-header-footer/header.html'), 'utf8'); - patternlab.footer = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'pattern-header-footer/footer.html'), 'utf8'); + patternlab.header = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'source/_meta/header.html'), 'utf8'); + patternlab.footer = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'source/_meta/footer.html'), 'utf8'); patternlab.patterns = []; patternlab.data.link = {}; patternlab.partials = {}; From 05a922c69a8c4f43fab8ad02cc88a836f70cf182 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Fri, 4 Mar 2016 00:10:39 -0600 Subject: [PATCH 26/37] #133 add user defined atoms-_head and atoms-_foot pattern move patterns to account for new dir move footer and header to proper place inject header and footer into styleguide, index, and pattern html --- core/lib/patternlab.js | 61 +++++++++++++++--- core/source/_meta/footer.html | 34 ---------- core/source/_meta/header.html | 35 ---------- core/templates/index.mustache | 12 +++- .../pattern-header-footer}/README.txt | 0 .../pattern-header-footer/footer-pattern.html | 19 ++++++ .../pattern-header-footer/footer.html | 6 ++ .../pattern-header-footer/header.html | 9 +++ core/templates/styleguide.mustache | 20 ------ core/templates/viewall.mustache | 19 ------ .../partials/ishControls.mustache | 64 ------------------- .../partials/patternNav.mustache | 17 ----- .../partials/patternPaths.mustache | 3 - .../partials/viewAllPaths.mustache | 3 - .../00-atoms/00-meta/_00-head.mustache | 15 +++++ .../00-atoms/00-meta/_01-foot.mustache | 7 ++ .../00-colors.mustache | 0 .../01-fonts.mustache | 0 .../02-animations.mustache | 0 .../03-visibility.mustache | 0 .../{01-text => 02-text}/00-headings.mustache | 0 .../01-subheadings.mustache | 0 .../02-headings-with-links.mustache | 0 .../03-paragraph.mustache | 0 .../04-blockquote.mustache | 0 .../05-inline-elements.mustache | 0 .../{01-text => 02-text}/06-time.mustache | 0 .../07-preformatted-text.mustache | 0 .../08-emphasis-colors.mustache | 0 .../{01-text => 02-text}/09-hr.mustache | 0 .../{01-text => 02-text}/10-caption.mustache | 0 .../00-unordered.mustache | 0 .../01-ordered.mustache | 0 .../02-definition.mustache | 0 .../{03-images => 04-images}/00-logo.mustache | 0 .../01-landscape-4x3.mustache | 0 .../02-landscape-16x9.mustache | 0 .../03-square.mustache | 0 .../04-avatar.mustache | 0 .../05-icons.mustache | 0 .../06-loading-icon.mustache | 0 .../07-favicon.mustache | 0 .../00-text-fields.mustache | 0 .../01-select-menu.mustache | 0 .../02-checkbox.mustache | 0 .../03-radio-buttons.mustache | 0 .../04-html5-inputs.mustache | 0 .../00-buttons.mustache | 0 .../00-table.mustache | 0 .../{07-media => 08-media}/00-video.mustache | 0 .../{07-media => 08-media}/01-audio.mustache | 0 test/pattern_assembler_tests.js | 12 ++-- 52 files changed, 125 insertions(+), 211 deletions(-) delete mode 100644 core/source/_meta/footer.html delete mode 100644 core/source/_meta/header.html rename core/{source/_meta => templates/pattern-header-footer}/README.txt (100%) create mode 100644 core/templates/pattern-header-footer/footer-pattern.html create mode 100644 core/templates/pattern-header-footer/footer.html create mode 100644 core/templates/pattern-header-footer/header.html delete mode 100644 source/_patternlab-files/partials/ishControls.mustache delete mode 100644 source/_patternlab-files/partials/patternNav.mustache delete mode 100644 source/_patternlab-files/partials/patternPaths.mustache delete mode 100644 source/_patternlab-files/partials/viewAllPaths.mustache create mode 100644 source/_patterns/00-atoms/00-meta/_00-head.mustache create mode 100644 source/_patterns/00-atoms/00-meta/_01-foot.mustache rename source/_patterns/00-atoms/{00-global => 01-global}/00-colors.mustache (100%) rename source/_patterns/00-atoms/{00-global => 01-global}/01-fonts.mustache (100%) rename source/_patterns/00-atoms/{00-global => 01-global}/02-animations.mustache (100%) rename source/_patterns/00-atoms/{00-global => 01-global}/03-visibility.mustache (100%) rename source/_patterns/00-atoms/{01-text => 02-text}/00-headings.mustache (100%) rename source/_patterns/00-atoms/{01-text => 02-text}/01-subheadings.mustache (100%) rename source/_patterns/00-atoms/{01-text => 02-text}/02-headings-with-links.mustache (100%) rename source/_patterns/00-atoms/{01-text => 02-text}/03-paragraph.mustache (100%) rename source/_patterns/00-atoms/{01-text => 02-text}/04-blockquote.mustache (100%) rename source/_patterns/00-atoms/{01-text => 02-text}/05-inline-elements.mustache (100%) rename source/_patterns/00-atoms/{01-text => 02-text}/06-time.mustache (100%) rename source/_patterns/00-atoms/{01-text => 02-text}/07-preformatted-text.mustache (100%) rename source/_patterns/00-atoms/{01-text => 02-text}/08-emphasis-colors.mustache (100%) rename source/_patterns/00-atoms/{01-text => 02-text}/09-hr.mustache (100%) rename source/_patterns/00-atoms/{01-text => 02-text}/10-caption.mustache (100%) rename source/_patterns/00-atoms/{02-lists => 03-lists}/00-unordered.mustache (100%) rename source/_patterns/00-atoms/{02-lists => 03-lists}/01-ordered.mustache (100%) rename source/_patterns/00-atoms/{02-lists => 03-lists}/02-definition.mustache (100%) rename source/_patterns/00-atoms/{03-images => 04-images}/00-logo.mustache (100%) rename source/_patterns/00-atoms/{03-images => 04-images}/01-landscape-4x3.mustache (100%) rename source/_patterns/00-atoms/{03-images => 04-images}/02-landscape-16x9.mustache (100%) rename source/_patterns/00-atoms/{03-images => 04-images}/03-square.mustache (100%) rename source/_patterns/00-atoms/{03-images => 04-images}/04-avatar.mustache (100%) rename source/_patterns/00-atoms/{03-images => 04-images}/05-icons.mustache (100%) rename source/_patterns/00-atoms/{03-images => 04-images}/06-loading-icon.mustache (100%) rename source/_patterns/00-atoms/{03-images => 04-images}/07-favicon.mustache (100%) rename source/_patterns/00-atoms/{04-forms => 05-forms}/00-text-fields.mustache (100%) rename source/_patterns/00-atoms/{04-forms => 05-forms}/01-select-menu.mustache (100%) rename source/_patterns/00-atoms/{04-forms => 05-forms}/02-checkbox.mustache (100%) rename source/_patterns/00-atoms/{04-forms => 05-forms}/03-radio-buttons.mustache (100%) rename source/_patterns/00-atoms/{04-forms => 05-forms}/04-html5-inputs.mustache (100%) rename source/_patterns/00-atoms/{05-buttons => 06-buttons}/00-buttons.mustache (100%) rename source/_patterns/00-atoms/{06-tables => 07-tables}/00-table.mustache (100%) rename source/_patterns/00-atoms/{07-media => 08-media}/00-video.mustache (100%) rename source/_patterns/00-atoms/{07-media => 08-media}/01-audio.mustache (100%) diff --git a/core/lib/patternlab.js b/core/lib/patternlab.js index f4fb81a06..dc11e4ecd 100644 --- a/core/lib/patternlab.js +++ b/core/lib/patternlab.js @@ -57,8 +57,9 @@ var patternlab_engine = function (config) { function buildPatterns(deletePatternDir) { patternlab.data = fs.readJSONSync(path.resolve(paths.source.data, 'data.json')); patternlab.listitems = fs.readJSONSync(path.resolve(paths.source.data, 'listitems.json')); - patternlab.header = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'source/_meta/header.html'), 'utf8'); - patternlab.footer = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'source/_meta/footer.html'), 'utf8'); + patternlab.header = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'templates/pattern-header-footer/header.html'), 'utf8'); + patternlab.footerPattern = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'templates/pattern-header-footer/footer-pattern.html'), 'utf8'); + patternlab.footer = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'templates/pattern-header-footer/footer.html'), 'utf8'); patternlab.patterns = []; patternlab.partials = {}; patternlab.data.link = {}; @@ -116,6 +117,25 @@ var patternlab_engine = function (config) { pattern_assembler.process_pattern_recursive(path.resolve(file), patternlab); }); + //set user defined head and foot if they exist + try { + patternlab.userHead = pattern_assembler.get_pattern_by_key('atoms-head', patternlab); + } + catch(ex) { + if (patternlab.config.debug) { + console.log(ex); + console.log('Could not find optional user-defined header, atoms-head pattern. It was likely deleted.'); + } + } + try { + patternlab.userFoot = pattern_assembler.get_pattern_by_key('atoms-foot', patternlab); + } + catch(ex) { + if (patternlab.config.debug) { + console.log(ex); + console.log('Could not find optional user-defined footer, atoms-foot pattern. It was likely deleted.'); + } + } //now that all the main patterns are known, look for any links that might be within data and expand them //we need to do this before expanding patterns & partials into extendedTemplates, otherwise we could lose the data -> partial reference @@ -126,21 +146,40 @@ var patternlab_engine = function (config) { fs.emptyDirSync(paths.public.patterns); } + //set pattern-specific header if necessary + var head; + if (patternlab.userHead) { + head = patternlab.userHead.extendedTemplate.replace('{% pattern-lab-head %}', patternlab.header); + } else { + head = patternlab.header; + } + //render all patterns last, so lineageR works patternlab.patterns.forEach(function (pattern) { + pattern.header = head; + //render the pattern, but first consolidate any data we may have var allData = JSON.parse(JSON.stringify(patternlab.data)); allData = pattern_assembler.merge_data(allData, pattern.jsonFileData); + //render the pattern-specific header + var headHtml = pattern_assembler.renderPattern(pattern.header, allData); + //render the extendedTemplate with all data pattern.patternPartial = pattern_assembler.renderPattern(pattern.extendedTemplate, allData); - //add footer info before writing - var patternFooter = pattern_assembler.renderPattern(patternlab.footer, pattern); + //set the pattern-specific footer if necessary + if (patternlab.userFoot) { + console.log('found custom userFoot') + var userFooter = patternlab.userFoot.extendedTemplate.replace('{% pattern-lab-foot %}', patternlab.footerPattern + patternlab.footer); + pattern.footer = pattern_assembler.renderPattern(userFooter, pattern); + } else { + pattern.footer = pattern_assembler.renderPattern(patternlab.footerPattern, pattern); + } //write the compiled template to the public patterns directory - fs.outputFileSync(paths.public.patterns + pattern.patternLink, patternlab.header + pattern.patternPartial + patternFooter); + fs.outputFileSync(paths.public.patterns + pattern.patternLink, headHtml + pattern.patternPartial + pattern.footer); //write the mustache file too fs.outputFileSync(paths.public.patterns + pattern.patternLink.replace('.html', '.mustache'), entity_encoder.encode(pattern.template)); @@ -211,11 +250,17 @@ var patternlab_engine = function (config) { styleguidePatterns = patternlab.patterns; } + //get the main page head and foot + var mainPageHead = patternlab.userHead.extendedTemplate.replace('{% pattern-lab-head %}', patternlab.header); + var mainPageHeadHtml = pattern_assembler.renderPattern(mainPageHead, patternlab.data); + var mainPageFoot = patternlab.userFoot.extendedTemplate.replace('{% pattern-lab-foot %}', patternlab.footer); + var mainPageFootHtml = pattern_assembler.renderPattern(mainPageFoot, patternlab.data); + //build the styleguide var styleguideTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'templates/styleguide.mustache'), 'utf8'), styleguideHtml = pattern_assembler.renderPattern(styleguideTemplate, {partials: styleguidePatterns}); - fs.outputFileSync(path.resolve(paths.public.styleguide, 'html/styleguide.html'), styleguideHtml); + fs.outputFileSync(path.resolve(paths.public.styleguide, 'html/styleguide.html'), mainPageHeadHtml + styleguideHtml + mainPageFootHtml); //build the viewall pages var prevSubdir = '', @@ -257,7 +302,7 @@ var patternlab_engine = function (config) { var viewAllTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'templates/viewall.mustache'), 'utf8'); var viewAllHtml = pattern_assembler.renderPattern(viewAllTemplate, {partials: viewAllPatterns, patternPartial: patternPartial}); - fs.outputFileSync(paths.public.patterns + pattern.subdir.slice(0, pattern.subdir.indexOf(pattern.patternGroup) + pattern.patternGroup.length) + '/index.html', viewAllHtml); + fs.outputFileSync(paths.public.patterns + pattern.subdir.slice(0, pattern.subdir.indexOf(pattern.patternGroup) + pattern.patternGroup.length) + '/index.html', mainPageHead + viewAllHtml + mainPageFoot); } // create the view all for the subsection @@ -284,7 +329,7 @@ var patternlab_engine = function (config) { var viewAllTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'templates/viewall.mustache'), 'utf8'); var viewAllHtml = pattern_assembler.renderPattern(viewAllTemplate, {partials: viewAllPatterns, patternPartial: patternPartial}); - fs.outputFileSync(paths.public.patterns + pattern.flatPatternPath + '/index.html', viewAllHtml); + fs.outputFileSync(paths.public.patterns + pattern.flatPatternPath + '/index.html', mainPageHeadHtml + viewAllHtml + mainPageFootHtml); } } diff --git a/core/source/_meta/footer.html b/core/source/_meta/footer.html deleted file mode 100644 index 2234cfd9f..000000000 --- a/core/source/_meta/footer.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/core/source/_meta/header.html b/core/source/_meta/header.html deleted file mode 100644 index 1d0019a03..000000000 --- a/core/source/_meta/header.html +++ /dev/null @@ -1,35 +0,0 @@ - - - - Pattern Lab Pattern - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/core/templates/index.mustache b/core/templates/index.mustache index 1688121dd..912839552 100644 --- a/core/templates/index.mustache +++ b/core/templates/index.mustache @@ -3,6 +3,14 @@ Pattern Lab + + + + + + + + @@ -21,7 +29,7 @@
- +
@@ -91,4 +99,4 @@ - \ No newline at end of file + diff --git a/core/source/_meta/README.txt b/core/templates/pattern-header-footer/README.txt similarity index 100% rename from core/source/_meta/README.txt rename to core/templates/pattern-header-footer/README.txt diff --git a/core/templates/pattern-header-footer/footer-pattern.html b/core/templates/pattern-header-footer/footer-pattern.html new file mode 100644 index 000000000..20caf0102 --- /dev/null +++ b/core/templates/pattern-header-footer/footer-pattern.html @@ -0,0 +1,19 @@ + + + + + + + diff --git a/core/templates/pattern-header-footer/footer.html b/core/templates/pattern-header-footer/footer.html new file mode 100644 index 000000000..9bdd04a87 --- /dev/null +++ b/core/templates/pattern-header-footer/footer.html @@ -0,0 +1,6 @@ + + + + + + diff --git a/core/templates/pattern-header-footer/header.html b/core/templates/pattern-header-footer/header.html new file mode 100644 index 000000000..603079c27 --- /dev/null +++ b/core/templates/pattern-header-footer/header.html @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/core/templates/styleguide.mustache b/core/templates/styleguide.mustache index fe39a3816..b9a63debe 100644 --- a/core/templates/styleguide.mustache +++ b/core/templates/styleguide.mustache @@ -1,15 +1,3 @@ - - - - Pattern Lab Style Guide - - - - - - - -
@@ -58,11 +46,3 @@ var lineage = ""; var baseurl = "{{{baseurl}}}"; - - - - - - - - diff --git a/core/templates/viewall.mustache b/core/templates/viewall.mustache index 87b345ae2..e22a33833 100644 --- a/core/templates/viewall.mustache +++ b/core/templates/viewall.mustache @@ -1,14 +1,3 @@ - - - - Pattern Lab Sub-type Style Guide - - - - - - -
@@ -58,11 +47,3 @@ var lineage = ""; var baseurl = "{{{baseurl}}}"; - - - - - - - - diff --git a/source/_patternlab-files/partials/ishControls.mustache b/source/_patternlab-files/partials/ishControls.mustache deleted file mode 100644 index 6c0a70b68..000000000 --- a/source/_patternlab-files/partials/ishControls.mustache +++ /dev/null @@ -1,64 +0,0 @@ - -
-
-
    -
  • -
    -
    - Size px / - em -
    -
    -
      - {{# ishControlsVisible.s }}
    • S
    • {{/ ishControlsVisible.s }} - {{# ishControlsVisible.m }}
    • M
    • {{/ ishControlsVisible.m }} - {{# ishControlsVisible.l }}
    • L
    • {{/ ishControlsVisible.l }} - {{# ishControlsVisible.full }}
    • Full
    • {{/ ishControlsVisible.full }} - {{# ishControlsVisible.random }}
    • Random
    • {{/ ishControlsVisible.random }} - {{# ishControlsVisible.disco }}
    • Disco
    • {{/ ishControlsVisible.disco }} - {{# ishControlsVisible.hay }}
    • Hay!
    • {{/ ishControlsVisible.hay }} -
    -
  • - {{# ishControlsVisible.mqs }} -
  • - MQ -
      - {{# mqs }} -
    • {{ . }}
    • - {{/ mqs }} -
    -
  • - {{/ ishControlsVisible.mqs }} - {{# ishControlsVisible.find }} -
  • - Search Patterns -
      -
    • -
    -
  • - {{/ ishControlsVisible.find }} - {{# ishControlsVisible.views-all }} -
  • - View -
      - {{# ishControlsVisible.views-annotations }}
    • Annotations
    • {{/ ishControlsVisible.views-annotations }} - {{# ishControlsVisible.views-code }}
    • Code
    • {{/ ishControlsVisible.views-code }} - {{# ishControlsVisible.views-new }}
    • Open in new window
    • {{/ ishControlsVisible.views-new }} -
    -
  • - {{/ ishControlsVisible.views-all }} - {{# ishControlsVisible.tools-all }} -
  • - Tools -
      - {{# ishControlsVisible.tools-sync }}
    • BrowserSync UI
    • {{/ ishControlsVisible.tools-sync }} - {{# ishControlsVisible.tools-shortcuts }}
    • Keyboard Shortcuts{{/ ishControlsVisible.tools-shortcuts }} - {{# ishControlsVisible.tools-docs }}
    • Pattern Lab Docs{{/ ishControlsVisible.tools-docs }} -
    -
  • - {{/ ishControlsVisible.tools-all }} -
- -
-
- diff --git a/source/_patternlab-files/partials/patternNav.mustache b/source/_patternlab-files/partials/patternNav.mustache deleted file mode 100644 index 86933aa55..000000000 --- a/source/_patternlab-files/partials/patternNav.mustache +++ /dev/null @@ -1,17 +0,0 @@ -
    - {{# buckets }} -
  1. {{ bucketNameUC }}
      - {{# navItems }} -
    1. {{ sectionNameUC }}
        - {{# navSubItems }} -
      1. {{ patternName }}
      2. - {{/ navSubItems }} -
    2. - {{/ navItems }} - {{# patternItems }} -
    3. {{ patternName }}
    4. - {{/ patternItems }} -
  2. - {{/ buckets }} -
  3. All
  4. -
diff --git a/source/_patternlab-files/partials/patternPaths.mustache b/source/_patternlab-files/partials/patternPaths.mustache deleted file mode 100644 index 798744030..000000000 --- a/source/_patternlab-files/partials/patternPaths.mustache +++ /dev/null @@ -1,3 +0,0 @@ - \ No newline at end of file diff --git a/source/_patternlab-files/partials/viewAllPaths.mustache b/source/_patternlab-files/partials/viewAllPaths.mustache deleted file mode 100644 index b0e044d97..000000000 --- a/source/_patternlab-files/partials/viewAllPaths.mustache +++ /dev/null @@ -1,3 +0,0 @@ - \ No newline at end of file diff --git a/source/_patterns/00-atoms/00-meta/_00-head.mustache b/source/_patterns/00-atoms/00-meta/_00-head.mustache new file mode 100644 index 000000000..a751d06a2 --- /dev/null +++ b/source/_patterns/00-atoms/00-meta/_00-head.mustache @@ -0,0 +1,15 @@ + + + + {{ title }} + + + + + + + {% pattern-lab-head %} + + + + diff --git a/source/_patterns/00-atoms/00-meta/_01-foot.mustache b/source/_patterns/00-atoms/00-meta/_01-foot.mustache new file mode 100644 index 000000000..10e69fba6 --- /dev/null +++ b/source/_patterns/00-atoms/00-meta/_01-foot.mustache @@ -0,0 +1,7 @@ + + +{% pattern-lab-foot %} + + + + diff --git a/source/_patterns/00-atoms/00-global/00-colors.mustache b/source/_patterns/00-atoms/01-global/00-colors.mustache similarity index 100% rename from source/_patterns/00-atoms/00-global/00-colors.mustache rename to source/_patterns/00-atoms/01-global/00-colors.mustache diff --git a/source/_patterns/00-atoms/00-global/01-fonts.mustache b/source/_patterns/00-atoms/01-global/01-fonts.mustache similarity index 100% rename from source/_patterns/00-atoms/00-global/01-fonts.mustache rename to source/_patterns/00-atoms/01-global/01-fonts.mustache diff --git a/source/_patterns/00-atoms/00-global/02-animations.mustache b/source/_patterns/00-atoms/01-global/02-animations.mustache similarity index 100% rename from source/_patterns/00-atoms/00-global/02-animations.mustache rename to source/_patterns/00-atoms/01-global/02-animations.mustache diff --git a/source/_patterns/00-atoms/00-global/03-visibility.mustache b/source/_patterns/00-atoms/01-global/03-visibility.mustache similarity index 100% rename from source/_patterns/00-atoms/00-global/03-visibility.mustache rename to source/_patterns/00-atoms/01-global/03-visibility.mustache diff --git a/source/_patterns/00-atoms/01-text/00-headings.mustache b/source/_patterns/00-atoms/02-text/00-headings.mustache similarity index 100% rename from source/_patterns/00-atoms/01-text/00-headings.mustache rename to source/_patterns/00-atoms/02-text/00-headings.mustache diff --git a/source/_patterns/00-atoms/01-text/01-subheadings.mustache b/source/_patterns/00-atoms/02-text/01-subheadings.mustache similarity index 100% rename from source/_patterns/00-atoms/01-text/01-subheadings.mustache rename to source/_patterns/00-atoms/02-text/01-subheadings.mustache diff --git a/source/_patterns/00-atoms/01-text/02-headings-with-links.mustache b/source/_patterns/00-atoms/02-text/02-headings-with-links.mustache similarity index 100% rename from source/_patterns/00-atoms/01-text/02-headings-with-links.mustache rename to source/_patterns/00-atoms/02-text/02-headings-with-links.mustache diff --git a/source/_patterns/00-atoms/01-text/03-paragraph.mustache b/source/_patterns/00-atoms/02-text/03-paragraph.mustache similarity index 100% rename from source/_patterns/00-atoms/01-text/03-paragraph.mustache rename to source/_patterns/00-atoms/02-text/03-paragraph.mustache diff --git a/source/_patterns/00-atoms/01-text/04-blockquote.mustache b/source/_patterns/00-atoms/02-text/04-blockquote.mustache similarity index 100% rename from source/_patterns/00-atoms/01-text/04-blockquote.mustache rename to source/_patterns/00-atoms/02-text/04-blockquote.mustache diff --git a/source/_patterns/00-atoms/01-text/05-inline-elements.mustache b/source/_patterns/00-atoms/02-text/05-inline-elements.mustache similarity index 100% rename from source/_patterns/00-atoms/01-text/05-inline-elements.mustache rename to source/_patterns/00-atoms/02-text/05-inline-elements.mustache diff --git a/source/_patterns/00-atoms/01-text/06-time.mustache b/source/_patterns/00-atoms/02-text/06-time.mustache similarity index 100% rename from source/_patterns/00-atoms/01-text/06-time.mustache rename to source/_patterns/00-atoms/02-text/06-time.mustache diff --git a/source/_patterns/00-atoms/01-text/07-preformatted-text.mustache b/source/_patterns/00-atoms/02-text/07-preformatted-text.mustache similarity index 100% rename from source/_patterns/00-atoms/01-text/07-preformatted-text.mustache rename to source/_patterns/00-atoms/02-text/07-preformatted-text.mustache diff --git a/source/_patterns/00-atoms/01-text/08-emphasis-colors.mustache b/source/_patterns/00-atoms/02-text/08-emphasis-colors.mustache similarity index 100% rename from source/_patterns/00-atoms/01-text/08-emphasis-colors.mustache rename to source/_patterns/00-atoms/02-text/08-emphasis-colors.mustache diff --git a/source/_patterns/00-atoms/01-text/09-hr.mustache b/source/_patterns/00-atoms/02-text/09-hr.mustache similarity index 100% rename from source/_patterns/00-atoms/01-text/09-hr.mustache rename to source/_patterns/00-atoms/02-text/09-hr.mustache diff --git a/source/_patterns/00-atoms/01-text/10-caption.mustache b/source/_patterns/00-atoms/02-text/10-caption.mustache similarity index 100% rename from source/_patterns/00-atoms/01-text/10-caption.mustache rename to source/_patterns/00-atoms/02-text/10-caption.mustache diff --git a/source/_patterns/00-atoms/02-lists/00-unordered.mustache b/source/_patterns/00-atoms/03-lists/00-unordered.mustache similarity index 100% rename from source/_patterns/00-atoms/02-lists/00-unordered.mustache rename to source/_patterns/00-atoms/03-lists/00-unordered.mustache diff --git a/source/_patterns/00-atoms/02-lists/01-ordered.mustache b/source/_patterns/00-atoms/03-lists/01-ordered.mustache similarity index 100% rename from source/_patterns/00-atoms/02-lists/01-ordered.mustache rename to source/_patterns/00-atoms/03-lists/01-ordered.mustache diff --git a/source/_patterns/00-atoms/02-lists/02-definition.mustache b/source/_patterns/00-atoms/03-lists/02-definition.mustache similarity index 100% rename from source/_patterns/00-atoms/02-lists/02-definition.mustache rename to source/_patterns/00-atoms/03-lists/02-definition.mustache diff --git a/source/_patterns/00-atoms/03-images/00-logo.mustache b/source/_patterns/00-atoms/04-images/00-logo.mustache similarity index 100% rename from source/_patterns/00-atoms/03-images/00-logo.mustache rename to source/_patterns/00-atoms/04-images/00-logo.mustache diff --git a/source/_patterns/00-atoms/03-images/01-landscape-4x3.mustache b/source/_patterns/00-atoms/04-images/01-landscape-4x3.mustache similarity index 100% rename from source/_patterns/00-atoms/03-images/01-landscape-4x3.mustache rename to source/_patterns/00-atoms/04-images/01-landscape-4x3.mustache diff --git a/source/_patterns/00-atoms/03-images/02-landscape-16x9.mustache b/source/_patterns/00-atoms/04-images/02-landscape-16x9.mustache similarity index 100% rename from source/_patterns/00-atoms/03-images/02-landscape-16x9.mustache rename to source/_patterns/00-atoms/04-images/02-landscape-16x9.mustache diff --git a/source/_patterns/00-atoms/03-images/03-square.mustache b/source/_patterns/00-atoms/04-images/03-square.mustache similarity index 100% rename from source/_patterns/00-atoms/03-images/03-square.mustache rename to source/_patterns/00-atoms/04-images/03-square.mustache diff --git a/source/_patterns/00-atoms/03-images/04-avatar.mustache b/source/_patterns/00-atoms/04-images/04-avatar.mustache similarity index 100% rename from source/_patterns/00-atoms/03-images/04-avatar.mustache rename to source/_patterns/00-atoms/04-images/04-avatar.mustache diff --git a/source/_patterns/00-atoms/03-images/05-icons.mustache b/source/_patterns/00-atoms/04-images/05-icons.mustache similarity index 100% rename from source/_patterns/00-atoms/03-images/05-icons.mustache rename to source/_patterns/00-atoms/04-images/05-icons.mustache diff --git a/source/_patterns/00-atoms/03-images/06-loading-icon.mustache b/source/_patterns/00-atoms/04-images/06-loading-icon.mustache similarity index 100% rename from source/_patterns/00-atoms/03-images/06-loading-icon.mustache rename to source/_patterns/00-atoms/04-images/06-loading-icon.mustache diff --git a/source/_patterns/00-atoms/03-images/07-favicon.mustache b/source/_patterns/00-atoms/04-images/07-favicon.mustache similarity index 100% rename from source/_patterns/00-atoms/03-images/07-favicon.mustache rename to source/_patterns/00-atoms/04-images/07-favicon.mustache diff --git a/source/_patterns/00-atoms/04-forms/00-text-fields.mustache b/source/_patterns/00-atoms/05-forms/00-text-fields.mustache similarity index 100% rename from source/_patterns/00-atoms/04-forms/00-text-fields.mustache rename to source/_patterns/00-atoms/05-forms/00-text-fields.mustache diff --git a/source/_patterns/00-atoms/04-forms/01-select-menu.mustache b/source/_patterns/00-atoms/05-forms/01-select-menu.mustache similarity index 100% rename from source/_patterns/00-atoms/04-forms/01-select-menu.mustache rename to source/_patterns/00-atoms/05-forms/01-select-menu.mustache diff --git a/source/_patterns/00-atoms/04-forms/02-checkbox.mustache b/source/_patterns/00-atoms/05-forms/02-checkbox.mustache similarity index 100% rename from source/_patterns/00-atoms/04-forms/02-checkbox.mustache rename to source/_patterns/00-atoms/05-forms/02-checkbox.mustache diff --git a/source/_patterns/00-atoms/04-forms/03-radio-buttons.mustache b/source/_patterns/00-atoms/05-forms/03-radio-buttons.mustache similarity index 100% rename from source/_patterns/00-atoms/04-forms/03-radio-buttons.mustache rename to source/_patterns/00-atoms/05-forms/03-radio-buttons.mustache diff --git a/source/_patterns/00-atoms/04-forms/04-html5-inputs.mustache b/source/_patterns/00-atoms/05-forms/04-html5-inputs.mustache similarity index 100% rename from source/_patterns/00-atoms/04-forms/04-html5-inputs.mustache rename to source/_patterns/00-atoms/05-forms/04-html5-inputs.mustache diff --git a/source/_patterns/00-atoms/05-buttons/00-buttons.mustache b/source/_patterns/00-atoms/06-buttons/00-buttons.mustache similarity index 100% rename from source/_patterns/00-atoms/05-buttons/00-buttons.mustache rename to source/_patterns/00-atoms/06-buttons/00-buttons.mustache diff --git a/source/_patterns/00-atoms/06-tables/00-table.mustache b/source/_patterns/00-atoms/07-tables/00-table.mustache similarity index 100% rename from source/_patterns/00-atoms/06-tables/00-table.mustache rename to source/_patterns/00-atoms/07-tables/00-table.mustache diff --git a/source/_patterns/00-atoms/07-media/00-video.mustache b/source/_patterns/00-atoms/08-media/00-video.mustache similarity index 100% rename from source/_patterns/00-atoms/07-media/00-video.mustache rename to source/_patterns/00-atoms/08-media/00-video.mustache diff --git a/source/_patterns/00-atoms/07-media/01-audio.mustache b/source/_patterns/00-atoms/08-media/01-audio.mustache similarity index 100% rename from source/_patterns/00-atoms/07-media/01-audio.mustache rename to source/_patterns/00-atoms/08-media/01-audio.mustache diff --git a/test/pattern_assembler_tests.js b/test/pattern_assembler_tests.js index f28ea7c1c..cca671f9d 100644 --- a/test/pattern_assembler_tests.js +++ b/test/pattern_assembler_tests.js @@ -202,8 +202,8 @@ patternlab.data = fs.readJSONSync(path.resolve(patternlab.config.paths.source.data, 'data.json')); patternlab.listitems = fs.readJSONSync(path.resolve(patternlab.config.paths.source.data, 'listitems.json')); - patternlab.header = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'source/_meta/header.html'), 'utf8'); - patternlab.footer = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'source/_meta/footer.html'), 'utf8'); + patternlab.header = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'templates/pattern-header-footer/header.html'), 'utf8'); + patternlab.footer = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'templates/pattern-header-footer/footer.html'), 'utf8'); patternlab.patterns = []; patternlab.data.link = {}; patternlab.partials = {}; @@ -530,8 +530,8 @@ patternlab.data = fs.readJSONSync(path.resolve(patternlab.config.paths.source.data, 'data.json')); patternlab.listitems = fs.readJSONSync(path.resolve(patternlab.config.paths.source.data, 'listitems.json')); - patternlab.header = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'source/_meta/header.html'), 'utf8'); - patternlab.footer = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'source/_meta/footer.html'), 'utf8'); + patternlab.header = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'templates/pattern-header-footer/header.html'), 'utf8'); + patternlab.footer = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'templates/pattern-header-footer/footer.html'), 'utf8'); patternlab.patterns = []; patternlab.data.link = {}; patternlab.partials = {}; @@ -622,8 +622,8 @@ patternlab.config.paths.source.patterns = patterns_dir; patternlab.data = fs.readJSONSync(path.resolve(patternlab.config.paths.source.data, 'data.json')); patternlab.listitems = fs.readJSONSync(path.resolve(patternlab.config.paths.source.data, 'listitems.json')); - patternlab.header = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'source/_meta/header.html'), 'utf8'); - patternlab.footer = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'source/_meta/footer.html'), 'utf8'); + patternlab.header = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'templates/pattern-header-footer/header.html'), 'utf8'); + patternlab.footer = fs.readFileSync(path.resolve(patternlab.config.paths.source.patternlabFiles, 'templates/pattern-header-footer/footer.html'), 'utf8'); patternlab.patterns = []; patternlab.data.link = {}; patternlab.partials = {}; From db06056fdd9ceb84629c987e6c8ffea8a3cff7ca Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Sat, 5 Mar 2016 14:57:58 -0600 Subject: [PATCH 27/37] remove a debug statement --- core/lib/patternlab.js | 1 - 1 file changed, 1 deletion(-) diff --git a/core/lib/patternlab.js b/core/lib/patternlab.js index dc11e4ecd..91d155f58 100644 --- a/core/lib/patternlab.js +++ b/core/lib/patternlab.js @@ -171,7 +171,6 @@ var patternlab_engine = function (config) { //set the pattern-specific footer if necessary if (patternlab.userFoot) { - console.log('found custom userFoot') var userFooter = patternlab.userFoot.extendedTemplate.replace('{% pattern-lab-foot %}', patternlab.footerPattern + patternlab.footer); pattern.footer = pattern_assembler.renderPattern(userFooter, pattern); } else { From d167a97b694d73987a2de43f58f07fcfb2a38b58 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Sun, 6 Mar 2016 22:12:39 -0600 Subject: [PATCH 28/37] cacheBust support --- README.md | 10 +++++++ config.json | 3 +- core/lib/patternlab.js | 28 ++++++++++++++++--- core/templates/index.mustache | 26 ++++++++--------- .../pattern-header-footer/footer.html | 10 +++---- .../pattern-header-footer/header.html | 4 +-- 6 files changed, 56 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index c934f0738..22df180af 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,16 @@ Pattern states should be lowercase and use hyphens where spaces are present. Coupled with exported css (much easier to extract with existing tools like [grunt-contrib-copy](https://github.com/gruntjs/grunt-contrib-copy)), pattern export can help to maintain the relevancy of the design system by directly placing partials in a directory of your choosing. +##### cacheBust +`config.json` has this flag to instruct Pattern Lab to append a unique query string to Javascript and CSS assets throughout the frontend. + +``` +"cacheBust": true +``` + +Default: true + + ##### baseurl If your instance of Pattern Lab lives in a subdirectory of your server, for instance on github pages (ex: yourusername.github.io/patterns-demo/), then add the baseurl here. The baseurl is everything after the hostname - ie: `patterns-demo` diff --git a/config.json b/config.json index d9aec61cb..4d42d0bc5 100644 --- a/config.json +++ b/config.json @@ -53,5 +53,6 @@ }, "patternExportKeys": [], "patternExportDirectory": "./pattern_exports/", - "baseurl" : "" + "baseurl" : "", + "cacheBust": true } diff --git a/core/lib/patternlab.js b/core/lib/patternlab.js index 91d155f58..1d7dcf62a 100644 --- a/core/lib/patternlab.js +++ b/core/lib/patternlab.js @@ -54,6 +54,17 @@ var patternlab_engine = function (config) { } } + function setCacheBust() { + if (patternlab.config.cacheBust) { + if (patternlab.config.debug) { + console.log('setting cacheBuster value for frontend assets.'); + } + patternlab.cacheBuster = new Date().getTime(); + } else { + patternlab.cacheBuster = 0; + } + } + function buildPatterns(deletePatternDir) { patternlab.data = fs.readJSONSync(path.resolve(paths.source.data, 'data.json')); patternlab.listitems = fs.readJSONSync(path.resolve(paths.source.data, 'listitems.json')); @@ -64,6 +75,8 @@ var patternlab_engine = function (config) { patternlab.partials = {}; patternlab.data.link = {}; + setCacheBust(); + var pattern_assembler = new pa(), entity_encoder = new he(), pattern_exporter = new pe(), @@ -163,6 +176,10 @@ var patternlab_engine = function (config) { var allData = JSON.parse(JSON.stringify(patternlab.data)); allData = pattern_assembler.merge_data(allData, pattern.jsonFileData); + //also add the cachebuster value. slight chance this could collide with a user that has defined cacheBuster as a value + allData.cacheBuster = patternlab.cacheBuster; + pattern.cacheBuster = patternlab.cacheBuster; + //render the pattern-specific header var headHtml = pattern_assembler.renderPattern(pattern.header, allData); @@ -249,6 +266,9 @@ var patternlab_engine = function (config) { styleguidePatterns = patternlab.patterns; } + //also add the cachebuster value. slight chance this could collide with a user that has defined cacheBuster as a value + patternlab.data.cacheBuster = patternlab.cacheBuster; + //get the main page head and foot var mainPageHead = patternlab.userHead.extendedTemplate.replace('{% pattern-lab-head %}', patternlab.header); var mainPageHeadHtml = pattern_assembler.renderPattern(mainPageHead, patternlab.data); @@ -257,7 +277,7 @@ var patternlab_engine = function (config) { //build the styleguide var styleguideTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'templates/styleguide.mustache'), 'utf8'), - styleguideHtml = pattern_assembler.renderPattern(styleguideTemplate, {partials: styleguidePatterns}); + styleguideHtml = pattern_assembler.renderPattern(styleguideTemplate, {partials: styleguidePatterns, cacheBuster: patternlab.cacheBuster}); fs.outputFileSync(path.resolve(paths.public.styleguide, 'html/styleguide.html'), mainPageHeadHtml + styleguideHtml + mainPageFootHtml); @@ -300,7 +320,7 @@ var patternlab_engine = function (config) { } var viewAllTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'templates/viewall.mustache'), 'utf8'); - var viewAllHtml = pattern_assembler.renderPattern(viewAllTemplate, {partials: viewAllPatterns, patternPartial: patternPartial}); + var viewAllHtml = pattern_assembler.renderPattern(viewAllTemplate, {partials: viewAllPatterns, patternPartial: patternPartial, cacheBuster: patternlab.cacheBuster }); fs.outputFileSync(paths.public.patterns + pattern.subdir.slice(0, pattern.subdir.indexOf(pattern.patternGroup) + pattern.patternGroup.length) + '/index.html', mainPageHead + viewAllHtml + mainPageFoot); } @@ -327,7 +347,7 @@ var patternlab_engine = function (config) { } var viewAllTemplate = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'templates/viewall.mustache'), 'utf8'); - var viewAllHtml = pattern_assembler.renderPattern(viewAllTemplate, {partials: viewAllPatterns, patternPartial: patternPartial}); + var viewAllHtml = pattern_assembler.renderPattern(viewAllTemplate, {partials: viewAllPatterns, patternPartial: patternPartial, cacheBuster: patternlab.cacheBuster}); fs.outputFileSync(paths.public.patterns + pattern.flatPatternPath + '/index.html', mainPageHeadHtml + viewAllHtml + mainPageFootHtml); } } @@ -523,7 +543,7 @@ var patternlab_engine = function (config) { var viewAllPathsPartialHtml = pattern_assembler.renderPattern(viewAllPathsTemplate, {'viewallpaths': JSON.stringify(patternlab.viewAllPaths)}); //render the patternlab template, with all partials - var patternlabSiteHtml = pattern_assembler.renderPattern(patternlabSiteTemplate, {}, { + var patternlabSiteHtml = pattern_assembler.renderPattern(patternlabSiteTemplate, {cacheBuster: patternlab.cacheBuster}, { 'ishControls': ishControlsPartialHtml, 'patternNav': patternNavPartialHtml, 'patternPaths': patternPathsPartialHtml, diff --git a/core/templates/index.mustache b/core/templates/index.mustache index 912839552..e3c1be462 100644 --- a/core/templates/index.mustache +++ b/core/templates/index.mustache @@ -12,10 +12,10 @@ - - - - + + + + @@ -86,17 +86,17 @@
- - - - + + + + {{> patternPaths }} {{> viewAllPaths }} - - - - - + + + + + diff --git a/core/templates/pattern-header-footer/footer.html b/core/templates/pattern-header-footer/footer.html index 9bdd04a87..b865c85ab 100644 --- a/core/templates/pattern-header-footer/footer.html +++ b/core/templates/pattern-header-footer/footer.html @@ -1,6 +1,6 @@ - - - - - + + + + + diff --git a/core/templates/pattern-header-footer/header.html b/core/templates/pattern-header-footer/header.html index 603079c27..ebe81993e 100644 --- a/core/templates/pattern-header-footer/header.html +++ b/core/templates/pattern-header-footer/header.html @@ -5,5 +5,5 @@ - - + + From 88198f053c496a5d9ff208120016039aca8c23b6 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Sun, 6 Mar 2016 23:30:15 -0600 Subject: [PATCH 29/37] fix some eslint warnings --- core/lib/patternlab.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/lib/patternlab.js b/core/lib/patternlab.js index 1d7dcf62a..21df458ef 100644 --- a/core/lib/patternlab.js +++ b/core/lib/patternlab.js @@ -134,7 +134,7 @@ var patternlab_engine = function (config) { try { patternlab.userHead = pattern_assembler.get_pattern_by_key('atoms-head', patternlab); } - catch(ex) { + catch (ex) { if (patternlab.config.debug) { console.log(ex); console.log('Could not find optional user-defined header, atoms-head pattern. It was likely deleted.'); @@ -143,7 +143,7 @@ var patternlab_engine = function (config) { try { patternlab.userFoot = pattern_assembler.get_pattern_by_key('atoms-foot', patternlab); } - catch(ex) { + catch (ex) { if (patternlab.config.debug) { console.log(ex); console.log('Could not find optional user-defined footer, atoms-foot pattern. It was likely deleted.'); @@ -195,7 +195,7 @@ var patternlab_engine = function (config) { } //write the compiled template to the public patterns directory - fs.outputFileSync(paths.public.patterns + pattern.patternLink, headHtml + pattern.patternPartial + pattern.footer); + fs.outputFileSync(paths.public.patterns + pattern.patternLink, headHtml + pattern.patternPartial + pattern.footer); //write the mustache file too fs.outputFileSync(paths.public.patterns + pattern.patternLink.replace('.html', '.mustache'), entity_encoder.encode(pattern.template)); From 31a5b115fcd6da7151edef46c9f89be86ee9fbaa Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Mon, 7 Mar 2016 01:09:22 -0600 Subject: [PATCH 30/37] renamed config.json to patternlab-config.json for better consumption closes #192 --- Gruntfile.js | 2 +- README.md | 16 ++++++++-------- core/lib/patternlab.js | 4 ++-- gulpfile.js | 2 +- config.json => patternlab-config.json | 0 test/pattern_assembler_tests.js | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) rename config.json => patternlab-config.json (100%) diff --git a/Gruntfile.js b/Gruntfile.js index 2f5dc2ad3..83cdbb4c8 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -3,7 +3,7 @@ module.exports = function (grunt) { var path = require('path'); function paths() { - return require('./config.json').paths; + return require('./patternlab-config.json').paths; } // Project configuration. diff --git a/README.md b/README.md index ba5bc510f..ce7d394b6 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ Get more information about patternlab-node, pattern lab in general, and where to To have patternlab-node watch for changes to either a mustache template, data, or stylesheets, run `grunt|gulp watch` or `grunt|gulp serve`. The `Gruntfile|Gulpfile` governs what is watched. It should be easy to add scss or whatever preprocessor you fancy. ##### Configurable Paths -Pattern Lab Node ships with a particular source and public workflow intended to separate the code you work on with the code generated for consumption elsewhere. If you wish to change any paths, you may do so within `config.json`. The contents are here: +Pattern Lab Node ships with a particular source and public workflow intended to separate the code you work on with the code generated for consumption elsewhere. If you wish to change any paths, you may do so within `patternlab-config.json`. The contents are here: ``` "paths" : { @@ -117,7 +117,7 @@ Pattern Lab Node ships with a particular source and public workflow intended to Note the intentional repitition of the nested structure, made this way for maximum flexibility. Relative paths are default but absolute paths should work too. You may also use these paths within Grunt or Gulp files by referring to the paths() object. ##### Nav Bar Controls -If you don't have a need for some of the nav-bar tools in the Pattern Lab frontend, you can turn them off in `config.json`. +If you don't have a need for some of the nav-bar tools in the Pattern Lab frontend, you can turn them off in `patternlab-config.json`. The current selection is as follows. @@ -144,7 +144,7 @@ The current selection is as follows. } ``` ##### Pattern States -You can set the state of a pattern by including it in `config.json` too. The out of the box styles are in progress (orange), in review (yellow), and complete (green). +You can set the state of a pattern by including it in `patternlab-config.json` too. The out of the box styles are in progress (orange), in review (yellow), and complete (green). Pattern states should be lowercase and use hyphens where spaces are present. ``` "patternStates": { @@ -155,7 +155,7 @@ Pattern states should be lowercase and use hyphens where spaces are present. ``` ##### Pattern Export -`config.json` also has two properties that work together to export completed patterns for use in a production environment. Provide an array of keys and an output directory. Pattern Lab doesn't ship with any pattern export keys, but the default directory is `"./pattern_exports/"` created inside the install directory. +`patternlab-config.json` also has two properties that work together to export completed patterns for use in a production environment. Provide an array of keys and an output directory. Pattern Lab doesn't ship with any pattern export keys, but the default directory is `"./pattern_exports/"` created inside the install directory. ``` "patternExportKeys": ["molecules-primary-nav", "organisms-header", "organisms-header"], @@ -165,7 +165,7 @@ Pattern states should be lowercase and use hyphens where spaces are present. Coupled with exported css (much easier to extract with existing tools like [grunt-contrib-copy](https://github.com/gruntjs/grunt-contrib-copy)), pattern export can help to maintain the relevancy of the design system by directly placing partials in a directory of your choosing. ##### cacheBust -`config.json` has this flag to instruct Pattern Lab to append a unique query string to Javascript and CSS assets throughout the frontend. +`patternlab-config.json` has this flag to instruct Pattern Lab to append a unique query string to Javascript and CSS assets throughout the frontend. ``` "cacheBust": true @@ -174,7 +174,7 @@ Coupled with exported css (much easier to extract with existing tools like [grun Default: true ##### defaultPattter -`config.json` has an entry that allows you to specifiy a specific pattern upon launch of the main site. It works even without BrowserSync running. Set it like this: +`patternlab-config.json` has an entry that allows you to specifiy a specific pattern upon launch of the main site. It works even without BrowserSync running. Set it like this: ``` "defaultPattern": "pages-homepage", @@ -204,7 +204,7 @@ You can also exclude complete directories by prepending the directory name with ##### Style Guide Excludes -Exclude whole pattern types from the "All patterns" styleguide by adding entries to `config.json`. This is quite useful to make speedier. Pattern Lab Node ships with the following: +Exclude whole pattern types from the "All patterns" styleguide by adding entries to `patternlab-config.json`. This is quite useful to make speedier. Pattern Lab Node ships with the following: ``` "styleGuideExcludes": [ @@ -215,7 +215,7 @@ Exclude whole pattern types from the "All patterns" styleguide by adding entries ##### Debug Mode -`patternlab.json` is a file created for debugging purposes. Set `debug` to true in `.config.json` to see all the secrets. +`patternlab.json` is a file created for debugging purposes. Set `debug` to true in `.patternlab-config.json` to see all the secrets. ##### Server & BrowserSync Running `grunt serve` or `gulp serve` will compile the Pattern Lab frontend and host it by default on http://localhost:3000 via [BrowserSync](http://www.browsersync.io/docs/). After it starts, templates, `data.json`, and scss/css changes in your source code will be automatically injected into the page. diff --git a/core/lib/patternlab.js b/core/lib/patternlab.js index 7f79cf102..c09f0986d 100644 --- a/core/lib/patternlab.js +++ b/core/lib/patternlab.js @@ -22,7 +22,7 @@ var patternlab_engine = function (config) { patternlab = {}; patternlab.package = fs.readJSONSync('./package.json'); - patternlab.config = config || fs.readJSONSync(path.resolve(__dirname, '../../config.json')); + patternlab.config = config || fs.readJSONSync(path.resolve(__dirname, '../../patternlab-config.json')); var paths = patternlab.config.paths; @@ -47,7 +47,7 @@ var patternlab_engine = function (config) { } function printDebug() { - //debug file can be written by setting flag on config.json + //debug file can be written by setting flag on patternlab-config.json if (patternlab.config.debug) { console.log('writing patternlab debug file to ./patternlab.json'); fs.outputFileSync('./patternlab.json', JSON.stringify(patternlab, null, 3)); diff --git a/gulpfile.js b/gulpfile.js index 85e157f15..a97b3b805 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -23,7 +23,7 @@ var banner = [ '/** ', ' * ', ' **/'].join(eol); function paths() { - return require('./config.json').paths; + return require('./patternlab-config.json').paths; } //load patternlab-node tasks diff --git a/config.json b/patternlab-config.json similarity index 100% rename from config.json rename to patternlab-config.json diff --git a/test/pattern_assembler_tests.js b/test/pattern_assembler_tests.js index cca671f9d..14d6cc3f7 100644 --- a/test/pattern_assembler_tests.js +++ b/test/pattern_assembler_tests.js @@ -197,7 +197,7 @@ var pattern_assembler = new pa(); var patterns_dir = './test/files/_patterns'; var patternlab = {}; - patternlab.config = fs.readJSONSync('./config.json'); + patternlab.config = fs.readJSONSync('./patternlab-config.json'); patternlab.config.paths.source.patterns = patterns_dir; patternlab.data = fs.readJSONSync(path.resolve(patternlab.config.paths.source.data, 'data.json')); @@ -525,7 +525,7 @@ var patterns_dir = './test/files/_patterns'; var patternlab = {}; //THIS IS BAD. - patternlab.config = fs.readJSONSync('./config.json'); + patternlab.config = fs.readJSONSync('./patternlab-config.json'); patternlab.config.paths.source.patterns = patterns_dir; patternlab.data = fs.readJSONSync(path.resolve(patternlab.config.paths.source.data, 'data.json')); @@ -618,7 +618,7 @@ var patterns_dir = './test/files/_patterns/'; var patternlab = {}; //THIS IS BAD - patternlab.config = fs.readJSONSync('./config.json'); + patternlab.config = fs.readJSONSync('./patternlab-config.json'); patternlab.config.paths.source.patterns = patterns_dir; patternlab.data = fs.readJSONSync(path.resolve(patternlab.config.paths.source.data, 'data.json')); patternlab.listitems = fs.readJSONSync(path.resolve(patternlab.config.paths.source.data, 'listitems.json')); From 32d00c4a701334aecc59e8a6ae221a2fedff4991 Mon Sep 17 00:00:00 2001 From: Zac Anger Date: Tue, 8 Mar 2016 17:51:30 -0700 Subject: [PATCH 31/37] Updating `.gitignore` to just say `public` Previously had many files/subdirectories broken out in the `.gitignore`; seems the idea is just to ignore the entire directory, which can be done with just the one line. Does not address any open issue; just addresses potential confusion over what should/shouldn't be ignored in `public`. --- .gitignore | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index f9d11769c..32d4d0c2f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,22 +1,10 @@ node_modules/ .DS_Store -public/index.html -public/styleguide.html -public/styleguide/html/styleguide.html -public/css/* -public/data/* -public/fonts/* -public/js/* -public/images/* -public/patterns/* latest-change.txt patternlab.json .sass-cache/* /sass-cache source/images/Thumbs.db -public/styleguide/css/static.css.map -public/styleguide/css/styleguide-specific.css.map -public/styleguide/css/styleguide.css.map source/css/style.css.map .idea/ -public/styleguide/ +public From 5ad83444bb2e120ea62b3696bc3e840291c2736b Mon Sep 17 00:00:00 2001 From: Zac Anger Date: Tue, 8 Mar 2016 17:53:26 -0700 Subject: [PATCH 32/37] Updating gitignore for Thumbs.db Not specifying any directory means it'll catch all `Thumbs.db` files in any directory. --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 32d4d0c2f..74ab03195 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ latest-change.txt patternlab.json .sass-cache/* /sass-cache -source/images/Thumbs.db +Thumbs.db source/css/style.css.map .idea/ public From 03e85a76e0b5a9708e0de4344465a0e19b76c02b Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Wed, 9 Mar 2016 10:40:55 -0600 Subject: [PATCH 33/37] Implement pattern state lowest common denominator closes #203 --- README.md | 20 +- core/lib/lineage_hunter.js | 85 ++- core/lib/pattern_assembler.js | 4 +- core/lib/patternlab.js | 18 + patternlab-config.json | 5 +- test/lineage_hunter_tests.js | 1008 ++++++++++++++++++------------- test/pattern_assembler_tests.js | 8 +- 7 files changed, 705 insertions(+), 443 deletions(-) diff --git a/README.md b/README.md index ce7d394b6..398df1c2a 100644 --- a/README.md +++ b/README.md @@ -148,12 +148,26 @@ You can set the state of a pattern by including it in `patternlab-config.json` t Pattern states should be lowercase and use hyphens where spaces are present. ``` "patternStates": { - "colors" : "inprogress", - "fonts" : "inreview", - "three-up" : "complete" + "atoms-colors" : "complete", + "molecules-primary-nav" : "inreview", + "organisms-header" : "inprogress" } ``` +Note that patterns inherit the lowest common denominator pattern state of their lineage. +Consider: +``` +"patternStates": { + "molecules-single-comment" : "complete", + "organisms-sticky-comment" : "inreview", + "templates-article" : "complete" +} +``` +In this case, two things are of note: + +* templates-article will display inreview since it inherits `organisms-sticky-comment` +* pages-article will not display any pattern state, as it does not define one + ##### Pattern Export `patternlab-config.json` also has two properties that work together to export completed patterns for use in a production environment. Provide an array of keys and an output directory. Pattern Lab doesn't ship with any pattern export keys, but the default directory is `"./pattern_exports/"` created inside the install directory. diff --git a/core/lib/lineage_hunter.js b/core/lib/lineage_hunter.js index 65a0e35cc..6463c038c 100644 --- a/core/lib/lineage_hunter.js +++ b/core/lib/lineage_hunter.js @@ -12,9 +12,10 @@ var lineage_hunter = function () { + var pa = require('./pattern_assembler'); + function findlineage(pattern, patternlab) { - var pa = require('./pattern_assembler'); var pattern_assembler = new pa(); //find the {{> template-name }} within patterns @@ -50,7 +51,11 @@ var lineage_hunter = function () { "lineagePattern": ancestorPattern.key, "lineagePath": "../../patterns/" + ancestorPattern.patternLink }; - pattern.lineage.push(JSON.stringify(l)); + if (ancestorPattern.patternState) { + l.lineageState = ancestorPattern.patternState; + } + + pattern.lineage.push(l); //also, add the lineageR entry if it doesn't exist if (ancestorPattern.lineageRIndex.indexOf(pattern.key) === -1) { @@ -61,16 +66,90 @@ var lineage_hunter = function () { "lineagePattern": pattern.key, "lineagePath": "../../patterns/" + pattern.patternLink }; - ancestorPattern.lineageR.push(JSON.stringify(lr)); + if (pattern.patternState) { + lr.lineageState = pattern.patternState; + } + + ancestorPattern.lineageR.push(lr); } } }); } } + function setPatternState(direction, pattern, targetPattern) { + // if the request came from the past, apply target pattern state to current pattern lineage + if (direction === 'fromPast') { + for (var i = 0; i < pattern.lineageIndex.length; i++) { + if (pattern.lineageIndex[i] === targetPattern.key) { + pattern.lineage[i].lineageState = targetPattern.patternState; + } + } + } else { + //the request came from the future, apply target pattern state to current pattern reverse lineage + for (var i = 0; i < pattern.lineageRIndex.length; i++) { + if (pattern.lineageRIndex[i] === targetPattern.key) { + pattern.lineageR[i].lineageState = targetPattern.patternState; + } + } + } + } + + + function cascadePatternStates(patternlab) { + + var pattern_assembler = new pa(); + + for (var i = 0; i < patternlab.patterns.length; i++) { + var pattern = patternlab.patterns[i]; + + //for each pattern with a defined state + if (pattern.patternState) { + + if (pattern.lineageIndex && pattern.lineageIndex.length > 0) { + + //find all lineage - patterns being consumed by this one + for (var h = 0; h < pattern.lineageIndex.length; h++) { + var lineagePattern = pattern_assembler.get_pattern_by_key(pattern.lineageIndex[h], patternlab); + setPatternState('fromFuture', lineagePattern, pattern); + } + } + + if (pattern.lineageRIndex && pattern.lineageRIndex.length > 0) { + + //find all reverse lineage - that is, patterns consuming this one + for (var j = 0; j < pattern.lineageRIndex.length; j++) { + + var lineageRPattern = pattern_assembler.get_pattern_by_key(pattern.lineageRIndex[j], patternlab); + + //only set patternState if pattern.patternState "is less than" the lineageRPattern.patternstate + //this makes patternlab apply the lowest common ancestor denominator + if (patternlab.config.patternStateCascade.indexOf(pattern.patternState) + < patternlab.config.patternStateCascade.indexOf(lineageRPattern.patternState)) { + + if (patternlab.config.debug) { + console.log('Found a lower common denominator pattern state: ' + pattern.patternState + ' on ' + pattern.key + '. Setting reverse lineage pattern ' + lineageRPattern.key + ' from ' + lineageRPattern.patternState); + } + + lineageRPattern.patternState = pattern.patternState; + + //take this opportunity to overwrite the lineageRPattern's lineage state too + setPatternState('fromPast', lineageRPattern, pattern); + } else { + setPatternState('fromPast', pattern, lineageRPattern); + } + } + } + } + } + } + return { find_lineage: function (pattern, patternlab) { findlineage(pattern, patternlab); + }, + cascade_pattern_states : function (patternlab) { + cascadePatternStates(patternlab); } }; diff --git a/core/lib/pattern_assembler.js b/core/lib/pattern_assembler.js index 2d40c1544..df6129c30 100644 --- a/core/lib/pattern_assembler.js +++ b/core/lib/pattern_assembler.js @@ -36,8 +36,8 @@ var pattern_assembler = function () { } function setState(pattern, patternlab) { - if (patternlab.config.patternStates && patternlab.config.patternStates[pattern.patternName]) { - pattern.patternState = patternlab.config.patternStates[pattern.patternName]; + if (patternlab.config.patternStates && patternlab.config.patternStates[pattern.key]) { + pattern.patternState = patternlab.config.patternStates[pattern.key]; } else { pattern.patternState = ""; } diff --git a/core/lib/patternlab.js b/core/lib/patternlab.js index c09f0986d..45e8b4e05 100644 --- a/core/lib/patternlab.js +++ b/core/lib/patternlab.js @@ -18,6 +18,7 @@ var patternlab_engine = function (config) { pa = require('./pattern_assembler'), mh = require('./media_hunter'), pe = require('./pattern_exporter'), + lh = require('./lineage_hunter'), he = require('html-entities').AllHtmlEntities, patternlab = {}; @@ -80,6 +81,7 @@ var patternlab_engine = function (config) { var pattern_assembler = new pa(), entity_encoder = new he(), pattern_exporter = new pe(), + lineage_hunter = new lh(), patterns_dir = paths.source.patterns; pattern_assembler.combine_listItems(patternlab); @@ -154,6 +156,9 @@ var patternlab_engine = function (config) { //we need to do this before expanding patterns & partials into extendedTemplates, otherwise we could lose the data -> partial reference pattern_assembler.parse_data_links(patternlab); + //cascade any patternStates + lineage_hunter.cascade_pattern_states(patternlab); + //delete the contents of config.patterns.public before writing if (deletePatternDir) { fs.emptyDirSync(paths.public.patterns); @@ -172,6 +177,19 @@ var patternlab_engine = function (config) { pattern.header = head; + //json stringify lineage and lineageR + var lineageArray = []; + for (var i = 0; i < pattern.lineage.length; i++) { + lineageArray.push(JSON.stringify(pattern.lineage[i])); + } + pattern.lineage = lineageArray; + + var lineageRArray = []; + for (var i = 0; i < pattern.lineageR.length; i++) { + lineageRArray.push(JSON.stringify(pattern.lineageR[i])); + } + pattern.lineageR = lineageRArray; + //render the pattern, but first consolidate any data we may have var allData = JSON.parse(JSON.stringify(patternlab.data)); allData = pattern_assembler.merge_data(allData, pattern.jsonFileData); diff --git a/patternlab-config.json b/patternlab-config.json index c66bc914c..42d13071a 100644 --- a/patternlab-config.json +++ b/patternlab-config.json @@ -49,8 +49,11 @@ "tools-shortcuts": true, "tools-docs": true }, + "patternStateCascade": ["inprogress", "inreview", "complete"], "patternStates": { - "homepage-emergency" : "inprogress" + "molecules-single-comment" : "complete", + "organisms-sticky-comment" : "inreview", + "templates-article" : "complete" }, "patternExportKeys": [], "patternExportDirectory": "./pattern_exports/", diff --git a/test/lineage_hunter_tests.js b/test/lineage_hunter_tests.js index 490c704ec..60ee018a6 100644 --- a/test/lineage_hunter_tests.js +++ b/test/lineage_hunter_tests.js @@ -1,433 +1,581 @@ (function () { - "use strict"; - - var lh = require('../core/lib/lineage_hunter'); - - exports['lineage hunter '] = { - 'find_lineage - finds lineage' : function(test){ - - //setup current pattern from what we would have during execution - var currentPattern = { - "name": "02-organisms-00-global-00-header", - "subdir": "02-organisms\\00-global", - "filename": "00-header.mustache", - "data": null, - "template": "\r\n
\r\n\t{{> atoms-logo }}\r\n\tSearch\r\n\tMenu\r\n\t{{> molecules-primary-nav }}\r\n\t{{> molecules-search }}\r\n
\r\n\r\n", - "patternPartial": "\r\n
\r\n\"Logo\tSearch\r\n\tMenu\r\n\r\n
\r\n
\r\n\t Search\r\n\t \r\n\t \r\n\t \r\n
\r\n
\r\n\r\n", - "patternName": "header", - "patternLink": "02-organisms-00-global-00-header/02-organisms-00-global-00-header.html", - "patternGroup": "organisms", - "patternSubGroup": "organisms\\00-global", - "flatPatternPath": "02-organisms\\00-global", - "key": "organisms-header", - "patternState": "", - "lineage": [], - "lineageIndex": [], - "lineageR": [], - "lineageRIndex": [] - }; - var patternlab = { - patterns: [ - { - "name": "00-atoms-03-images-00-logo", - "subdir": "00-atoms\\03-images", - "filename": "00-logo.mustache", - "data": null, - "template": "\"Logo", - "patternPartial": "\"Logo", - "patternName": "logo", - "patternLink": "00-atoms-03-images-00-logo/00-atoms-03-images-00-logo.html", - "patternGroup": "atoms", - "patternSubGroup": "atoms\\03-images", - "flatPatternPath": "00-atoms\\03-images", - "key": "atoms-logo", - "patternState": "", - "lineage": [], - "lineageIndex": [], - "lineageR": [], - "lineageRIndex": [] - }, - { - "name": "01-molecules-05-navigation-00-primary-nav", - "subdir": "01-molecules\\05-navigation", - "filename": "00-primary-nav.mustache", - "data": null, - "template": "\r\n", - "patternPartial": "\r\n", - "patternName": "primary-nav", - "patternLink": "01-molecules-05-navigation-00-primary-nav/01-molecules-05-navigation-00-primary-nav.html", - "patternGroup": "molecules", - "patternSubGroup": "molecules\\05-navigation", - "flatPatternPath": "01-molecules\\05-navigation", - "key": "molecules-primary-nav", - "patternState": "", - "lineage": [], - "lineageIndex": [], - "lineageR": [], - "lineageRIndex": [] - }, - { - "name": "01-molecules-04-forms-00-search", - "subdir": "01-molecules\\04-forms", - "filename": "00-search.mustache", - "data": null, - "template": "
\r\n
\r\n\t Search\r\n\t \r\n\t \r\n\t \r\n
\r\n
", - "patternPartial": "
\r\n
\r\n\t Search\r\n\t \r\n\t \r\n\t \r\n
\r\n
", - "patternName": "search", - "patternLink": "01-molecules-04-forms-00-search/01-molecules-04-forms-00-search.html", - "patternGroup": "molecules", - "patternSubGroup": "molecules\\04-forms", - "flatPatternPath": "01-molecules\\04-forms", - "key": "molecules-search", - "patternState": "", - "lineage": [], - "lineageIndex": [], - "lineageR": [], - "lineageRIndex": [] - } - ] - }; - - var lineage_hunter = new lh(); - lineage_hunter.find_lineage(currentPattern, patternlab); - - test.equals(currentPattern.lineageIndex.length, 3); - test.equals(currentPattern.lineageIndex[0], "atoms-logo"); - test.equals(currentPattern.lineageIndex[1], "molecules-primary-nav"); - test.equals(currentPattern.lineageIndex[2], "molecules-search"); - - test.done(); - }, - - 'find_lineage - 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", - "key": "molecules-error", - "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": "

{{message}}

", - "patternPartial": "

{{message}}

", - "patternName": "error", - "patternLink": "01-atoms-05-alerts-00-error/01-atoms-05-alerts-00-error.html", - "patternGroup": "atoms", - "patternSubGroup": "atoms\\05-alerts", - "flatPatternPath": "01-atoms\\05-alerts", - "key": "atoms-error", - "patternState": "", - "lineage": [], - "lineageIndex": [], - "lineageR": [], - "lineageRIndex": [] - } - ] - }; - - var lineage_hunter = new lh(); - lineage_hunter.find_lineage(currentPattern, patternlab); - - test.equals(currentPattern.lineageIndex.length, 1); - test.equals(currentPattern.lineageIndex[0], "atoms-error"); - - test.done(); - }, - - 'find_lineage - finds lineage with unspaced 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", - "key": "molecules-error", - "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": "

{{message}}

", - "patternPartial": "

{{message}}

", - "patternName": "error", - "patternLink": "01-atoms-05-alerts-00-error/01-atoms-05-alerts-00-error.html", - "patternGroup": "atoms", - "patternSubGroup": "atoms\\05-alerts", - "flatPatternPath": "01-atoms\\05-alerts", - "key": "atoms-error", - "patternState": "", - "lineage": [], - "lineageIndex": [], - "lineageR": [], - "lineageRIndex": [] - } - ] - }; - - var lineage_hunter = new lh(); - lineage_hunter.find_lineage(currentPattern, patternlab); - - test.equals(currentPattern.lineageIndex.length, 1); - test.equals(currentPattern.lineageIndex[0], "atoms-error"); - test.equals(patternlab.patterns[0].lineageRIndex.length, 1); - test.equals(JSON.parse(patternlab.patterns[0].lineageR).lineagePattern, 'molecules-error'); - - test.done(); - }, - - 'find_lineage - finds lineage with spaced styleModifier' : 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:foo }}", - "patternPartial": "{{> atoms-error:foo }}", - "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", - "key": "molecules-error", - "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": "

{{message}}

", - "patternPartial": "

{{message}}

", - "patternName": "error", - "patternLink": "01-atoms-05-alerts-00-error/01-atoms-05-alerts-00-error.html", - "patternGroup": "atoms", - "patternSubGroup": "atoms\\05-alerts", - "flatPatternPath": "01-atoms\\05-alerts", - "key": "atoms-error", - "patternState": "", - "lineage": [], - "lineageIndex": [], - "lineageR": [], - "lineageRIndex": [] - } - ] - }; - - var lineage_hunter = new lh(); - lineage_hunter.find_lineage(currentPattern, patternlab); - - test.equals(currentPattern.lineageIndex.length, 1); - test.equals(currentPattern.lineageIndex[0], "atoms-error"); - - test.done(); - }, - - 'find_lineage - finds lineage with unspaced styleModifier' : 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:foo }}", - "patternPartial": "{{>atoms-error:foo}}", - "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", - "key": "molecules-error", - "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": "

{{message}}

", - "patternPartial": "

{{message}}

", - "patternName": "error", - "patternLink": "01-atoms-05-alerts-00-error/01-atoms-05-alerts-00-error.html", - "patternGroup": "atoms", - "patternSubGroup": "atoms\\05-alerts", - "flatPatternPath": "01-atoms\\05-alerts", - "key": "atoms-error", - "patternState": "", - "lineage": [], - "lineageIndex": [], - "lineageR": [], - "lineageRIndex": [] - } - ] - }; - - var lineage_hunter = new lh(); - lineage_hunter.find_lineage(currentPattern, patternlab); - - test.equals(currentPattern.lineageIndex.length, 1); - test.equals(currentPattern.lineageIndex[0], "atoms-error"); - - test.done(); - }, - - 'find_lineage - finds lineage with fuzzy partial with styleModifier' : 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-e:foo }}", - "patternPartial": "{{>atoms-e:foo}}", - "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", - "key": "molecules-error", - "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": "

{{message}}

", - "patternPartial": "

{{message}}

", - "patternName": "error", - "patternLink": "01-atoms-05-alerts-00-error/01-atoms-05-alerts-00-error.html", - "patternGroup": "atoms", - "patternSubGroup": "atoms\\05-alerts", - "flatPatternPath": "01-atoms\\05-alerts", - "key": "atoms-error", - "patternState": "", - "lineage": [], - "lineageIndex": [], - "lineageR": [], - "lineageRIndex": [] - } - ] - }; - - var lineage_hunter = new lh(); - lineage_hunter.find_lineage(currentPattern, patternlab); - - test.equals(currentPattern.lineageIndex.length, 1); - test.equals(currentPattern.lineageIndex[0], "atoms-error"); - - test.done(); - }, - - 'find_lineage - does not apply lineage twice' : 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", - "key": "molecules-error", - "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": "

{{message}}

", - "patternPartial": "

{{message}}

", - "patternName": "error", - "patternLink": "01-atoms-05-alerts-00-error/01-atoms-05-alerts-00-error.html", - "patternGroup": "atoms", - "patternSubGroup": "atoms\\05-alerts", - "flatPatternPath": "01-atoms\\05-alerts", - "key": "atoms-error", - "patternState": "", - "lineage": [], - "lineageIndex": [], - "lineageR": [], - "lineageRIndex": [] - } - ] - }; - - var lineage_hunter = new lh(); - lineage_hunter.find_lineage(currentPattern, patternlab); - lineage_hunter.find_lineage(currentPattern, patternlab); - - test.equals(currentPattern.lineageIndex.length, 1); - test.equals(currentPattern.lineageIndex[0], "atoms-error"); - test.equals(patternlab.patterns[0].lineageRIndex.length, 1); - test.equals(JSON.parse(patternlab.patterns[0].lineageR).lineagePattern, 'molecules-error'); - - test.done(); - } - - }; + "use strict"; + + var lh = require('../core/lib/lineage_hunter'); + var pa = require('../core/lib/pattern_assembler'); + var object_factory = require('../core/lib/object_factory'); + + var fs = require('fs-extra'); + var pattern_assembler = new pa(); + var lineage_hunter = new lh(); + + function createBasePatternLabObject() { + var patterns_dir = './test/files/_patterns/'; + var pl = {}; + pl.config = { + paths: { + source: { + patterns: patterns_dir + } + } + }; + pl.data = {}; + pl.data.link = {}; + pl.config.debug = false; + pl.patterns = []; + pl.partials = {}; + pl.config.patternStateCascade = ["inprogress", "inreview", "complete"]; + return pl; + } + + exports['lineage hunter '] = { + 'find_lineage - finds lineage' : function(test){ + + //setup current pattern from what we would have during execution + var currentPattern = { + "name": "02-organisms-00-global-00-header", + "subdir": "02-organisms\\00-global", + "filename": "00-header.mustache", + "data": null, + "template": "\r\n
\r\n\t{{> atoms-logo }}\r\n\tSearch\r\n\tMenu\r\n\t{{> molecules-primary-nav }}\r\n\t{{> molecules-search }}\r\n
\r\n\r\n", + "patternPartial": "\r\n
\r\n\"Logo\tSearch\r\n\tMenu\r\n\r\n
\r\n
\r\n\t Search\r\n\t \r\n\t \r\n\t \r\n
\r\n
\r\n\r\n", + "patternName": "header", + "patternLink": "02-organisms-00-global-00-header/02-organisms-00-global-00-header.html", + "patternGroup": "organisms", + "patternSubGroup": "organisms\\00-global", + "flatPatternPath": "02-organisms\\00-global", + "key": "organisms-header", + "patternState": "", + "lineage": [], + "lineageIndex": [], + "lineageR": [], + "lineageRIndex": [] + }; + var patternlab = { + patterns: [ + { + "name": "00-atoms-03-images-00-logo", + "subdir": "00-atoms\\03-images", + "filename": "00-logo.mustache", + "data": null, + "template": "\"Logo", + "patternPartial": "\"Logo", + "patternName": "logo", + "patternLink": "00-atoms-03-images-00-logo/00-atoms-03-images-00-logo.html", + "patternGroup": "atoms", + "patternSubGroup": "atoms\\03-images", + "flatPatternPath": "00-atoms\\03-images", + "key": "atoms-logo", + "patternState": "", + "lineage": [], + "lineageIndex": [], + "lineageR": [], + "lineageRIndex": [] + }, + { + "name": "01-molecules-05-navigation-00-primary-nav", + "subdir": "01-molecules\\05-navigation", + "filename": "00-primary-nav.mustache", + "data": null, + "template": "\r\n", + "patternPartial": "\r\n", + "patternName": "primary-nav", + "patternLink": "01-molecules-05-navigation-00-primary-nav/01-molecules-05-navigation-00-primary-nav.html", + "patternGroup": "molecules", + "patternSubGroup": "molecules\\05-navigation", + "flatPatternPath": "01-molecules\\05-navigation", + "key": "molecules-primary-nav", + "patternState": "", + "lineage": [], + "lineageIndex": [], + "lineageR": [], + "lineageRIndex": [] + }, + { + "name": "01-molecules-04-forms-00-search", + "subdir": "01-molecules\\04-forms", + "filename": "00-search.mustache", + "data": null, + "template": "
\r\n
\r\n\t Search\r\n\t \r\n\t \r\n\t \r\n
\r\n
", + "patternPartial": "
\r\n
\r\n\t Search\r\n\t \r\n\t \r\n\t \r\n
\r\n
", + "patternName": "search", + "patternLink": "01-molecules-04-forms-00-search/01-molecules-04-forms-00-search.html", + "patternGroup": "molecules", + "patternSubGroup": "molecules\\04-forms", + "flatPatternPath": "01-molecules\\04-forms", + "key": "molecules-search", + "patternState": "", + "lineage": [], + "lineageIndex": [], + "lineageR": [], + "lineageRIndex": [] + } + ] + }; + + lineage_hunter.find_lineage(currentPattern, patternlab); + + test.equals(currentPattern.lineageIndex.length, 3); + test.equals(currentPattern.lineageIndex[0], "atoms-logo"); + test.equals(currentPattern.lineageIndex[1], "molecules-primary-nav"); + test.equals(currentPattern.lineageIndex[2], "molecules-search"); + + test.done(); + }, + + 'find_lineage - 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", + "key": "molecules-error", + "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": "

{{message}}

", + "patternPartial": "

{{message}}

", + "patternName": "error", + "patternLink": "01-atoms-05-alerts-00-error/01-atoms-05-alerts-00-error.html", + "patternGroup": "atoms", + "patternSubGroup": "atoms\\05-alerts", + "flatPatternPath": "01-atoms\\05-alerts", + "key": "atoms-error", + "patternState": "", + "lineage": [], + "lineageIndex": [], + "lineageR": [], + "lineageRIndex": [] + } + ] + }; + + lineage_hunter.find_lineage(currentPattern, patternlab); + + test.equals(currentPattern.lineageIndex.length, 1); + test.equals(currentPattern.lineageIndex[0], "atoms-error"); + + test.done(); + }, + + 'find_lineage - finds lineage with unspaced 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", + "key": "molecules-error", + "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": "

{{message}}

", + "patternPartial": "

{{message}}

", + "patternName": "error", + "patternLink": "01-atoms-05-alerts-00-error/01-atoms-05-alerts-00-error.html", + "patternGroup": "atoms", + "patternSubGroup": "atoms\\05-alerts", + "flatPatternPath": "01-atoms\\05-alerts", + "key": "atoms-error", + "patternState": "", + "lineage": [], + "lineageIndex": [], + "lineageR": [], + "lineageRIndex": [] + } + ] + }; + + lineage_hunter.find_lineage(currentPattern, patternlab); + + test.equals(currentPattern.lineageIndex.length, 1); + test.equals(currentPattern.lineageIndex[0], "atoms-error"); + test.equals(patternlab.patterns[0].lineageRIndex.length, 1); + test.equals(patternlab.patterns[0].lineageR[0].lineagePattern, 'molecules-error'); + + test.done(); + }, + + 'find_lineage - finds lineage with spaced styleModifier' : 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:foo }}", + "patternPartial": "{{> atoms-error:foo }}", + "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", + "key": "molecules-error", + "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": "

{{message}}

", + "patternPartial": "

{{message}}

", + "patternName": "error", + "patternLink": "01-atoms-05-alerts-00-error/01-atoms-05-alerts-00-error.html", + "patternGroup": "atoms", + "patternSubGroup": "atoms\\05-alerts", + "flatPatternPath": "01-atoms\\05-alerts", + "key": "atoms-error", + "patternState": "", + "lineage": [], + "lineageIndex": [], + "lineageR": [], + "lineageRIndex": [] + } + ] + }; + + lineage_hunter.find_lineage(currentPattern, patternlab); + + test.equals(currentPattern.lineageIndex.length, 1); + test.equals(currentPattern.lineageIndex[0], "atoms-error"); + + test.done(); + }, + + 'find_lineage - finds lineage with unspaced styleModifier' : 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:foo }}", + "patternPartial": "{{>atoms-error:foo}}", + "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", + "key": "molecules-error", + "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": "

{{message}}

", + "patternPartial": "

{{message}}

", + "patternName": "error", + "patternLink": "01-atoms-05-alerts-00-error/01-atoms-05-alerts-00-error.html", + "patternGroup": "atoms", + "patternSubGroup": "atoms\\05-alerts", + "flatPatternPath": "01-atoms\\05-alerts", + "key": "atoms-error", + "patternState": "", + "lineage": [], + "lineageIndex": [], + "lineageR": [], + "lineageRIndex": [] + } + ] + }; + + lineage_hunter.find_lineage(currentPattern, patternlab); + + test.equals(currentPattern.lineageIndex.length, 1); + test.equals(currentPattern.lineageIndex[0], "atoms-error"); + + test.done(); + }, + + 'find_lineage - finds lineage with fuzzy partial with styleModifier' : 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-e:foo }}", + "patternPartial": "{{>atoms-e:foo}}", + "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", + "key": "molecules-error", + "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": "

{{message}}

", + "patternPartial": "

{{message}}

", + "patternName": "error", + "patternLink": "01-atoms-05-alerts-00-error/01-atoms-05-alerts-00-error.html", + "patternGroup": "atoms", + "patternSubGroup": "atoms\\05-alerts", + "flatPatternPath": "01-atoms\\05-alerts", + "key": "atoms-error", + "patternState": "", + "lineage": [], + "lineageIndex": [], + "lineageR": [], + "lineageRIndex": [] + } + ] + }; + + lineage_hunter.find_lineage(currentPattern, patternlab); + + test.equals(currentPattern.lineageIndex.length, 1); + test.equals(currentPattern.lineageIndex[0], "atoms-error"); + + test.done(); + }, + + 'find_lineage - does not apply lineage twice' : 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", + "key": "molecules-error", + "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": "

{{message}}

", + "patternPartial": "

{{message}}

", + "patternName": "error", + "patternLink": "01-atoms-05-alerts-00-error/01-atoms-05-alerts-00-error.html", + "patternGroup": "atoms", + "patternSubGroup": "atoms\\05-alerts", + "flatPatternPath": "01-atoms\\05-alerts", + "key": "atoms-error", + "patternState": "", + "lineage": [], + "lineageIndex": [], + "lineageR": [], + "lineageRIndex": [] + } + ] + }; + + lineage_hunter.find_lineage(currentPattern, patternlab); + lineage_hunter.find_lineage(currentPattern, patternlab); + + test.equals(currentPattern.lineageIndex.length, 1); + test.equals(currentPattern.lineageIndex[0], "atoms-error"); + test.equals(patternlab.patterns[0].lineageRIndex.length, 1); + test.equals(patternlab.patterns[0].lineageR[0].lineagePattern, 'molecules-error'); + + test.done(); + }, + + 'cascade_pattern_states promotes a lower pattern state up to the consumer' : function(test){ + //arrange + var pl = createBasePatternLabObject(); + pl.config.patternStates = { + "test-foo" : "complete", + "test-bar" : "inreview" + }; + + var atomPattern = new object_factory.oPattern('test/files/_patterns/00-test/01-bar.mustache', '00-test', '01-bar.mustache'); + atomPattern.template = fs.readFileSync(pl.config.paths.source.patterns + '00-test/01-bar.mustache', 'utf8'); + atomPattern.extendedTemplate = atomPattern.template; + + pattern_assembler.setPatternState(atomPattern, pl); + pattern_assembler.addPattern(atomPattern, pl); + + var consumerPattern = new object_factory.oPattern('test/files/_patterns/00-test/00-foo.mustache', '00-test', '00-foo.mustache'); + consumerPattern.template = fs.readFileSync(pl.config.paths.source.patterns + '00-test/00-foo.mustache', 'utf8'); + consumerPattern.extendedTemplate = consumerPattern.template; + pattern_assembler.setPatternState(consumerPattern, pl); + pattern_assembler.addPattern(consumerPattern, pl); + + lineage_hunter.find_lineage(consumerPattern, pl); + + //act + lineage_hunter.cascade_pattern_states(pl); + + //assert + var consumerPatternReturned = pattern_assembler.get_pattern_by_key('test-foo', pl); + test.equals(consumerPatternReturned.patternState, 'inreview'); + test.done(); + }, + + 'cascade_pattern_states promotes a lower pattern state up to the consumers lineage' : function(test){ + //arrange + var pl = createBasePatternLabObject(); + pl.config.patternStates = { + "test-foo" : "complete", + "test-bar" : "inreview" + }; + + var atomPattern = new object_factory.oPattern('test/files/_patterns/00-test/01-bar.mustache', '00-test', '01-bar.mustache'); + atomPattern.template = fs.readFileSync(pl.config.paths.source.patterns + '00-test/01-bar.mustache', 'utf8'); + atomPattern.extendedTemplate = atomPattern.template; + + pattern_assembler.setPatternState(atomPattern, pl); + pattern_assembler.addPattern(atomPattern, pl); + + var consumerPattern = new object_factory.oPattern('test/files/_patterns/00-test/00-foo.mustache', '00-test', '00-foo.mustache'); + consumerPattern.template = fs.readFileSync(pl.config.paths.source.patterns + '00-test/00-foo.mustache', 'utf8'); + consumerPattern.extendedTemplate = consumerPattern.template; + pattern_assembler.setPatternState(consumerPattern, pl); + pattern_assembler.addPattern(consumerPattern, pl); + + lineage_hunter.find_lineage(consumerPattern, pl); + + //act + lineage_hunter.cascade_pattern_states(pl); + + //assert + var consumerPatternReturned = pattern_assembler.get_pattern_by_key('test-foo', pl); + test.equals(consumerPatternReturned.lineage[0].lineageState, 'inreview'); + test.done(); + }, + + 'cascade_pattern_states sets the pattern state on any lineage patterns reverse lineage' : function(test){ + //arrange + var pl = createBasePatternLabObject(); + pl.config.patternStates = { + "test-foo" : "complete", + "test-bar" : "inreview" + }; + + var atomPattern = new object_factory.oPattern('test/files/_patterns/00-test/01-bar.mustache', '00-test', '01-bar.mustache'); + atomPattern.template = fs.readFileSync(pl.config.paths.source.patterns + '00-test/01-bar.mustache', 'utf8'); + atomPattern.extendedTemplate = atomPattern.template; + + pattern_assembler.setPatternState(atomPattern, pl); + pattern_assembler.addPattern(atomPattern, pl); + + var consumerPattern = new object_factory.oPattern('test/files/_patterns/00-test/00-foo.mustache', '00-test', '00-foo.mustache'); + consumerPattern.template = fs.readFileSync(pl.config.paths.source.patterns + '00-test/00-foo.mustache', 'utf8'); + consumerPattern.extendedTemplate = consumerPattern.template; + pattern_assembler.setPatternState(consumerPattern, pl); + pattern_assembler.addPattern(consumerPattern, pl); + + lineage_hunter.find_lineage(consumerPattern, pl); + + //act + lineage_hunter.cascade_pattern_states(pl); + + //assert + var consumedPatternReturned = pattern_assembler.get_pattern_by_key('test-bar', pl); + test.equals(consumedPatternReturned.lineageR[0].lineageState, 'inreview'); + + test.done(); + }, + + 'cascade_pattern_states does not promote lower pattern state when consumer does not display its own state' : function(test){ + //arrange + var pl = createBasePatternLabObject(); + pl.config.patternStates = { + "test-bar" : "inreview" + }; + + var atomPattern = new object_factory.oPattern('test/files/_patterns/00-test/01-bar.mustache', '00-test', '01-bar.mustache'); + atomPattern.template = fs.readFileSync(pl.config.paths.source.patterns + '00-test/01-bar.mustache', 'utf8'); + atomPattern.extendedTemplate = atomPattern.template; + + pattern_assembler.setPatternState(atomPattern, pl); + pattern_assembler.addPattern(atomPattern, pl); + + var consumerPattern = new object_factory.oPattern('test/files/_patterns/00-test/00-foo.mustache', '00-test', '00-foo.mustache'); + consumerPattern.template = fs.readFileSync(pl.config.paths.source.patterns + '00-test/00-foo.mustache', 'utf8'); + consumerPattern.extendedTemplate = consumerPattern.template; + pattern_assembler.setPatternState(consumerPattern, pl); + pattern_assembler.addPattern(consumerPattern, pl); + + lineage_hunter.find_lineage(consumerPattern, pl); + + //act + lineage_hunter.cascade_pattern_states(pl); + + //assert + var consumerPatternReturned = pattern_assembler.get_pattern_by_key('test-foo', pl); + test.equals(consumerPatternReturned.lineage.length, 1); + test.equals(consumerPatternReturned.lineage[0].lineageState, 'inreview'); + test.equals(consumerPatternReturned.patternState, ''); + test.done(); + } + + }; }()); diff --git a/test/pattern_assembler_tests.js b/test/pattern_assembler_tests.js index 14d6cc3f7..d85933a92 100644 --- a/test/pattern_assembler_tests.js +++ b/test/pattern_assembler_tests.js @@ -576,10 +576,10 @@ var patternlab = {}; patternlab.config = {}; patternlab.config.patternStates = {}; - patternlab.config.patternStates["homepage-emergency"] = "inprogress"; + patternlab.config.patternStates["pages-homepage-emergency"] = "inprogress"; var pattern = { - patternName: "homepage-emergency" + key: "pages-homepage-emergency" }; //act @@ -596,10 +596,10 @@ var patternlab = {}; patternlab.config = {}; patternlab.config.patternStates = {}; - patternlab.config.patternStates["homepage-emergency"] = "inprogress"; + patternlab.config.patternStates["pages-homepage-emergency"] = "inprogress"; var pattern = { - patternName: "homepage" + patternName: "pages-homepage" }; //act From 5090a2639218b951728c231ff81fe2f5c0fa3fb8 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Wed, 9 Mar 2016 21:55:38 -0600 Subject: [PATCH 34/37] futher clarify pattern states --- README.md | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 398df1c2a..307a5bd06 100644 --- a/README.md +++ b/README.md @@ -144,8 +144,7 @@ The current selection is as follows. } ``` ##### Pattern States -You can set the state of a pattern by including it in `patternlab-config.json` too. The out of the box styles are in progress (orange), in review (yellow), and complete (green). -Pattern states should be lowercase and use hyphens where spaces are present. +You can set the state of a pattern by including its key in the `patternStates` object in `patternlab-config.json`, along with a style defined inside `patternStateCascade`. The out of the box styles are in progress (orange), in review (yellow), and complete (green). ``` "patternStates": { "atoms-colors" : "complete", @@ -168,6 +167,30 @@ In this case, two things are of note: * templates-article will display inreview since it inherits `organisms-sticky-comment` * pages-article will not display any pattern state, as it does not define one +The `patternStateCascade` array is important in that the order is hierarchical. +The default is below: + +``` +"patternStateCascade": ["inprogress", "inreview", "complete"], +``` + +which correspond to classes defined inside `./core/styleguide/css/styleguide.css` + +``` +/* pattern states */ +.inprogress:before { + color: #FF4136 !important; +} + +.inreview:before { + color: #FFCC00 !important; +} + +.complete:before { + color: #2ECC40 !important; +} +``` + ##### Pattern Export `patternlab-config.json` also has two properties that work together to export completed patterns for use in a production environment. Provide an array of keys and an output directory. Pattern Lab doesn't ship with any pattern export keys, but the default directory is `"./pattern_exports/"` created inside the install directory. From 9ceb4ed1360583d48f56798c9e993156f2dd1099 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Wed, 9 Mar 2016 22:01:42 -0600 Subject: [PATCH 35/37] fix an errant typo in a unit test --- test/pattern_assembler_tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/pattern_assembler_tests.js b/test/pattern_assembler_tests.js index d85933a92..2b42a95e6 100644 --- a/test/pattern_assembler_tests.js +++ b/test/pattern_assembler_tests.js @@ -599,7 +599,7 @@ patternlab.config.patternStates["pages-homepage-emergency"] = "inprogress"; var pattern = { - patternName: "pages-homepage" + key: "pages-homepage" }; //act From f7e0a792ecb45899e23a2204f122bc381bc54a49 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Thu, 10 Mar 2016 23:26:47 -0600 Subject: [PATCH 36/37] update package.json with version bump --- core/lib/lineage_hunter.js | 12 ++++++------ core/lib/list_item_hunter.js | 12 ++++++------ core/lib/media_hunter.js | 12 ++++++------ core/lib/object_factory.js | 2 +- core/lib/parameter_hunter.js | 12 ++++++------ core/lib/pattern_assembler.js | 12 ++++++------ core/lib/pattern_exporter.js | 12 ++++++------ core/lib/patternlab.js | 12 ++++++------ core/lib/patternlab_grunt.js | 2 +- core/lib/patternlab_gulp.js | 12 ++++++------ core/lib/pseudopattern_hunter.js | 12 ++++++------ core/lib/style_modifier_hunter.js | 12 ++++++------ package.gulp.json | 2 +- package.json | 2 +- 14 files changed, 64 insertions(+), 64 deletions(-) diff --git a/core/lib/lineage_hunter.js b/core/lib/lineage_hunter.js index 6463c038c..e5367f2e0 100644 --- a/core/lib/lineage_hunter.js +++ b/core/lib/lineage_hunter.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v1.1.3 - 2016 - * +/* + * patternlab-node - v1.2.0 - 2016 + * * 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/core/lib/list_item_hunter.js b/core/lib/list_item_hunter.js index 7fcf3d188..2b08ef2f1 100644 --- a/core/lib/list_item_hunter.js +++ b/core/lib/list_item_hunter.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v1.1.3 - 2016 - * +/* + * patternlab-node - v1.2.0 - 2016 + * * 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/core/lib/media_hunter.js b/core/lib/media_hunter.js index e8de9a81f..62a02ad5a 100644 --- a/core/lib/media_hunter.js +++ b/core/lib/media_hunter.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v1.1.3 - 2016 - * +/* + * patternlab-node - v1.2.0 - 2016 + * * 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/core/lib/object_factory.js b/core/lib/object_factory.js index c1e44ac38..28a4af057 100644 --- a/core/lib/object_factory.js +++ b/core/lib/object_factory.js @@ -1,5 +1,5 @@ /* - * patternlab-node - v1.1.3 - 2016 + * patternlab-node - v1.2.0 - 2016 * * Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. diff --git a/core/lib/parameter_hunter.js b/core/lib/parameter_hunter.js index 2f8738034..9567f2a46 100644 --- a/core/lib/parameter_hunter.js +++ b/core/lib/parameter_hunter.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v1.1.3 - 2016 - * +/* + * patternlab-node - v1.2.0 - 2016 + * * 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/core/lib/pattern_assembler.js b/core/lib/pattern_assembler.js index df6129c30..869b1986c 100644 --- a/core/lib/pattern_assembler.js +++ b/core/lib/pattern_assembler.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v1.1.3 - 2016 - * +/* + * patternlab-node - v1.2.0 - 2016 + * * 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/core/lib/pattern_exporter.js b/core/lib/pattern_exporter.js index 23c9777a4..ff53cac6c 100644 --- a/core/lib/pattern_exporter.js +++ b/core/lib/pattern_exporter.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v1.1.3 - 2016 - * +/* + * patternlab-node - v1.2.0 - 2016 + * * 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/core/lib/patternlab.js b/core/lib/patternlab.js index 45e8b4e05..cc910a5bc 100644 --- a/core/lib/patternlab.js +++ b/core/lib/patternlab.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v1.1.3 - 2016 - * +/* + * patternlab-node - v1.2.0 - 2016 + * * 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/core/lib/patternlab_grunt.js b/core/lib/patternlab_grunt.js index 69085c291..d124a7e0e 100644 --- a/core/lib/patternlab_grunt.js +++ b/core/lib/patternlab_grunt.js @@ -1,5 +1,5 @@ /* - * patternlab-node - v1.1.3 - 2016 + * patternlab-node - v1.2.0 - 2016 * * Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. diff --git a/core/lib/patternlab_gulp.js b/core/lib/patternlab_gulp.js index 82cf2a4ce..be02179cf 100644 --- a/core/lib/patternlab_gulp.js +++ b/core/lib/patternlab_gulp.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v1.1.3 - 2016 - * +/* + * patternlab-node - v1.2.0 - 2016 + * * 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/core/lib/pseudopattern_hunter.js b/core/lib/pseudopattern_hunter.js index 6366be9e8..053e520c3 100644 --- a/core/lib/pseudopattern_hunter.js +++ b/core/lib/pseudopattern_hunter.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v1.1.3 - 2016 - * +/* + * patternlab-node - v1.2.0 - 2016 + * * 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/core/lib/style_modifier_hunter.js b/core/lib/style_modifier_hunter.js index 742009ce4..b6f870074 100644 --- a/core/lib/style_modifier_hunter.js +++ b/core/lib/style_modifier_hunter.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v1.1.3 - 2016 - * +/* + * patternlab-node - v1.2.0 - 2016 + * * 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/package.gulp.json b/package.gulp.json index 3bb48a781..be9f8ddc4 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": "1.1.3", + "version": "1.2.0", "main": "./core/lib/patternlab.js", "dependencies": { "del": "^2.2.0", diff --git a/package.json b/package.json index 68c810687..588f19d60 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": "1.1.3", + "version": "1.2.0", "main": "./core/lib/patternlab.js", "dependencies": { "diveSync": "^0.3.0", From c53440a73838fa4bdef97624ae2d8ef42e6cdd71 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Thu, 10 Mar 2016 23:46:11 -0600 Subject: [PATCH 37/37] add js directory to watch:all grunt task --- Gruntfile.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index 83cdbb4c8..2fbe7d31f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -88,7 +88,8 @@ module.exports = function (grunt) { path.resolve(paths().source.patterns + '**/*.json'), path.resolve(paths().source.fonts + '/*'), path.resolve(paths().source.images + '/*'), - path.resolve(paths().source.data + '*.json') + path.resolve(paths().source.data + '*.json'), + path.resolve(paths().source.js + '/*.js') ], tasks: ['default', 'bsReload:css'] }