From e69805683d5d9c5cfdcd5c395db6cbd026ed1c06 Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Wed, 17 Aug 2016 15:02:55 -0500 Subject: [PATCH 01/13] Fix missing outputFileSuffix blobs and update defaults to match edition --- core/lib/patternlab.js | 16 ++++++++-------- patternlab-config.json | 7 ++++++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/core/lib/patternlab.js b/core/lib/patternlab.js index ddc8aaa8b..bb2cb45b7 100644 --- a/core/lib/patternlab.js +++ b/core/lib/patternlab.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v2.4.2 - 2016 - * +/* + * patternlab-node - v2.4.2 - 2016 + * * Brian Muenzenmeyer, Geoff Pursell, 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. * */ @@ -60,10 +60,10 @@ function processAllPatternsRecursive(pattern_assembler, patterns_dir, patternlab function checkConfiguration(patternlab) { //default the output suffixes if not present var outputFileSuffixes = { - rendered: '', + rendered: '.rendered', rawTemplate: '', markupOnly: '.markup-only' - } + }; if (!patternlab.config.outputFileSuffixes) { plutils.logOrange('Configuration Object "outputFileSuffixes" not found, and defaulted to the following:'); diff --git a/patternlab-config.json b/patternlab-config.json index b3f2d975b..5292c76bd 100644 --- a/patternlab-config.json +++ b/patternlab-config.json @@ -54,5 +54,10 @@ }, "patternExportPatternPartials": [], "patternExportDirectory": "./pattern_exports/", - "cacheBust": true + "cacheBust": true, + "outputFileSuffixes": { + "rendered": ".rendered", + "rawTemplate": "", + "markupOnly": ".markup-only" + } } From 80c9c97c3392f0cec270107230e08bac9c010c81 Mon Sep 17 00:00:00 2001 From: Brian Muenzenmeyer Date: Thu, 18 Aug 2016 09:24:00 -0500 Subject: [PATCH 02/13] experimenting with travis install of all engines part of #438 --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index c185e08d3..31175d78f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,11 +11,15 @@ before_install: before_script: - npm install -g grunt-cli + - npm install patternengine-node-underscore + - npm install patternengine-node-handlebars + - npm install patternengine-node-twig branches: only: - master - dev + - 438-runAllTestsTravis notifications: webhooks: From 1ceeec57154b5625f6984bb737747b2f4b780a9f Mon Sep 17 00:00:00 2001 From: Brian Muenzenmeyer Date: Thu, 18 Aug 2016 09:27:19 -0500 Subject: [PATCH 03/13] fix branch path --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 31175d78f..844871fce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ branches: only: - master - dev - - 438-runAllTestsTravis + - issue/438-runAllTestsTravis notifications: webhooks: From 1935b1cc460e350ded2dda0af145127cb1def838 Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Thu, 18 Aug 2016 09:36:16 -0500 Subject: [PATCH 04/13] replace pattern.patternLink with pattern.getPatternLink(pl) to output correct static file paths; add and fix unit tests --- core/lib/lineage_hunter.js | 5 +- core/lib/object_factory.js | 20 +++- core/lib/pattern_assembler.js | 2 +- core/lib/patternlab.js | 6 +- test/lineage_hunter_tests.js | 83 +++++++++++++---- test/object_factory_tests.js | 167 ++++++++++++++++++++-------------- 6 files changed, 185 insertions(+), 98 deletions(-) diff --git a/core/lib/lineage_hunter.js b/core/lib/lineage_hunter.js index e74e4a6c9..5dbb26a91 100644 --- a/core/lib/lineage_hunter.js +++ b/core/lib/lineage_hunter.js @@ -22,8 +22,9 @@ var lineage_hunter = function () { //create the more complex patternLineage object too var l = { "lineagePattern": ancestorPattern.patternPartial, - "lineagePath": "../../patterns/" + ancestorPattern.patternLink + "lineagePath": "../../patterns/" + ancestorPattern.getPatternLink(patternlab) }; + if (ancestorPattern.patternState) { l.lineageState = ancestorPattern.patternState; } @@ -37,7 +38,7 @@ var lineage_hunter = function () { //create the more complex patternLineage object in reverse var lr = { "lineagePattern": pattern.patternPartial, - "lineagePath": "../../patterns/" + pattern.patternLink + "lineagePath": "../../patterns/" + pattern.getPatternLink(patternlab) }; if (pattern.patternState) { lr.lineageState = pattern.patternState; diff --git a/core/lib/object_factory.js b/core/lib/object_factory.js index e277c510d..839182d06 100644 --- a/core/lib/object_factory.js +++ b/core/lib/object_factory.js @@ -29,10 +29,6 @@ var Pattern = function (relPath, data) { 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 - // calculated path from the root of the public directory to the generated html - // file for this pattern - this.patternLink = this.name + path.sep + this.name + '.html'; // '00-atoms-00-global-00-colors/00-atoms-00-global-00-colors.html' - // the top-level pattern group this pattern belongs to. 'atoms' this.patternGroup = this.subdir.split(path.sep)[0].replace(/^\d*-/, ''); @@ -84,6 +80,22 @@ Pattern.prototype = { } }, + // calculated path from the root of the public directory to the generated html + // file for this pattern. + // Should look something like '00-atoms-00-global-00-colors/00-atoms-00-global-00-colors.html' + getPatternLink: function (patternlab, suffixType) { + // if no suffixType is provided, we default to rendered + var suffixConfig = patternlab.config.outputFileSuffixes; + var suffix = suffixType ? suffixConfig[suffixType] : suffixConfig.rendered; + + if (this.patternLink) { + // Someone or something has explicitly set a patternLink on this pattern. + // We had better respect that. + return this.patternLink; + } + return this.name + path.sep + this.name + suffix + '.html'; + }, + // the finders all delegate to the PatternEngine, which also encapsulates all // appropriate regexes findPartials: function () { diff --git a/core/lib/pattern_assembler.js b/core/lib/pattern_assembler.js index 532d88f9d..96cb371a9 100644 --- a/core/lib/pattern_assembler.js +++ b/core/lib/pattern_assembler.js @@ -94,7 +94,7 @@ var pattern_assembler = function () { function addPattern(pattern, patternlab) { //add the link to the global object - patternlab.data.link[pattern.patternPartial] = '/patterns/' + pattern.patternLink.replace('.html', patternlab.config.outputFileSuffixes.rendered + '.html'); + patternlab.data.link[pattern.patternPartial] = '/patterns/' + pattern.getPatternLink(patternlab); //only push to array if the array doesn't contain this pattern var isNew = true; diff --git a/core/lib/patternlab.js b/core/lib/patternlab.js index bb2cb45b7..d852fc6ce 100644 --- a/core/lib/patternlab.js +++ b/core/lib/patternlab.js @@ -355,13 +355,13 @@ var patternlab_engine = function (config) { //write the compiled template to the public patterns directory var patternPage = headHTML + pattern.patternPartialCode + footerHTML; - fs.outputFileSync(paths.public.patterns + pattern.patternLink.replace('.html', patternlab.config.outputFileSuffixes.rendered + '.html'), patternPage); + fs.outputFileSync(paths.public.patterns + pattern.getPatternLink(patternlab, 'rendered'), patternPage); //write the mustache file too - fs.outputFileSync(paths.public.patterns + pattern.patternLink.replace('.html', patternlab.config.outputFileSuffixes.rawTemplate + pattern.fileExtension), pattern.template); + fs.outputFileSync(paths.public.patterns + pattern.getPatternLink(patternlab, 'rawTemplate'), pattern.template); //write the encoded version too - fs.outputFileSync(paths.public.patterns + pattern.patternLink.replace('.html', patternlab.config.outputFileSuffixes.markupOnly + '.html'), pattern.patternPartialCode); + fs.outputFileSync(paths.public.patterns + pattern.getPatternLink(patternlab, 'markupOnly'), pattern.patternPartialCode); return true; }); diff --git a/test/lineage_hunter_tests.js b/test/lineage_hunter_tests.js index 39a0bb1b2..aa77de5f1 100644 --- a/test/lineage_hunter_tests.js +++ b/test/lineage_hunter_tests.js @@ -30,15 +30,18 @@ function createBasePatternLabObject() { } }, outputFileSuffixes: { - rendered: '' - } + rendered: '.rendered', + rawTemplate: '', + markupOnly: '.markup-only' + }, + patternStateCascade: ["inprogress", "inreview", "complete"] }; pl.data = {}; pl.data.link = {}; pl.config.debug = false; pl.patterns = []; pl.partials = {}; - pl.config.patternStateCascade = ["inprogress", "inreview", "complete"]; + return pl; } @@ -57,7 +60,7 @@ exports['lineage hunter '] = { var patternlab = { patterns: [ - { + Pattern.createEmpty({ "name": "00-atoms-03-images-00-logo", "subdir": "00-atoms\\03-images", "filename": "00-logo.mustache", @@ -75,8 +78,8 @@ exports['lineage hunter '] = { "lineageIndex": [], "lineageR": [], "lineageRIndex": [] - }, - { + }), + Pattern.createEmpty({ "name": "01-molecules-05-navigation-00-primary-nav", "subdir": "01-molecules\\05-navigation", "filename": "00-primary-nav.mustache", @@ -94,8 +97,8 @@ exports['lineage hunter '] = { "lineageIndex": [], "lineageR": [], "lineageRIndex": [] - }, - { + }), + Pattern.createEmpty({ "name": "01-molecules-04-forms-00-search", "subdir": "01-molecules\\04-forms", "filename": "00-search.mustache", @@ -113,11 +116,13 @@ exports['lineage hunter '] = { "lineageIndex": [], "lineageR": [], "lineageRIndex": [] - } + }) ], config: { outputFileSuffixes: { - rendered: '' + rendered: '.rendered', + rawTemplate: '', + markupOnly: '.markup-only' } } }; @@ -150,7 +155,14 @@ exports['lineage hunter '] = { "template": "

{{message}}

", "extendedTemplate": "

{{message}}

" }) - ] + ], + config: { + outputFileSuffixes: { + rendered: '.rendered', + rawTemplate: '', + markupOnly: '.markup-only' + } + } }; lineage_hunter.find_lineage(currentPattern, patternlab); @@ -286,7 +298,7 @@ exports['lineage hunter '] = { var patternlab = { patterns: [ - { + Pattern.createEmpty({ "name": "01-atoms-05-alerts-00-error", "subdir": "01-atoms\\05-alerts", "filename": "00-error.mustache", @@ -304,8 +316,15 @@ exports['lineage hunter '] = { "lineageIndex": [], "lineageR": [], "lineageRIndex": [] + }) + ], + config: { + outputFileSuffixes: { + rendered: '.rendered', + rawTemplate: '', + markupOnly: '.markup-only' } - ] + } }; var lineage_hunter = new lh(); @@ -361,7 +380,14 @@ exports['lineage hunter '] = { "lineageR": [], "lineageRIndex": [] }) - ] + ], + config: { + outputFileSuffixes: { + rendered: '.rendered', + rawTemplate: '', + markupOnly: '.markup-only' + } + } }; var lineage_hunter = new lh(); @@ -415,7 +441,14 @@ exports['lineage hunter '] = { "lineageR": [], "lineageRIndex": [] }) - ] + ], + config: { + outputFileSuffixes: { + rendered: '.rendered', + rawTemplate: '', + markupOnly: '.markup-only' + } + } }; var lineage_hunter = new lh(); @@ -469,7 +502,14 @@ exports['lineage hunter '] = { "lineageR": [], "lineageRIndex": [] }) - ] + ], + config: { + outputFileSuffixes: { + rendered: '.rendered', + rawTemplate: '', + markupOnly: '.markup-only' + } + } }; var lineage_hunter = new lh(); @@ -490,7 +530,7 @@ exports['lineage hunter '] = { }); var patternlab = { patterns: [ - { + Pattern.createEmpty({ "name": "01-atoms-05-alerts-00-error", "subdir": "01-atoms\\05-alerts", "filename": "00-error.mustache", @@ -508,8 +548,15 @@ exports['lineage hunter '] = { "lineageIndex": [], "lineageR": [], "lineageRIndex": [] + }) + ], + config: { + outputFileSuffixes: { + rendered: '.rendered', + rawTemplate: '', + markupOnly: '.markup-only' } - ] + } }; var lineage_hunter = new lh(); diff --git a/test/object_factory_tests.js b/test/object_factory_tests.js index b3fb433cb..5875d78d7 100644 --- a/test/object_factory_tests.js +++ b/test/object_factory_tests.js @@ -1,74 +1,101 @@ -(function () { "use strict"; - var of = require('../core/lib/object_factory'); - var Pattern = require('../core/lib/object_factory').Pattern; - var path = require('path'); - - exports['Pattern initialization'] = { - 'test Pattern initializes correctly' : function (test) { - var p = new Pattern('00-atoms/00-global/00-colors.mustache', { d: 123}); - test.equals(p.relPath, '00-atoms' + path.sep + '00-global' + path.sep + '00-colors.mustache'); - test.equals(p.name, '00-atoms-00-global-00-colors'); - test.equals(p.subdir, '00-atoms' + path.sep + '00-global'); - test.equals(p.fileName, '00-colors'); - test.equals(p.fileExtension, '.mustache'); - test.equals(p.jsonFileData.d, 123); - test.equals(p.patternBaseName, 'colors'); - test.equals(p.patternName, 'Colors'); - test.equals(p.patternLink, '00-atoms-00-global-00-colors' + path.sep + '00-atoms-00-global-00-colors.html'); - test.equals(p.patternGroup, 'atoms'); - test.equals(p.patternSubGroup, 'global'); - test.equals(p.flatPatternPath, '00-atoms-00-global'); - test.equals(p.patternPartial, 'atoms-colors'); - test.equals(p.template, ''); - test.equals(p.patternPartialCode, ''); - test.equals(p.lineage.length, 0); - test.equals(p.lineageIndex.length, 0); - test.equals(p.lineageR.length, 0); - test.equals(p.lineageRIndex.length, 0); - test.equals(p.patternState, ''); - test.done(); - }, - 'test Pattern with one-directory subdir works as expected' : function (test) { - var p = new Pattern('00-atoms/00-colors.mustache', { d: 123}); - test.equals(p.relPath, '00-atoms' + path.sep + '00-colors.mustache'); - test.equals(p.name, '00-atoms-00-colors'); - test.equals(p.subdir, '00-atoms'); - test.equals(p.fileName, '00-colors'); - test.equals(p.fileExtension, '.mustache'); - test.equals(p.jsonFileData.d, 123); - test.equals(p.patternBaseName, 'colors'); - test.equals(p.patternName, 'Colors'); - test.equals(p.patternLink, '00-atoms-00-colors' + path.sep + '00-atoms-00-colors.html'); - test.equals(p.patternGroup, 'atoms'); - test.equals(p.flatPatternPath, '00-atoms'); - test.equals(p.patternPartial, 'atoms-colors'); - test.equals(p.template, ''); - test.equals(p.lineage.length, 0); - test.equals(p.lineageIndex.length, 0); - test.equals(p.lineageR.length, 0); - test.equals(p.lineageRIndex.length, 0); - test.done(); - }, - 'test Pattern with no numbers in pattern group works as expected' : function (test) { - var p = new Pattern('atoms/colors.mustache', { d: 123}); - test.equals(p.relPath, 'atoms' + path.sep + 'colors.mustache'); - test.equals(p.name, 'atoms-colors'); - test.equals(p.subdir, 'atoms'); - test.equals(p.fileName, 'colors'); - test.equals(p.patternLink, 'atoms-colors' + path.sep + 'atoms-colors.html'); - test.equals(p.patternGroup, 'atoms'); - test.equals(p.flatPatternPath, 'atoms'); - test.equals(p.patternPartial, 'atoms-colors'); - test.done(); +// fake pattern lab constructor: +// sets up a fake patternlab object, which is needed by the pattern processing +// apparatus. +function fakePatternLab() { + var fpl = { + partials: {}, + patterns: [], + footer: '', + header: '', + listitems: {}, + listItemArray: [], + data: { + link: {} }, - 'test Pattern capitalizes patternDisplayName correctly' : function(test){ - var p = new Pattern('00-atoms/00-global/00-colors-alt.mustache', { d: 123}); - test.equals(p.patternBaseName, 'colors-alt'); - test.equals(p.patternName, 'Colors Alt'); - test.done(); - } - }; + config: require('../patternlab-config.json'), + package: {} + }; + + return fpl; +} + +var of = require('../core/lib/object_factory'); +var Pattern = require('../core/lib/object_factory').Pattern; +var path = require('path'); +var pl = fakePatternLab(); -}()); +exports['Pattern initialization'] = { + 'test Pattern initializes correctly' : function (test) { + var p = new Pattern('00-atoms/00-global/00-colors.mustache', { d: 123}); + test.equals(p.relPath, '00-atoms' + path.sep + '00-global' + path.sep + '00-colors.mustache'); + test.equals(p.name, '00-atoms-00-global-00-colors'); + test.equals(p.subdir, '00-atoms' + path.sep + '00-global'); + test.equals(p.fileName, '00-colors'); + test.equals(p.fileExtension, '.mustache'); + test.equals(p.jsonFileData.d, 123); + test.equals(p.patternBaseName, 'colors'); + test.equals(p.patternName, 'Colors'); + test.equals(p.getPatternLink(pl), '00-atoms-00-global-00-colors' + path.sep + '00-atoms-00-global-00-colors.rendered.html'); + test.equals(p.patternGroup, 'atoms'); + test.equals(p.patternSubGroup, 'global'); + test.equals(p.flatPatternPath, '00-atoms-00-global'); + test.equals(p.patternPartial, 'atoms-colors'); + test.equals(p.template, ''); + test.equals(p.patternPartialCode, ''); + test.equals(p.lineage.length, 0); + test.equals(p.lineageIndex.length, 0); + test.equals(p.lineageR.length, 0); + test.equals(p.lineageRIndex.length, 0); + test.equals(p.patternState, ''); + test.done(); + }, + 'test Pattern with one-directory subdir works as expected' : function (test) { + var p = new Pattern('00-atoms/00-colors.mustache', { d: 123}); + test.equals(p.relPath, '00-atoms' + path.sep + '00-colors.mustache'); + test.equals(p.name, '00-atoms-00-colors'); + test.equals(p.subdir, '00-atoms'); + test.equals(p.fileName, '00-colors'); + test.equals(p.fileExtension, '.mustache'); + test.equals(p.jsonFileData.d, 123); + test.equals(p.patternBaseName, 'colors'); + test.equals(p.patternName, 'Colors'); + test.equals(p.getPatternLink(pl), '00-atoms-00-colors' + path.sep + '00-atoms-00-colors.rendered.html'); + test.equals(p.patternGroup, 'atoms'); + test.equals(p.flatPatternPath, '00-atoms'); + test.equals(p.patternPartial, 'atoms-colors'); + test.equals(p.template, ''); + test.equals(p.lineage.length, 0); + test.equals(p.lineageIndex.length, 0); + test.equals(p.lineageR.length, 0); + test.equals(p.lineageRIndex.length, 0); + test.done(); + }, + 'test Pattern with no numbers in pattern group works as expected' : function (test) { + var p = new Pattern('atoms/colors.mustache', { d: 123}); + test.equals(p.relPath, 'atoms' + path.sep + 'colors.mustache'); + test.equals(p.name, 'atoms-colors'); + test.equals(p.subdir, 'atoms'); + test.equals(p.fileName, 'colors'); + test.equals(p.getPatternLink(pl), 'atoms-colors' + path.sep + 'atoms-colors.rendered.html'); + test.equals(p.patternGroup, 'atoms'); + test.equals(p.flatPatternPath, 'atoms'); + test.equals(p.patternPartial, 'atoms-colors'); + test.done(); + }, + 'test Pattern capitalizes patternDisplayName correctly' : function (test) { + var p = new Pattern('00-atoms/00-global/00-colors-alt.mustache', { d: 123}); + test.equals(p.patternBaseName, 'colors-alt'); + test.equals(p.patternName, 'Colors Alt'); + test.done(); + }, + 'The forms of Pattern.getPatternLink() work as expected': function (test) { + var p = new Pattern('00-atoms/00-global/00-colors.hbs'); + test.equals(p.getPatternLink(pl), '00-atoms-00-global-00-colors' + path.sep + '00-atoms-00-global-00-colors.rendered.html'); + test.equals(p.getPatternLink(pl, 'rendered'), '00-atoms-00-global-00-colors' + path.sep + '00-atoms-00-global-00-colors.rendered.html'); + test.equals(p.getPatternLink(pl, 'rawTemplate'), '00-atoms-00-global-00-colors' + path.sep + '00-atoms-00-global-00-colors.html'); + test.equals(p.getPatternLink(pl, 'markupOnly'), '00-atoms-00-global-00-colors' + path.sep + '00-atoms-00-global-00-colors.markup-only.html'); + test.done(); + } +}; From e88552435742f3f3ffefa95adc858bf6d8dff971 Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Thu, 18 Aug 2016 14:12:05 -0500 Subject: [PATCH 05/13] revert most of the getPatternLink usage -- we're going back to feeding config into Pattern object initialization --- core/lib/lineage_hunter.js | 5 ++--- core/lib/pattern_assembler.js | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/core/lib/lineage_hunter.js b/core/lib/lineage_hunter.js index 5dbb26a91..e74e4a6c9 100644 --- a/core/lib/lineage_hunter.js +++ b/core/lib/lineage_hunter.js @@ -22,9 +22,8 @@ var lineage_hunter = function () { //create the more complex patternLineage object too var l = { "lineagePattern": ancestorPattern.patternPartial, - "lineagePath": "../../patterns/" + ancestorPattern.getPatternLink(patternlab) + "lineagePath": "../../patterns/" + ancestorPattern.patternLink }; - if (ancestorPattern.patternState) { l.lineageState = ancestorPattern.patternState; } @@ -38,7 +37,7 @@ var lineage_hunter = function () { //create the more complex patternLineage object in reverse var lr = { "lineagePattern": pattern.patternPartial, - "lineagePath": "../../patterns/" + pattern.getPatternLink(patternlab) + "lineagePath": "../../patterns/" + pattern.patternLink }; if (pattern.patternState) { lr.lineageState = pattern.patternState; diff --git a/core/lib/pattern_assembler.js b/core/lib/pattern_assembler.js index 96cb371a9..8aba2d631 100644 --- a/core/lib/pattern_assembler.js +++ b/core/lib/pattern_assembler.js @@ -94,7 +94,7 @@ var pattern_assembler = function () { function addPattern(pattern, patternlab) { //add the link to the global object - patternlab.data.link[pattern.patternPartial] = '/patterns/' + pattern.getPatternLink(patternlab); + patternlab.data.link[pattern.patternPartial] = '/patterns/' + pattern.patternLink; //only push to array if the array doesn't contain this pattern var isNew = true; From eb3db580c05aabcb782189b441ba0e99576130d0 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Thu, 18 Aug 2016 22:24:28 -0500 Subject: [PATCH 06/13] set property when excluded, do not omit outright --- core/lib/ui_builder.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/lib/ui_builder.js b/core/lib/ui_builder.js index 104286366..8a45eab9b 100644 --- a/core/lib/ui_builder.js +++ b/core/lib/ui_builder.js @@ -108,9 +108,11 @@ var ui_builder = function () { return exclude === pattern.patternGroup; }); if (isOmitted) { if (patternlab.config.debug) { - console.log('Omitting ' + pattern.patternPartial + ' from styleguide patterns its patternGroup is specified in styleguideExcludes.'); + console.log('Omitting ' + pattern.patternPartial + ' from future viewall pages because its patternGroup is specified in styleguideExcludes.'); } - return true; + //these patterns should not be omitted from later processing, just viewall pages + pattern.omitFromViewAll = true; + isOmitted = false; } //this pattern is contained with a directory prefixed with an underscore (a handy way to hide whole directories from the nav From 1cea9c152eaee7a0fee64145406674cc33009418 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Thu, 18 Aug 2016 23:08:06 -0500 Subject: [PATCH 07/13] exclude styleguideExcludes from all page - but still render them in the navigation fixes #393 --- core/lib/ui_builder.js | 28 ++++++++++++++-------------- test/ui_builder_tests.js | 15 --------------- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/core/lib/ui_builder.js b/core/lib/ui_builder.js index 8a45eab9b..4e46e9ec7 100644 --- a/core/lib/ui_builder.js +++ b/core/lib/ui_builder.js @@ -103,18 +103,6 @@ var ui_builder = function () { return true; } - //this pattern is a member of any excluded pattern groups - isOmitted = styleGuideExcludes && styleGuideExcludes.length && _.some(styleGuideExcludes, function (exclude) { - return exclude === pattern.patternGroup; }); - if (isOmitted) { - if (patternlab.config.debug) { - console.log('Omitting ' + pattern.patternPartial + ' from future viewall pages because its patternGroup is specified in styleguideExcludes.'); - } - //these patterns should not be omitted from later processing, just viewall pages - pattern.omitFromViewAll = true; - isOmitted = false; - } - //this pattern is contained with a directory prefixed with an underscore (a handy way to hide whole directories from the nav isOmitted = pattern.relPath.charAt(0) === '_' || pattern.relPath.indexOf('/_') > -1; if (isOmitted) { @@ -465,6 +453,7 @@ var ui_builder = function () { var p; var typePatterns = []; + var styleGuideExcludes = patternlab.config.styleGuideExcludes; _.forOwn(patternTypeObj, function (patternSubtypes, patternSubtype) { @@ -494,7 +483,6 @@ var ui_builder = function () { return true; //stop yelling at us eslint we know we know }); - //do not create a viewall page for flat patterns if (!writeViewAllFile || !p) { return false; @@ -511,7 +499,19 @@ var ui_builder = function () { var viewAllHTML = buildViewAllHTML(patternlab, typePatterns, patternType); writeFile(paths.public.patterns + p.subdir + '/index.html', mainPageHeadHtml + viewAllHTML + footerHTML); - patterns = patterns.concat(typePatterns); + //determine if we should omit this patterntype completely from the viewall page + var omitPatternType = styleGuideExcludes && styleGuideExcludes.length + && _.some(styleGuideExcludes, function (exclude) { + return exclude === patternType; + }); + if (omitPatternType) { + if (patternlab.config.debug) { + console.log('Omitting ' + patternType+ ' from building a viewall page because its patternGroup is specified in styleguideExcludes.'); + } + } else { + patterns = patterns.concat(typePatterns); + } + return true; //stop yelling at us eslint we know we know }); return patterns; diff --git a/test/ui_builder_tests.js b/test/ui_builder_tests.js index 2273f0010..9c4a34028 100644 --- a/test/ui_builder_tests.js +++ b/test/ui_builder_tests.js @@ -53,21 +53,6 @@ exports['ui_builder'] = { test.done(); }, - 'isPatternExcluded - returns true when patterngroup is specified in styleguideExcludes': function (test) { - //arrange - var patternlab = createFakePatternLab({}); - var pattern = new Pattern('00-test/foo.mustache'); - patternlab.config.defaultPattern = 'test-boaz'; - patternlab.config.styleGuideExcludes.push('test'); - - //act - var result = ui.isPatternExcluded(pattern, patternlab); - - //assert - test.equals(result, true); - test.done(); - }, - 'isPatternExcluded - returns true when pattern within underscored directory - top level': function (test) { //arrange var patternlab = createFakePatternLab({}); From c9a8ff848a7ec2cbf36558fb514cf905160dd307 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Thu, 18 Aug 2016 23:30:18 -0500 Subject: [PATCH 08/13] switching file writing back to a synchronous task seems to resolve hangs on watches pretty sure this closes #439 --- core/lib/ui_builder.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/lib/ui_builder.js b/core/lib/ui_builder.js index 4e46e9ec7..ef108692a 100644 --- a/core/lib/ui_builder.js +++ b/core/lib/ui_builder.js @@ -69,9 +69,9 @@ var ui_builder = function () { */ function writeFile(filePath, data, callback) { if (callback) { - fs.outputFile(filePath, data, callback); + fs.outputFileSync(filePath, data, callback); } else { - fs.outputFile(filePath, data); + fs.outputFileSync(filePath, data); } } From 02d8af0515097467e5022f1d1020b2191f4d15fd Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Thu, 18 Aug 2016 23:41:35 -0500 Subject: [PATCH 09/13] add default outputFileSuffixes to project. Forgot we use this file for some unit tests. closes #438 --- patternlab-config.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/patternlab-config.json b/patternlab-config.json index b3f2d975b..5292c76bd 100644 --- a/patternlab-config.json +++ b/patternlab-config.json @@ -54,5 +54,10 @@ }, "patternExportPatternPartials": [], "patternExportDirectory": "./pattern_exports/", - "cacheBust": true + "cacheBust": true, + "outputFileSuffixes": { + "rendered": ".rendered", + "rawTemplate": "", + "markupOnly": ".markup-only" + } } From 7a74545b5ac8f6f8ab715305370bbc93e29a0bc2 Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Thu, 18 Aug 2016 23:47:02 -0500 Subject: [PATCH 10/13] fix eslint warnings --- core/lib/ui_builder.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/lib/ui_builder.js b/core/lib/ui_builder.js index ef108692a..dd705d12a 100644 --- a/core/lib/ui_builder.js +++ b/core/lib/ui_builder.js @@ -82,7 +82,6 @@ var ui_builder = function () { * @returns boolean - whether or not the pattern is excluded */ function isPatternExcluded(pattern, patternlab) { - var styleGuideExcludes = patternlab.config.styleGuideExcludes; var isOmitted; // skip underscore-prefixed files @@ -506,7 +505,7 @@ var ui_builder = function () { }); if (omitPatternType) { if (patternlab.config.debug) { - console.log('Omitting ' + patternType+ ' from building a viewall page because its patternGroup is specified in styleguideExcludes.'); + console.log('Omitting ' + patternType + ' from building a viewall page because its patternGroup is specified in styleguideExcludes.'); } } else { patterns = patterns.concat(typePatterns); From b2c45c698554fafc832e368453dc4a44a3600afe Mon Sep 17 00:00:00 2001 From: Brian Muenzenmeyer Date: Fri, 19 Aug 2016 07:45:21 -0500 Subject: [PATCH 11/13] updating semver --- core/lib/patternlab.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/lib/patternlab.js b/core/lib/patternlab.js index ddc8aaa8b..f4308a9c0 100644 --- a/core/lib/patternlab.js +++ b/core/lib/patternlab.js @@ -1,5 +1,5 @@ /* - * patternlab-node - v2.4.2 - 2016 + * patternlab-node - v2.4.3 - 2016 * * Brian Muenzenmeyer, Geoff Pursell, and the web community. * Licensed under the MIT license. diff --git a/package.json b/package.json index 68ae8715b..25442e032 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": "2.4.2", + "version": "2.4.3", "main": "./core/lib/patternlab.js", "dependencies": { "diveSync": "^0.3.0", From a168ab857fd3da6ca9e3fbb57a0731f7bdd2e59a Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Fri, 19 Aug 2016 14:23:43 -0500 Subject: [PATCH 12/13] Have the constructor for Pattern take a patternlab object as its third parameter so it can construct correct pattern links based on the configure outputFilePaths in the user config --- core/lib/object_factory.js | 19 +++++++++---------- core/lib/pattern_assembler.js | 4 ++-- core/lib/ui_builder.js | 3 ++- test/ui_builder_tests.js | 7 ++++++- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/core/lib/object_factory.js b/core/lib/object_factory.js index 839182d06..0874326ce 100644 --- a/core/lib/object_factory.js +++ b/core/lib/object_factory.js @@ -6,7 +6,7 @@ var extend = require('util')._extend; // Pattern properties -var Pattern = function (relPath, data) { +var Pattern = function (relPath, data, patternlab) { // We expect relPath to be the path of the pattern template, relative to the // root of the pattern tree. Parse out the path parts and save the useful ones. var pathObj = path.parse(path.normalize(relPath)); @@ -44,6 +44,10 @@ var Pattern = function (relPath, data) { // the joined pattern group and subgroup directory this.flatPatternPath = this.subdir.replace(/[\/\\]/g, '-'); // '00-atoms-00-global' + // calculated path from the root of the public directory to the generated + // (rendered!) html file for this pattern, to be shown in the iframe + this.patternLink = patternlab ? this.getPatternLink(patternlab, 'rendered') : null; + // The canonical "key" by which this pattern is known. This is the callable // name of the pattern. UPDATE: this.key is now known as this.patternPartial this.patternPartial = this.patternGroup + '-' + this.patternBaseName; @@ -88,11 +92,6 @@ Pattern.prototype = { var suffixConfig = patternlab.config.outputFileSuffixes; var suffix = suffixType ? suffixConfig[suffixType] : suffixConfig.rendered; - if (this.patternLink) { - // Someone or something has explicitly set a patternLink on this pattern. - // We had better respect that. - return this.patternLink; - } return this.name + path.sep + this.name + suffix + '.html'; }, @@ -123,16 +122,16 @@ Pattern.prototype = { // factory: creates an empty Pattern for miscellaneous internal use, such as // by list_item_hunter -Pattern.createEmpty = function (customProps) { - var pattern = new Pattern('', null); +Pattern.createEmpty = function (customProps, patternlab) { + var pattern = new Pattern('', null, patternlab); return extend(pattern, customProps); }; // factory: creates an Pattern object on-demand from a hash; the hash accepts // parameters that replace the positional parameters that the Pattern // constructor takes. -Pattern.create = function (relPath, data, customProps) { - var newPattern = new Pattern(relPath || '', data || null); +Pattern.create = function (relPath, data, customProps, patternlab) { + var newPattern = new Pattern(relPath || '', data || null, patternlab); return extend(newPattern, customProps); }; diff --git a/core/lib/pattern_assembler.js b/core/lib/pattern_assembler.js index 8aba2d631..1c305688d 100644 --- a/core/lib/pattern_assembler.js +++ b/core/lib/pattern_assembler.js @@ -213,7 +213,7 @@ var pattern_assembler = function () { if (proposedDirectoryStats.isDirectory()) { var subTypeMarkdownFileContents = fs.readFileSync(proposedDirectory + '.md', 'utf8'); var subTypeMarkdown = markdown_parser.parse(subTypeMarkdownFileContents); - var subTypePattern = new Pattern(relPath); + var subTypePattern = new Pattern(relPath, null, patternlab); subTypePattern.patternSectionSubtype = true; subTypePattern.patternLink = subTypePattern.name + '/index.html'; subTypePattern.patternDesc = subTypeMarkdown.markdown; @@ -244,7 +244,7 @@ var pattern_assembler = function () { if (!patternEngines.isPatternFile(filename, patternlab)) { return null; } //make a new Pattern Object - var currentPattern = new Pattern(relPath); + var currentPattern = new Pattern(relPath, null, patternlab); //if file is named in the syntax for variants if (patternEngines.isPseudoPatternJSON(filename)) { diff --git a/core/lib/ui_builder.js b/core/lib/ui_builder.js index 104286366..d4a9b7d9e 100644 --- a/core/lib/ui_builder.js +++ b/core/lib/ui_builder.js @@ -154,7 +154,8 @@ var ui_builder = function () { engine: null, flatPatternPath: pattern.flatPatternPath, isDocPattern: true - } + }, + patternlab ); return docPattern; } diff --git a/test/ui_builder_tests.js b/test/ui_builder_tests.js index 2273f0010..509b81082 100644 --- a/test/ui_builder_tests.js +++ b/test/ui_builder_tests.js @@ -16,7 +16,12 @@ function createFakePatternLab(customProps) { } }, styleGuideExcludes: [ 'templates' ], - debug: false + debug: false, + outputFileSuffixes: { + rendered: '.rendered', + rawTemplate: '', + markupOnly: '.markup-only' + } } }; return extend(pl, customProps); From 88126513e3781c5a4fc9cdce69b78fb08e35f04b Mon Sep 17 00:00:00 2001 From: BRIAN MUENZENMEYER Date: Sat, 20 Aug 2016 00:52:58 -0500 Subject: [PATCH 13/13] attempt to fix render of raw template panel --- core/lib/object_factory.js | 3 +++ test/object_factory_tests.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/core/lib/object_factory.js b/core/lib/object_factory.js index 0874326ce..71c07e4e6 100644 --- a/core/lib/object_factory.js +++ b/core/lib/object_factory.js @@ -92,6 +92,9 @@ Pattern.prototype = { var suffixConfig = patternlab.config.outputFileSuffixes; var suffix = suffixType ? suffixConfig[suffixType] : suffixConfig.rendered; + if (suffixType === 'rawTemplate') { + return this.name + path.sep + this.name + suffix + this.fileExtension; + } return this.name + path.sep + this.name + suffix + '.html'; }, diff --git a/test/object_factory_tests.js b/test/object_factory_tests.js index 5875d78d7..77f203bce 100644 --- a/test/object_factory_tests.js +++ b/test/object_factory_tests.js @@ -94,7 +94,7 @@ exports['Pattern initialization'] = { var p = new Pattern('00-atoms/00-global/00-colors.hbs'); test.equals(p.getPatternLink(pl), '00-atoms-00-global-00-colors' + path.sep + '00-atoms-00-global-00-colors.rendered.html'); test.equals(p.getPatternLink(pl, 'rendered'), '00-atoms-00-global-00-colors' + path.sep + '00-atoms-00-global-00-colors.rendered.html'); - test.equals(p.getPatternLink(pl, 'rawTemplate'), '00-atoms-00-global-00-colors' + path.sep + '00-atoms-00-global-00-colors.html'); + test.equals(p.getPatternLink(pl, 'rawTemplate'), '00-atoms-00-global-00-colors' + path.sep + '00-atoms-00-global-00-colors.hbs'); test.equals(p.getPatternLink(pl, 'markupOnly'), '00-atoms-00-global-00-colors' + path.sep + '00-atoms-00-global-00-colors.markup-only.html'); test.done(); }