diff --git a/core/lib/object_factory.js b/core/lib/object_factory.js
index e277c510d..71c07e4e6 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));
@@ -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*-/, '');
@@ -48,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;
@@ -84,6 +84,20 @@ 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 (suffixType === 'rawTemplate') {
+ return this.name + path.sep + this.name + suffix + this.fileExtension;
+ }
+ return this.name + path.sep + this.name + suffix + '.html';
+ },
+
// the finders all delegate to the PatternEngine, which also encapsulates all
// appropriate regexes
findPartials: function () {
@@ -111,16 +125,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 532d88f9d..1c305688d 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.patternLink;
//only push to array if the array doesn't contain this pattern
var isNew = true;
@@ -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/patternlab.js b/core/lib/patternlab.js
index f4308a9c0..b0c68175f 100644
--- a/core/lib/patternlab.js
+++ b/core/lib/patternlab.js
@@ -2,9 +2,9 @@
* patternlab-node - v2.4.3 - 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:');
@@ -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/core/lib/ui_builder.js b/core/lib/ui_builder.js
index dd705d12a..a78240126 100644
--- a/core/lib/ui_builder.js
+++ b/core/lib/ui_builder.js
@@ -143,7 +143,8 @@ var ui_builder = function () {
engine: null,
flatPatternPath: pattern.flatPatternPath,
isDocPattern: true
- }
+ },
+ patternlab
);
return docPattern;
}
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..77f203bce 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.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();
+ }
+};
diff --git a/test/ui_builder_tests.js b/test/ui_builder_tests.js
index 9c4a34028..28af58e41 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);