Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions core/lib/object_factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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*-/, '');

Expand All @@ -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;
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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);
};

Expand Down
6 changes: 3 additions & 3 deletions core/lib/pattern_assembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
16 changes: 8 additions & 8 deletions core/lib/patternlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
*/

Expand Down Expand Up @@ -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:');
Expand Down Expand Up @@ -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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geoffp this stuff is cool !

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! :)


//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;
});
Expand Down
3 changes: 2 additions & 1 deletion core/lib/ui_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ var ui_builder = function () {
engine: null,
flatPatternPath: pattern.flatPatternPath,
isDocPattern: true
}
},
patternlab
);
return docPattern;
}
Expand Down
83 changes: 65 additions & 18 deletions test/lineage_hunter_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -113,11 +116,13 @@ exports['lineage hunter '] = {
"lineageIndex": [],
"lineageR": [],
"lineageRIndex": []
}
})
],
config: {
outputFileSuffixes: {
rendered: ''
rendered: '.rendered',
rawTemplate: '',
markupOnly: '.markup-only'
}
}
};
Expand Down Expand Up @@ -150,7 +155,14 @@ exports['lineage hunter '] = {
"template": "<h1> {{message}} </h1>",
"extendedTemplate": "<h1> {{message}} </h1>"
})
]
],
config: {
outputFileSuffixes: {
rendered: '.rendered',
rawTemplate: '',
markupOnly: '.markup-only'
}
}
};

lineage_hunter.find_lineage(currentPattern, patternlab);
Expand Down Expand Up @@ -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",
Expand All @@ -304,8 +316,15 @@ exports['lineage hunter '] = {
"lineageIndex": [],
"lineageR": [],
"lineageRIndex": []
})
],
config: {
outputFileSuffixes: {
rendered: '.rendered',
rawTemplate: '',
markupOnly: '.markup-only'
}
]
}
};

var lineage_hunter = new lh();
Expand Down Expand Up @@ -361,7 +380,14 @@ exports['lineage hunter '] = {
"lineageR": [],
"lineageRIndex": []
})
]
],
config: {
outputFileSuffixes: {
rendered: '.rendered',
rawTemplate: '',
markupOnly: '.markup-only'
}
}
};

var lineage_hunter = new lh();
Expand Down Expand Up @@ -415,7 +441,14 @@ exports['lineage hunter '] = {
"lineageR": [],
"lineageRIndex": []
})
]
],
config: {
outputFileSuffixes: {
rendered: '.rendered',
rawTemplate: '',
markupOnly: '.markup-only'
}
}
};

var lineage_hunter = new lh();
Expand Down Expand Up @@ -469,7 +502,14 @@ exports['lineage hunter '] = {
"lineageR": [],
"lineageRIndex": []
})
]
],
config: {
outputFileSuffixes: {
rendered: '.rendered',
rawTemplate: '',
markupOnly: '.markup-only'
}
}
};

var lineage_hunter = new lh();
Expand All @@ -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",
Expand All @@ -508,8 +548,15 @@ exports['lineage hunter '] = {
"lineageIndex": [],
"lineageR": [],
"lineageRIndex": []
})
],
config: {
outputFileSuffixes: {
rendered: '.rendered',
rawTemplate: '',
markupOnly: '.markup-only'
}
]
}
};

var lineage_hunter = new lh();
Expand Down
Loading