From 74544248e84dd70e686b1a1ec731476ebe1a9b3e Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Tue, 25 Aug 2015 16:58:59 -0500 Subject: [PATCH 01/15] Add editorconfig and eslintrc --- .editorconfig | 11 ++++++++ .eslintrc | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 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..f07e2be6d --- /dev/null +++ b/.eslintrc @@ -0,0 +1,71 @@ +{ + "env": { + "jasmine": true, + "node": true, + "mocha": true, + "browser": true, + "builtin": true + }, + "globals": {}, + "rules": { + "block-scoped-var": 2, + "camelcase": 0, + "curly": [ + 2, + "all" + ], + "dot-notation": [ + 2, + { + "allowKeywords": true + } + ], + "eqeqeq": [ + 2, + "allow-null" + ], + "global-strict": [ + 2, + "never" + ], + "guard-for-in": 2, + "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": 2, + "no-iterator": 2, + "no-loop-func": 2, + "no-multi-str": 2, + "no-new": 2, + "no-proto": 2, + "no-script-url": 2, + "no-sequences": 2, + "no-shadow": 2, + "no-undef": 2, + "no-unused-vars": 2, + "no-with": 2, + "quotes": [ + 0, + "single" + ], + "semi": [ + 0, + "never" + ], + "strict": 2, + "valid-typeof": 2, + "wrap-iife": [ + 2, + "inside" + ] + } +} From 4a9dec622eda58e1b67754fdc59a028855c7ca05 Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Tue, 25 Aug 2015 17:05:58 -0500 Subject: [PATCH 02/15] Add first draft of pattern engines --- builder/pattern_engines/engine_mustache.js | 36 ++++++++++++++++++++ builder/pattern_engines/pattern_engines.js | 38 ++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 builder/pattern_engines/engine_mustache.js create mode 100644 builder/pattern_engines/pattern_engines.js diff --git a/builder/pattern_engines/engine_mustache.js b/builder/pattern_engines/engine_mustache.js new file mode 100644 index 000000000..fb9dcef71 --- /dev/null +++ b/builder/pattern_engines/engine_mustache.js @@ -0,0 +1,36 @@ +/* + * mustache pattern engine for patternlab-node - v0.10.1 - 2015 + * + * Brian Muenzenmeyer, and the web community. + * Licensed under the MIT license. + * + * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. + * + */ + +(function () { + "use strict"; + + var Mustache = require('mustache'); + + var engine_mustache = { + engine: Mustache, + fileExtension: '.mustache', + + // render it + renderPattern: function renderPattern(template, data, partials) { + if (partials) { + return Mustache.render(template, data, partials); + } + return Mustache.render(template, data); + }, + + // find and return any {{> template-name }} within pattern + findPartials: function findPartials(pattern) { + var matches = pattern.template.match(/{{>([ ])?([A-Za-z0-9-]+)(?:\:[A-Za-z0-9-]+)?(?:(| )\(.*)?([ ])?}}/g); + return matches; + } + }; + + module.exports = engine_mustache; +})(); diff --git a/builder/pattern_engines/pattern_engines.js b/builder/pattern_engines/pattern_engines.js new file mode 100644 index 000000000..d290a8dc3 --- /dev/null +++ b/builder/pattern_engines/pattern_engines.js @@ -0,0 +1,38 @@ +/* + * patternlab-node - v0.10.1 - 2015 + * + * Brian Muenzenmeyer, and the web community. + * Licensed under the MIT license. + * + * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. + * + */ + +(function () { + 'use strict'; + + // list of supported pattern engines + var supportedPatternEngineNames = [ + 'mustache', + 'handlebars' + ]; + + // hash of all loaded pattern engines, empty at first + var patternEngines = {}; + + // try to load all supported engines + supportedPatternEngineNames.forEach(function (engineName) { + try { + patternEngines[engineName] = require('./engine_' + engineName); + } catch (err) { + console.log(err, 'pattern engine "' + engineName + '" not loaded. Did you install its dependency with npm?'); + } + }); + + patternEngines.getEngineForPattern = function (pattern) { + + }; + + module.exports = patternEngines; + +})(); From 4899cd9db23edafac3bdc710b752ccdbfa1b78bf Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Tue, 25 Aug 2015 17:08:20 -0500 Subject: [PATCH 03/15] first batch of changes to migrate from direct dependence on mustache to dependence on pattern engines --- builder/pattern_assembler.js | 67 +++++++++++++++++++-------------- builder/patternlab.js | 23 ++++++----- builder/pseudopattern_hunter.js | 14 +++---- 3 files changed, 56 insertions(+), 48 deletions(-) diff --git a/builder/pattern_assembler.js b/builder/pattern_assembler.js index a024a7dac..2bd1c19ce 100644 --- a/builder/pattern_assembler.js +++ b/builder/pattern_assembler.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v0.10.1 - 2015 - * +/* + * patternlab-node - v0.10.1 - 2015 + * * Brian Muenzenmeyer, and the web community. - * Licensed under the MIT license. - * - * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. + * Licensed under the MIT license. + * + * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. * */ @@ -13,7 +13,13 @@ var pattern_assembler = function(){ - //find and return any {{> template-name }} within pattern + var fs = require('fs-extra'), + of = require('./object_factory'), + path = require('path'), + patternEngines = require('./pattern_engines/pattern_engines'); + + // find and return any {{> template-name }} within pattern + // TODO: delete, factored out function findPartials(pattern){ var matches = pattern.template.match(/{{>([ ])?([A-Za-z0-9-]+)(?:\:[A-Za-z0-9-]+)?(?:(| )\(.*)?([ ])?}}/g); return matches; @@ -33,30 +39,37 @@ } function renderPattern(template, data, partials) { + debugger; + // TODO: + // choose an appropriate pattern engine + // call and return result of its renderPattern method + // OR MAYBE: this should just be a method of oPattern + } - var mustache = require('mustache'); - - if(partials) { - return mustache.render(template, data, partials); - } else{ - return mustache.render(template, data); - } + function isPatternFile(filename, patternlab) { + var engineNames = Object.keys(patternEngines); + var supportedPatternFileExtensions = engineNames.map(function (engineName) { + return patternEngines[engineName].fileExtension; + }); + var extension = path.extname(filename); + return (supportedPatternFileExtensions.lastIndexOf(extension) != -1); } + // given a pattern file, figure out what to do with it function processPatternFile(file, patternlab){ - var fs = require('fs-extra'), - of = require('./object_factory'), - path = require('path'); - //extract some information var abspath = file.substring(2); var subdir = path.dirname(path.relative('./source/_patterns', file)).replace('\\', '/'); var filename = path.basename(file); - //ignore _underscored patterns, json (for now), and dotfiles - if(filename.charAt(0) === '_' || path.extname(filename) === '.json' || filename.charAt(0) === '.'){ + // ignore _underscored patterns, dotfiles, and anything not recognized by + // a loaded pattern engine + if (filename.charAt(0) === '_' || + filename.charAt(0) === '.' || + !isPatternFile(filename, patternlab)) { return; } + console.log('found pattern', file); //make a new Pattern Object var currentPattern = new of.oPattern(subdir, filename); @@ -80,17 +93,13 @@ } function processPattern(currentPattern, patternlab, additionalData){ - - var fs = require('fs-extra'), - mustache = require('mustache'), - lh = require('./lineage_hunter'), - ph = require('./parameter_hunter'), - pph = require('./pseudopattern_hunter'), - path = require('path'); + var lh = require('./lineage_hunter'), + ph = require('./parameter_hunter'), + pph = require('./pseudopattern_hunter'); var parameter_hunter = new ph(), - lineage_hunter = new lh(), - pseudopattern_hunter = new pph(); + lineage_hunter = new lh(), + pseudopattern_hunter = new pph(); currentPattern.extendedTemplate = currentPattern.template; diff --git a/builder/patternlab.js b/builder/patternlab.js index 74e4c186f..5452aac7a 100644 --- a/builder/patternlab.js +++ b/builder/patternlab.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v0.10.1 - 2015 - * +/* + * patternlab-node - v0.10.1 - 2015 + * * Brian Muenzenmeyer, and the web community. - * Licensed under the MIT license. - * - * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. + * Licensed under the MIT license. + * + * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. * */ @@ -15,7 +15,6 @@ var patternlab_engine = function () { 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'), @@ -27,6 +26,7 @@ var patternlab_engine = function () { patternlab.package = fs.readJSONSync('./package.json'); patternlab.config = fs.readJSONSync('./config.json'); + function getVersion() { console.log(patternlab.package.version); } @@ -67,17 +67,16 @@ var patternlab_engine = function () { entity_encoder = new he(), pattern_exporter = new pe(); - diveSync('./source/_patterns', function(err, file){ + diveSync('./source/_patterns', function(err, filePath){ //log any errors if(err){ console.log(err); return; } - - pattern_assembler.process_pattern_file(file, patternlab); - + pattern_assembler.process_pattern_file(filePath, patternlab); }); - //render all patterns last, so lineageR works + + //render all patterns last, so lineage works patternlab.patterns.forEach(function(pattern, index, patterns){ //render the pattern, but first consolidate any data we may have var allData = JSON.parse(JSON.stringify(patternlab.data)); diff --git a/builder/pseudopattern_hunter.js b/builder/pseudopattern_hunter.js index b2b74a125..77f29868b 100644 --- a/builder/pseudopattern_hunter.js +++ b/builder/pseudopattern_hunter.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v0.10.1 - 2015 - * +/* + * patternlab-node - v0.10.1 - 2015 + * * Brian Muenzenmeyer, and the web community. - * Licensed under the MIT license. - * - * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. + * Licensed under the MIT license. + * + * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. * */ @@ -48,7 +48,7 @@ variantFileData = pattern_assembler.merge_data(variantFileData, currentPattern.jsonFileData); var variantName = pseudoPatterns[i].substring(pseudoPatterns[i].indexOf('~') + 1).split('.')[0]; - var patternVariant = new of.oPattern(currentPattern.subdir, currentPattern.fileName + '-' + variantName + '.mustache', variantFileData); + var patternVariant = new of.oPattern(currentPattern.subdir, currentPattern.fileName + '-' + variantName + '.mustache', variantFileData); //see if this file has a state pattern_assembler.setPatternState(patternVariant, patternlab); From 30f8000360247f6b06dfcceb150e7fe5d9200c2d Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Fri, 28 Aug 2015 14:44:55 -0500 Subject: [PATCH 04/15] First steps toward a .render() method directly on the oPattern object. The pattern_engines module returns an instance, but I now realize that this is a terrible idea. --- builder/object_factory.js | 19 +++++++++++++------ builder/parameter_hunter.js | 20 ++++++++++---------- builder/pattern_engines/engine_mustache.js | 14 +++++++------- builder/pattern_engines/pattern_engines.js | 21 ++++++++++++--------- 4 files changed, 42 insertions(+), 32 deletions(-) diff --git a/builder/object_factory.js b/builder/object_factory.js index f1809b16e..87b6700c5 100644 --- a/builder/object_factory.js +++ b/builder/object_factory.js @@ -1,16 +1,18 @@ -/* - * patternlab-node - v0.10.1 - 2015 - * +/* + * patternlab-node - v0.10.1 - 2015 + * * Brian Muenzenmeyer, and the web community. - * Licensed under the MIT license. - * - * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. + * Licensed under the MIT license. + * + * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. * */ (function () { "use strict"; + var PatternEngines = require('pattern_engines/pattern_engines'); + var oPattern = function(subdir, filename, data){ this.fileName = filename.substring(0, filename.indexOf('.')); this.subdir = subdir; @@ -29,6 +31,11 @@ this.lineageIndex = []; this.lineageR = []; this.lineageRIndex = []; + this.engine = PatternEngines.getEngineForPattern(this); + }; + // render method on oPatterns; this acts as a proxy for the + oPattern.prototype.render = function (data, partials) { + return this.engine.render(this.template, data, partials); }; var oBucket = function(name){ diff --git a/builder/parameter_hunter.js b/builder/parameter_hunter.js index 0541b211f..09ed0d1a0 100644 --- a/builder/parameter_hunter.js +++ b/builder/parameter_hunter.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v0.10.1 - 2015 - * +/* + * patternlab-node - v0.10.1 - 2015 + * * Brian Muenzenmeyer, and the web community. - * Licensed under the MIT license. - * - * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. + * Licensed under the MIT license. + * + * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. * */ @@ -14,9 +14,9 @@ var parameter_hunter = function(){ var extend = require('util')._extend, - pa = require('./pattern_assembler'), - mustache = require('mustache'), - pattern_assembler = new pa(); + pa = require('./pattern_asbsembler'), + mustache = require('mustache'), + pattern_assembler = new pa(); function findparameters(pattern, patternlab){ @@ -47,7 +47,7 @@ for (var prop in paramData) { if (existingData.hasOwnProperty(prop)) { existingData[prop] = paramData[prop]; - } + } } //extend pattern data links into link for pattern link shortcuts to work. we do this locally and globally diff --git a/builder/pattern_engines/engine_mustache.js b/builder/pattern_engines/engine_mustache.js index fb9dcef71..90bace478 100644 --- a/builder/pattern_engines/engine_mustache.js +++ b/builder/pattern_engines/engine_mustache.js @@ -1,10 +1,10 @@ -/* - * mustache pattern engine for patternlab-node - v0.10.1 - 2015 - * +/* + * mustache pattern engine for patternlab-node - v0.10.1 - 2015 + * * Brian Muenzenmeyer, and the web community. - * Licensed under the MIT license. - * - * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. + * Licensed under the MIT license. + * + * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. * */ @@ -31,6 +31,6 @@ return matches; } }; - + module.exports = engine_mustache; })(); diff --git a/builder/pattern_engines/pattern_engines.js b/builder/pattern_engines/pattern_engines.js index d290a8dc3..ac65ddc74 100644 --- a/builder/pattern_engines/pattern_engines.js +++ b/builder/pattern_engines/pattern_engines.js @@ -17,22 +17,25 @@ 'handlebars' ]; - // hash of all loaded pattern engines, empty at first - var patternEngines = {}; + // object/hash of all loaded pattern engines, empty at first + function PatternEngines () { + // do nothing + } + PatternEngines.prototype = { + getEngineForPattern: function (pattern) { + console.log('pattern file name: ', pattern.fileName); + return 'mustache'; + } + }; // try to load all supported engines supportedPatternEngineNames.forEach(function (engineName) { try { - patternEngines[engineName] = require('./engine_' + engineName); + PatternEngines[engineName] = require('./engine_' + engineName); } catch (err) { console.log(err, 'pattern engine "' + engineName + '" not loaded. Did you install its dependency with npm?'); } }); - patternEngines.getEngineForPattern = function (pattern) { - - }; - - module.exports = patternEngines; - + module.exports = new PatternEngines(); })(); From 5420ad1716714211d73f9e15bfb166b7f0dcae5e Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Mon, 21 Sep 2015 14:14:21 -0500 Subject: [PATCH 05/15] comment fixups --- builder/pattern_engines/engine_mustache.js | 2 +- builder/pattern_engines/pattern_engines.js | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/builder/pattern_engines/engine_mustache.js b/builder/pattern_engines/engine_mustache.js index 90bace478..1a9fc0ba8 100644 --- a/builder/pattern_engines/engine_mustache.js +++ b/builder/pattern_engines/engine_mustache.js @@ -1,7 +1,7 @@ /* * mustache pattern engine for patternlab-node - v0.10.1 - 2015 * - * Brian Muenzenmeyer, and the web community. + * Geoffrey Pursell, Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. * * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. diff --git a/builder/pattern_engines/pattern_engines.js b/builder/pattern_engines/pattern_engines.js index ac65ddc74..5be883448 100644 --- a/builder/pattern_engines/pattern_engines.js +++ b/builder/pattern_engines/pattern_engines.js @@ -1,7 +1,7 @@ /* * patternlab-node - v0.10.1 - 2015 * - * Brian Muenzenmeyer, and the web community. + * Geoffrey Pursell, Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. * * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. @@ -17,7 +17,13 @@ 'handlebars' ]; - // object/hash of all loaded pattern engines, empty at first + // Object/hash of all loaded pattern engines, empty at first. + // My intention here is to make this return an object that can be used to + // obtain any loaded PatternEngine by addressing them like this: + // + // var PatternEngines = require('pattern_engines/pattern_engines'); + // var Mustache = PatternEngines('mustache'); + // function PatternEngines () { // do nothing } From a2f5cf7a79c190c0ecd8f233bbb42f753ae4b94c Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Tue, 27 Oct 2015 10:55:20 -0500 Subject: [PATCH 06/15] fix typos and module path issues --- builder/object_factory.js | 11 ++++++----- builder/parameter_hunter.js | 8 ++++---- builder/patternlab.js | 12 ++++++------ 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/builder/object_factory.js b/builder/object_factory.js index 40cd396b2..5b111979f 100644 --- a/builder/object_factory.js +++ b/builder/object_factory.js @@ -1,6 +1,6 @@ -/* - * patternlab-node - v0.13.0 - 2015 - * +/* + * patternlab-node - v0.13.0 - 2015 + * * Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. * @@ -11,7 +11,7 @@ (function () { "use strict"; - var PatternEngines = require('pattern_engines/pattern_engines'); + var PatternEngines = require('./pattern_engines/pattern_engines'); var oPattern = function(abspath, subdir, filename, data){ this.fileName = filename.substring(0, filename.indexOf('.')); @@ -36,7 +36,8 @@ this.lineageRIndex = []; this.engine = PatternEngines.getEngineForPattern(this); }; - // render method on oPatterns; this acts as a proxy for the + // render method on oPatterns; this acts as a proxy for the PatternEngine's + // render function oPattern.prototype.render = function (data, partials) { return this.engine.render(this.template, data, partials); }; diff --git a/builder/parameter_hunter.js b/builder/parameter_hunter.js index 974f56f0b..d6b0a338f 100644 --- a/builder/parameter_hunter.js +++ b/builder/parameter_hunter.js @@ -1,6 +1,6 @@ -/* - * patternlab-node - v0.13.0 - 2015 - * +/* + * patternlab-node - v0.13.0 - 2015 + * * Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. * @@ -14,7 +14,7 @@ var parameter_hunter = function(){ var extend = require('util')._extend, - pa = require('./pattern_asbsembler'), + pa = require('./pattern_assembler'), mustache = require('mustache'), pattern_assembler = new pa(); diff --git a/builder/patternlab.js b/builder/patternlab.js index 2a4fd08a5..da61ffe6b 100644 --- a/builder/patternlab.js +++ b/builder/patternlab.js @@ -1,10 +1,10 @@ -/* - * patternlab-node - v0.13.0 - 2015 - * +/* + * patternlab-node - v0.13.0 - 2015 + * * Brian Muenzenmeyer, and the web community. - * Licensed under the MIT license. - * - * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. + * Licensed under the MIT license. + * + * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. * */ From 6a6db63d7088c0eeebcb2598ad453df138949685 Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Tue, 27 Oct 2015 10:56:03 -0500 Subject: [PATCH 07/15] make PatternEngines a genuine Object, and set up its method-bearing prototype in the ES5 Object.create style --- builder/pattern_engines/pattern_engines.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/builder/pattern_engines/pattern_engines.js b/builder/pattern_engines/pattern_engines.js index 5be883448..9f4ef2e80 100644 --- a/builder/pattern_engines/pattern_engines.js +++ b/builder/pattern_engines/pattern_engines.js @@ -21,18 +21,15 @@ // My intention here is to make this return an object that can be used to // obtain any loaded PatternEngine by addressing them like this: // - // var PatternEngines = require('pattern_engines/pattern_engines'); - // var Mustache = PatternEngines('mustache'); + // var PatternEngines = require('./pattern_engines/pattern_engines'); + // var Mustache = PatternEngines['mustache']; // - function PatternEngines () { - // do nothing - } - PatternEngines.prototype = { + var PatternEngines = Object.create({ getEngineForPattern: function (pattern) { console.log('pattern file name: ', pattern.fileName); return 'mustache'; } - }; + }); // try to load all supported engines supportedPatternEngineNames.forEach(function (engineName) { @@ -43,5 +40,5 @@ } }); - module.exports = new PatternEngines(); + module.exports = PatternEngines; })(); From f22551bd4464493b7c14aafd721738b2dded67a3 Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Tue, 27 Oct 2015 10:57:01 -0500 Subject: [PATCH 08/15] temporarily restore mustache-only pattern rendering --- builder/pattern_assembler.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/builder/pattern_assembler.js b/builder/pattern_assembler.js index 80e2ea315..12ad6c2cc 100644 --- a/builder/pattern_assembler.js +++ b/builder/pattern_assembler.js @@ -1,6 +1,6 @@ -/* - * patternlab-node - v0.13.0 - 2015 - * +/* + * patternlab-node - v0.13.0 - 2015 + * * Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. * @@ -68,12 +68,19 @@ } } + // template: a string containing the template text, not an oPattern function renderPattern(template, data, partials) { - debugger; // TODO: // choose an appropriate pattern engine // call and return result of its renderPattern method // OR MAYBE: this should just be a method of oPattern + + var mustache = require('mustache'); + if (partials) { + return mustache.render(template, data, partials); + } else { + return mustache.render(template, data); + } } function isPatternFile(filename, patternlab) { From a7236f7b9c9af944d978e871a1da7cc1ac7aa794 Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Tue, 27 Oct 2015 11:35:02 -0500 Subject: [PATCH 09/15] 'working' renderPattern function --- builder/pattern_assembler.js | 21 ++++++++++----------- builder/pattern_engines/engine_mustache.js | 1 + builder/pattern_engines/pattern_engines.js | 6 +++++- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/builder/pattern_assembler.js b/builder/pattern_assembler.js index 12ad6c2cc..860f46f22 100644 --- a/builder/pattern_assembler.js +++ b/builder/pattern_assembler.js @@ -68,18 +68,17 @@ } } - // template: a string containing the template text, not an oPattern - function renderPattern(template, data, partials) { - // TODO: - // choose an appropriate pattern engine - // call and return result of its renderPattern method - // OR MAYBE: this should just be a method of oPattern - - var mustache = require('mustache'); - if (partials) { - return mustache.render(template, data, partials); + function renderPattern(pattern, data, partials) { + // if we've been passed a full oPattern, it knows what kind of template it + // is, and how to render itself, so we just call its render method + if (pattern instanceof of.oPattern) { + console.log('rendering full oPattern'); + return pattern.render(pattern, data, partials); } else { - return mustache.render(template, data); + // otherwise, assume it's a plain mustache template string and act + // accordingly + console.log('rendering plain mustache string'); + return patternEngines.mustache.renderPattern(pattern, data, partials); } } diff --git a/builder/pattern_engines/engine_mustache.js b/builder/pattern_engines/engine_mustache.js index 1a9fc0ba8..485a2cf26 100644 --- a/builder/pattern_engines/engine_mustache.js +++ b/builder/pattern_engines/engine_mustache.js @@ -15,6 +15,7 @@ var engine_mustache = { engine: Mustache, + name: 'mustache', fileExtension: '.mustache', // render it diff --git a/builder/pattern_engines/pattern_engines.js b/builder/pattern_engines/pattern_engines.js index 9f4ef2e80..059acaf51 100644 --- a/builder/pattern_engines/pattern_engines.js +++ b/builder/pattern_engines/pattern_engines.js @@ -25,9 +25,13 @@ // var Mustache = PatternEngines['mustache']; // var PatternEngines = Object.create({ - getEngineForPattern: function (pattern) { + getEngineNameForPattern: function (pattern) { console.log('pattern file name: ', pattern.fileName); return 'mustache'; + }, + getEngineForPattern: function (pattern) { + var engineName = this.getEngineNameForPattern(pattern); + return this[engineName]; } }); From fd5e6b6c18cf8926af7c11a0262fbeb0260af3c8 Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Tue, 27 Oct 2015 11:42:47 -0500 Subject: [PATCH 10/15] start rendering real oPatterns and fix that rendering path --- builder/object_factory.js | 2 +- builder/pattern_assembler.js | 4 ++-- builder/patternlab.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/builder/object_factory.js b/builder/object_factory.js index 5b111979f..c0aed2537 100644 --- a/builder/object_factory.js +++ b/builder/object_factory.js @@ -39,7 +39,7 @@ // render method on oPatterns; this acts as a proxy for the PatternEngine's // render function oPattern.prototype.render = function (data, partials) { - return this.engine.render(this.template, data, partials); + return this.engine.renderPattern(this.template, data, partials); }; var oBucket = function(name){ diff --git a/builder/pattern_assembler.js b/builder/pattern_assembler.js index 860f46f22..4b6543559 100644 --- a/builder/pattern_assembler.js +++ b/builder/pattern_assembler.js @@ -72,8 +72,8 @@ // if we've been passed a full oPattern, it knows what kind of template it // is, and how to render itself, so we just call its render method if (pattern instanceof of.oPattern) { - console.log('rendering full oPattern'); - return pattern.render(pattern, data, partials); + console.log('rendering full oPattern: ' + pattern.name); + return pattern.render(data, partials); } else { // otherwise, assume it's a plain mustache template string and act // accordingly diff --git a/builder/patternlab.js b/builder/patternlab.js index da61ffe6b..061747cc9 100644 --- a/builder/patternlab.js +++ b/builder/patternlab.js @@ -124,7 +124,7 @@ var patternlab_engine = function () { var allData = JSON.parse(JSON.stringify(patternlab.data)); allData = pattern_assembler.merge_data(allData, pattern.jsonFileData); - pattern.patternPartial = pattern_assembler.renderPattern(pattern.extendedTemplate, allData); + pattern.patternPartial = pattern_assembler.renderPattern(pattern, allData); //add footer info before writing var patternFooter = pattern_assembler.renderPattern(patternlab.footer, pattern); From c4d5080d3da0f528c1928aa63f5d81603ae1d466 Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Tue, 27 Oct 2015 16:56:44 -0500 Subject: [PATCH 11/15] add file extension to oPattern, update unit test --- builder/object_factory.js | 6 ++++-- test/object_factory_tests.js | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/builder/object_factory.js b/builder/object_factory.js index c0aed2537..799452fcf 100644 --- a/builder/object_factory.js +++ b/builder/object_factory.js @@ -11,10 +11,12 @@ (function () { "use strict"; - var PatternEngines = require('./pattern_engines/pattern_engines'); + var patternEngines = require('./pattern_engines/pattern_engines'); + var path = require('path'); var oPattern = function(abspath, subdir, filename, data){ this.fileName = filename.substring(0, filename.indexOf('.')); + this.fileExtension = path.extname(abspath); this.abspath = abspath; this.subdir = subdir; this.name = subdir.replace(/[\/\\]/g, '-') + '-' + this.fileName; //this is the unique name with the subDir @@ -34,7 +36,7 @@ this.lineageIndex = []; this.lineageR = []; this.lineageRIndex = []; - this.engine = PatternEngines.getEngineForPattern(this); + this.engine = patternEngines.getEngineForPattern(this); }; // render method on oPatterns; this acts as a proxy for the PatternEngine's // render function diff --git a/test/object_factory_tests.js b/test/object_factory_tests.js index 6ce2693a1..dfa7dfc48 100644 --- a/test/object_factory_tests.js +++ b/test/object_factory_tests.js @@ -10,6 +10,7 @@ test.equals(p.abspath, 'source/_patterns/00-atoms/00-global/00-colors.mustache'); test.equals(p.subdir, '00-atoms/00-global'); test.equals(p.fileName, '00-colors'); + test.equals(p.fileExtension, '.mustache'); test.equals(p.jsonFileData.d, 123); test.equals(p.patternName, 'colors'); test.equals(p.patternDisplayName, 'Colors'); From 37bacdcc2c7bf09aa15225747494a23edfff402e Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Tue, 27 Oct 2015 16:57:22 -0500 Subject: [PATCH 12/15] Create a new mapping between file extensions and engine names at load time that powers a real implementation of getEngineNameForPattern! --- builder/pattern_engines/pattern_engines.js | 45 ++++++++++++++++++---- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/builder/pattern_engines/pattern_engines.js b/builder/pattern_engines/pattern_engines.js index 059acaf51..aab8efe6c 100644 --- a/builder/pattern_engines/pattern_engines.js +++ b/builder/pattern_engines/pattern_engines.js @@ -8,6 +8,7 @@ * */ + (function () { 'use strict'; @@ -17,6 +18,9 @@ 'handlebars' ]; + // mapping of file extensions to engine names, for lookup use + var engineNameForExtension = {}; + // Object/hash of all loaded pattern engines, empty at first. // My intention here is to make this return an object that can be used to // obtain any loaded PatternEngine by addressing them like this: @@ -25,8 +29,17 @@ // var Mustache = PatternEngines['mustache']; // var PatternEngines = Object.create({ + supportedPatternEngineNames: supportedPatternEngineNames, + getEngineNameForPattern: function (pattern) { - console.log('pattern file name: ', pattern.fileName); + // avoid circular dependency by putting this in here. TODO: is this slow? + var of = require('../object_factory'); + + if (pattern instanceof of.oPattern) { + return engineNameForExtension[pattern.fileExtension]; + } + // otherwise, assume it's a plain mustache template string and act + // accordingly return 'mustache'; }, getEngineForPattern: function (pattern) { @@ -36,13 +49,29 @@ }); // try to load all supported engines - supportedPatternEngineNames.forEach(function (engineName) { - try { - PatternEngines[engineName] = require('./engine_' + engineName); - } catch (err) { - console.log(err, 'pattern engine "' + engineName + '" not loaded. Did you install its dependency with npm?'); - } - }); + (function loadAllEngines() { + supportedPatternEngineNames.forEach(function (engineName) { + try { + PatternEngines[engineName] = require('./engine_' + engineName); + } catch (err) { + console.log(err, 'pattern engine "' + engineName + '" not loaded. Did you install its dependency with npm?'); + } + }); + })(); + + // produce a mapping between file extension and engine name for each of the + // loaded engines + engineNameForExtension = (function () { + var mapping = {}; + + Object.keys(PatternEngines).forEach(function (engineName) { + var extensionForEngine = PatternEngines[engineName].fileExtension; + mapping[extensionForEngine] = engineName; + }); + + return mapping; + })(); + module.exports = PatternEngines; })(); From f54db8356d31f8c912e7805d763a7929225e34da Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Tue, 27 Oct 2015 16:58:33 -0500 Subject: [PATCH 13/15] Add unit tests for pattern_engines.js and individual pattern engines --- test/pattern_engines_tests.js | 71 +++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 test/pattern_engines_tests.js diff --git a/test/pattern_engines_tests.js b/test/pattern_engines_tests.js new file mode 100644 index 000000000..f2f8d10cd --- /dev/null +++ b/test/pattern_engines_tests.js @@ -0,0 +1,71 @@ +(function () { + 'use strict'; + + var patternEngines = require('../builder/pattern_engines/pattern_engines'); + var of = require('../builder/object_factory'); + + // the mustache test pattern, stolen from object_factory unit tests + var mustacheTestPattern = new of.oPattern('source/_patterns/00-atoms/00-global/00-colors-alt.mustache', '00-atoms/00-global', '00-colors-alt.mustache', {d: 123}); + var engineNames = Object.keys(patternEngines); + + + exports['patternEngines support functions'] = { + 'getEngineNameForPattern returns "mustache" from test pattern': function (test) { + var engineName = patternEngines.getEngineNameForPattern(mustacheTestPattern); + test.equals(engineName, 'mustache'); + test.done(); + }, + 'getEngineForPattern returns a reference to the mustache engine from test pattern': function (test) { + var engine = patternEngines.getEngineForPattern(mustacheTestPattern); + test.equals(engine, patternEngines.mustache); + test.done(); + } + }; + + // testProps() utility function: given an object, and a hash of expected + // 'property name':'property type' pairs, verify that the object contains each + // expected property, and that each property is of the expected type. + function testProps(object, propTests, test) { + + // function to test each expected property is present and the correct type + function testProp(propName, typeString) { + test.ok(object.hasOwnProperty(propName), '"' + propName + '" prop should be present'); + test.ok(typeof object[propName] === typeString, '"' + propName + '" prop should be of type ' + typeString); + } + + // go over each property test and run it + Object.keys(propTests).forEach(function (propName) { + var propType = propTests[propName]; + testProp(propName, propType); + }); + } + + exports['patternEngines initialization'] = { + 'patternEngines object contains at least the default mustache engine': function (test) { + test.expect(1); + test.ok(patternEngines.hasOwnProperty('mustache')); + test.done(); + } + }; + + // make one big test group for each pattern engine + engineNames.forEach(function (engineName) { + exports[engineName + ' patternEngine'] = { + 'engine contains expected properties and methods': function (test) { + + var propertyTests = { + 'engine': 'object', + 'name': 'string', + 'fileExtension': 'string', + 'renderPattern': 'function', + 'findPartials': 'function' + }; + + test.expect(Object.keys(propertyTests).length * 2); + testProps(patternEngines[engineName], propertyTests, test); + test.done(); + } + }; + }); + +})(); From 5217108de99579925e4e24af83fb3b4d67da5d5f Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Mon, 16 Nov 2015 11:47:29 -0600 Subject: [PATCH 14/15] isPatternFile consolidation and tests --- builder/pattern_assembler.js | 38 ++++++++++++++++----------------- test/pattern_assembler_tests.js | 28 ++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/builder/pattern_assembler.js b/builder/pattern_assembler.js index 711dafda7..86bd35622 100644 --- a/builder/pattern_assembler.js +++ b/builder/pattern_assembler.js @@ -1,6 +1,6 @@ -/* - * patternlab-node - v0.14.0 - 2015 - * +/* + * patternlab-node - v0.14.0 - 2015 + * * Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. * @@ -92,33 +92,31 @@ } } - function isPatternFile(filename, patternlab) { + // ignore _underscored patterns, dotfiles, and anything not recognized by + // a loaded pattern engine + function isPatternFile(filename) { + // skip hidden patterns/files without a second thought + if (filename.charAt(0) === '_' || filename.charAt(0) === '.') { + return false; + } + + // not a hidden pattern, let's dig deeper var engineNames = Object.keys(patternEngines); var supportedPatternFileExtensions = engineNames.map(function (engineName) { return patternEngines[engineName].fileExtension; }); var extension = path.extname(filename); - return (supportedPatternFileExtensions.lastIndexOf(extension) != -1); + return (supportedPatternFileExtensions.lastIndexOf(extension) !== -1); } function processPatternIterative(file, patternlab){ - var fs = require('fs-extra'), - of = require('./object_factory'), - path = require('path'); - //extract some information var subdir = path.dirname(path.relative(patternlab.config.patterns.source, file)).replace('\\', '/'); var filename = path.basename(file); var ext = path.extname(filename); - // ignore _underscored patterns, dotfiles, and anything not recognized by - // a loaded pattern engine - if (filename.charAt(0) === '_' || - filename.charAt(0) === '.' || - (ext === '.json' && filename.indexOf('~') === -1) || - !isPatternFile(filename, patternlab)) { - return; - } + // skip non-pattern files + if (!isPatternFile(filename, patternlab)) { return; } console.log('found pattern', file); //make a new Pattern Object @@ -183,8 +181,7 @@ ph = require('./parameter_hunter'), pph = require('./pseudopattern_hunter'), lih = require('./list_item_hunter'), - smh = require('./style_modifier_hunter'), - path = require('path'); + smh = require('./style_modifier_hunter'); var parameter_hunter = new ph(), lineage_hunter = new lh(), @@ -385,7 +382,8 @@ }, is_object_empty: function(obj){ return isObjectEmpty(obj); - } + }, + is_pattern_file: isPatternFile }; }; diff --git a/test/pattern_assembler_tests.js b/test/pattern_assembler_tests.js index cc4e55333..b532664d1 100644 --- a/test/pattern_assembler_tests.js +++ b/test/pattern_assembler_tests.js @@ -283,6 +283,34 @@ //test that 00-foo.mustache included partial 01-bar.mustache test.equals(fooExtended, 'bar'); + test.done(); + }, + + 'isPatternFile correctly identifies pattern files and rejects non-pattern files': function(test){ + var pattern_assembler = new pa(); + + // each test case + var filenames = { + '00-comment-thread.mustache': true, + '00-comment-thread.fakeextthatdoesntexist': false, + '00-comment-thread': false, + '_00-comment-thread.mustache': false, + '.00-comment-thread.mustache': false, + '00-comment-thread.json': false, + '00-homepage~emergency.json': false + }; + // expect one test per test case + test.expect(Object.keys(filenames).length); + + // loop over each test case and test it + Object.keys(filenames).forEach(function (filename) { + var expectedResult = filenames[filename], + actualResult = pattern_assembler.is_pattern_file(filename), + testMessage = 'isPatternFile should return ' + expectedResult + ' for ' + filename; + test.strictEqual(actualResult, expectedResult, testMessage); + }); + + // done test.done(); } }; From ac54ffb677ba94db95110b0490269f3980f5f2bf Mon Sep 17 00:00:00 2001 From: Geoffrey Pursell Date: Tue, 17 Nov 2015 12:46:47 -0600 Subject: [PATCH 15/15] We now pass all tests and build "successfully," but pseudo-patterns don't render at all, and are missing in the menu. The quest continues... --- .eslintrc | 2 +- builder/object_factory.js | 25 +++++++++++++++++++--- builder/pattern_assembler.js | 24 ++++++++++++++++----- builder/pattern_engines/pattern_engines.js | 8 +++++-- builder/patternlab.js | 6 +++--- builder/pseudopattern_hunter.js | 17 +++++++++------ builder/util.js | 22 +++++++++++++++++++ test/pattern_engines_tests.js | 9 ++++++++ 8 files changed, 93 insertions(+), 20 deletions(-) create mode 100644 builder/util.js diff --git a/.eslintrc b/.eslintrc index f07e2be6d..1aab4503d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -41,7 +41,7 @@ "no-eval": 2, "no-extend-native": 2, "no-extra-parens": 0, - "no-irregular-whitespace": 2, + "no-irregular-whitespace": 1, "no-iterator": 2, "no-loop-func": 2, "no-multi-str": 2, diff --git a/builder/object_factory.js b/builder/object_factory.js index cd2e533c9..ede4f6a64 100644 --- a/builder/object_factory.js +++ b/builder/object_factory.js @@ -1,6 +1,6 @@ -/* - * patternlab-node - v0.14.0 - 2015 - * +/* + * patternlab-node - v0.14.0 - 2015 + * * Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. * @@ -14,7 +14,11 @@ var patternEngines = require('./pattern_engines/pattern_engines'); var path = require('path'); + // oPattern properties + var oPattern = function(abspath, subdir, filename, data){ + console.log('new oPattern'); + console.log('absPath:', abspath, 'subdir:', subdir, 'filename:', filename, 'data:', data); this.fileName = filename.substring(0, filename.indexOf('.')); this.fileExtension = path.extname(abspath); this.abspath = abspath; @@ -37,10 +41,22 @@ this.lineageR = []; this.lineageRIndex = []; this.engine = patternEngines.getEngineForPattern(this); + this.isPseudoPattern = false; }; + + // oPattern methods + // render method on oPatterns; this acts as a proxy for the PatternEngine's // render function oPattern.prototype.render = function (data, partials) { + if (this.isPseudoPattern) { + console.log(this.name + ' is a pseudo-pattern'); + } else { + console.log('this is NOT a pseudo-pattern'); + } + // console.log('this does ' + (this.template ? '' : 'NOT ') + 'have template'); + // console.log('this does ' + (this.extendedTemplate ? '' : 'NOT ') + 'have extendedTemplate'); + return this.engine.renderPattern(this.template, data, partials); }; @@ -55,6 +71,7 @@ this.patternItemsIndex = []; }; + var oNavItem = function(name){ this.sectionNameLC = name; this.sectionNameUC = name.split('-').reduce(function(val, working){ @@ -64,6 +81,7 @@ this.navSubItemsIndex = []; }; + var oNavSubItem = function(name){ this.patternPath = ''; this.patternPartial = ''; @@ -72,6 +90,7 @@ }, '').trim(); }; + module.exports = { oPattern: oPattern, oBucket: oBucket, diff --git a/builder/pattern_assembler.js b/builder/pattern_assembler.js index 86bd35622..5efb135e2 100644 --- a/builder/pattern_assembler.js +++ b/builder/pattern_assembler.js @@ -87,16 +87,20 @@ } else { // otherwise, assume it's a plain mustache template string and act // accordingly - console.log('rendering plain mustache string'); + console.log('rendering plain mustache string:', pattern.substring(0, 20) + '...'); return patternEngines.mustache.renderPattern(pattern, data, partials); } } - // ignore _underscored patterns, dotfiles, and anything not recognized by - // a loaded pattern engine + // ignore _underscored patterns, dotfiles, and anything not recognized by a + // loaded pattern engine. Pseudo-pattern .json files ARE considered to be + // pattern files! function isPatternFile(filename) { // skip hidden patterns/files without a second thought - if (filename.charAt(0) === '_' || filename.charAt(0) === '.') { + var extension = path.extname(filename); + if(filename.charAt(0) === '.' || + filename.charAt(0) === '_' || + (extension === '.json' && filename.indexOf('~') === -1)) { return false; } @@ -105,17 +109,27 @@ var supportedPatternFileExtensions = engineNames.map(function (engineName) { return patternEngines[engineName].fileExtension; }); - var extension = path.extname(filename); return (supportedPatternFileExtensions.lastIndexOf(extension) !== -1); } function processPatternIterative(file, patternlab){ + var fs = require('fs-extra'), + of = require('./object_factory'), + path = require('path'); + //extract some information var subdir = path.dirname(path.relative(patternlab.config.patterns.source, file)).replace('\\', '/'); var filename = path.basename(file); var ext = path.extname(filename); + console.log('processPatternIterative:', 'filename:', filename); + // skip non-pattern files + //ignore dotfiles and non-variant .json files + if(filename.charAt(0) === '.' || (ext === '.json' && filename.indexOf('~') === -1)){ + return; + } + if (!isPatternFile(filename, patternlab)) { return; } console.log('found pattern', file); diff --git a/builder/pattern_engines/pattern_engines.js b/builder/pattern_engines/pattern_engines.js index aab8efe6c..a56ff70e0 100644 --- a/builder/pattern_engines/pattern_engines.js +++ b/builder/pattern_engines/pattern_engines.js @@ -43,8 +43,12 @@ return 'mustache'; }, getEngineForPattern: function (pattern) { - var engineName = this.getEngineNameForPattern(pattern); - return this[engineName]; + if (pattern.isPseudoPattern) { + return this.getEngineForPattern(pattern.basePattern); + } else { + var engineName = this.getEngineNameForPattern(pattern); + return this[engineName]; + } } }); diff --git a/builder/patternlab.js b/builder/patternlab.js index 4cd48c0cb..1b64e990e 100644 --- a/builder/patternlab.js +++ b/builder/patternlab.js @@ -1,6 +1,6 @@ -/* - * patternlab-node - v0.14.0 - 2015 - * +/* + * patternlab-node - v0.14.0 - 2015 + * * Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. * diff --git a/builder/pseudopattern_hunter.js b/builder/pseudopattern_hunter.js index 92121bb6a..0d04e88c1 100644 --- a/builder/pseudopattern_hunter.js +++ b/builder/pseudopattern_hunter.js @@ -1,6 +1,6 @@ -/* - * patternlab-node - v0.14.0 - 2015 - * +/* + * patternlab-node - v0.14.0 - 2015 + * * Brian Muenzenmeyer, and the web community. * Licensed under the MIT license. * @@ -20,17 +20,19 @@ pa = require('./pattern_assembler'), lh = require('./lineage_hunter'), of = require('./object_factory'), + patternEngines = require('./pattern_engines/pattern_engines'), mustache = require('mustache'); var pattern_assembler = new pa(); var lineage_hunter = new lh(); - //look for a pseudo pattern by checking if there is a file containing same name, with ~ in it, ending in .json + //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: 'source/_patterns/', //relative to gruntfile debug: false, - nodir: true, + nodir: true }); if(pseudoPatterns.length > 0){ @@ -47,7 +49,7 @@ //extend any existing data with variant data variantFileData = pattern_assembler.merge_data(currentPattern.jsonFileData, variantFileData); - // GTP: mustache-specific stuff here + // GTP: mustache-specific stuff here var variantName = pseudoPatterns[i].substring(pseudoPatterns[i].indexOf('~') + 1).split('.')[0]; var variantFilePath = 'source/_patterns/' + currentPattern.subdir + '/' + currentPattern.fileName + '~' + variantName + '.json'; var variantFileName = currentPattern.fileName + '-' + variantName + '.'; @@ -59,6 +61,9 @@ //use the same template as the non-variant patternVariant.template = currentPattern.template; patternVariant.extendedTemplate = currentPattern.extendedTemplate; + patternVariant.isPseudoPattern = true; + patternVariant.basePattern = currentPattern; + patternVariant.engine = patternEngines.getEngineForPattern(this); //find pattern lineage lineage_hunter.find_lineage(patternVariant, patternlab); diff --git a/builder/util.js b/builder/util.js new file mode 100644 index 000000000..53ab39a3b --- /dev/null +++ b/builder/util.js @@ -0,0 +1,22 @@ +/* + * patternlab-node - v0.14.0 - 2015 + * + * Brian Muenzenmeyer, Geoffrey Pursell and the web community. + * Licensed under the MIT license. + * + * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. + * + */ + +(function () { + var path = require('path'); + + var util = { + // takes a string of the filename or path, and will tell you if it refers to + isPseudoPattern: function () { + + } + }; + + module.exports = util; +}()); diff --git a/test/pattern_engines_tests.js b/test/pattern_engines_tests.js index f2f8d10cd..19f5891dc 100644 --- a/test/pattern_engines_tests.js +++ b/test/pattern_engines_tests.js @@ -6,6 +6,10 @@ // the mustache test pattern, stolen from object_factory unit tests var mustacheTestPattern = new of.oPattern('source/_patterns/00-atoms/00-global/00-colors-alt.mustache', '00-atoms/00-global', '00-colors-alt.mustache', {d: 123}); + var mustacheTestPseudoPatternBasePattern = new of.oPattern('source/_patterns/04-pages/00-homepage.mustache', '04-pages', '00-homepage.mustache', {d: 123}); + var mustacheTestPseudoPattern = new of.oPattern('source/_patterns/04-pages/00-homepage~emergency.json', '04-pages', '00-homepage-emergency.', {d: 123}); + mustacheTestPseudoPattern.isPseudoPattern = true; + mustacheTestPseudoPattern.basePattern = mustacheTestPseudoPatternBasePattern; var engineNames = Object.keys(patternEngines); @@ -19,6 +23,11 @@ var engine = patternEngines.getEngineForPattern(mustacheTestPattern); test.equals(engine, patternEngines.mustache); test.done(); + }, + 'getEngineForPattern returns a reference to the mustache engine from test pseudo-pattern': function (test) { + var engine = patternEngines.getEngineForPattern(mustacheTestPseudoPattern); + test.equals(engine, patternEngines.mustache); + test.done(); } };