Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge WIP styleguide integration into 2.0 core #306

Merged
merged 16 commits into from
Apr 11, 2016
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
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ module.exports = function (grunt) {
grunt.registerTask('default', ['patternlab', 'copy:main', 'copy:styleguide']);

//travis CI task
grunt.registerTask('travis', ['nodeunit', 'eslint', 'patternlab']);
grunt.registerTask('travis', ['nodeunit', 'eslint']);

grunt.registerTask('serve', ['patternlab', 'copy:main', 'copy:styleguide', 'browserSync', 'watch:all']);

Expand Down
36 changes: 18 additions & 18 deletions core/lib/lineage_hunter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* patternlab-node - v1.2.1 - 2016
*
/*
* patternlab-node - v1.2.0 - 2016
*
* Brian Muenzenmeyer, and the web community.
* Licensed under the MIT license.
*
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
* Licensed under the MIT license.
*
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
*
*/

Expand All @@ -23,15 +23,15 @@ var lineage_hunter = function () {
if (matches !== null) {
matches.forEach(function (match) {
//get the ancestorPattern
var ancestorPattern = pattern_assembler.get_pattern_by_key(pattern.findPartialKey(match), patternlab);
var ancestorPattern = pattern_assembler.findPartial(pattern.findPartial(match), patternlab);

if (ancestorPattern && pattern.lineageIndex.indexOf(ancestorPattern.key) === -1) {
if (ancestorPattern && pattern.lineageIndex.indexOf(ancestorPattern.patternPartial) === -1) {
//add it since it didnt exist
pattern.lineageIndex.push(ancestorPattern.key);
pattern.lineageIndex.push(ancestorPattern.patternPartial);

//create the more complex patternLineage object too
var l = {
"lineagePattern": ancestorPattern.key,
"lineagePattern": ancestorPattern.patternPartial,
"lineagePath": "../../patterns/" + ancestorPattern.patternLink
};
if (ancestorPattern.patternState) {
Expand All @@ -41,12 +41,12 @@ var lineage_hunter = function () {
pattern.lineage.push(l);

//also, add the lineageR entry if it doesn't exist
if (ancestorPattern.lineageRIndex.indexOf(pattern.key) === -1) {
ancestorPattern.lineageRIndex.push(pattern.key);
if (ancestorPattern.lineageRIndex.indexOf(pattern.patternPartial) === -1) {
ancestorPattern.lineageRIndex.push(pattern.patternPartial);

//create the more complex patternLineage object in reverse
var lr = {
"lineagePattern": pattern.key,
"lineagePattern": pattern.patternPartial,
"lineagePath": "../../patterns/" + pattern.patternLink
};
if (pattern.patternState) {
Expand All @@ -64,14 +64,14 @@ var lineage_hunter = function () {
// if the request came from the past, apply target pattern state to current pattern lineage
if (direction === 'fromPast') {
for (var i = 0; i < pattern.lineageIndex.length; i++) {
if (pattern.lineageIndex[i] === targetPattern.key) {
if (pattern.lineageIndex[i] === targetPattern.patternPartial) {
pattern.lineage[i].lineageState = targetPattern.patternState;
}
}
} else {
//the request came from the future, apply target pattern state to current pattern reverse lineage
for (var i = 0; i < pattern.lineageRIndex.length; i++) {
if (pattern.lineageRIndex[i] === targetPattern.key) {
if (pattern.lineageRIndex[i] === targetPattern.patternPartial) {
pattern.lineageR[i].lineageState = targetPattern.patternState;
}
}
Expand All @@ -93,7 +93,7 @@ var lineage_hunter = function () {

//find all lineage - patterns being consumed by this one
for (var h = 0; h < pattern.lineageIndex.length; h++) {
var lineagePattern = pattern_assembler.get_pattern_by_key(pattern.lineageIndex[h], patternlab);
var lineagePattern = pattern_assembler.findPartial(pattern.lineageIndex[h], patternlab);
setPatternState('fromFuture', lineagePattern, pattern);
}
}
Expand All @@ -103,15 +103,15 @@ var lineage_hunter = function () {
//find all reverse lineage - that is, patterns consuming this one
for (var j = 0; j < pattern.lineageRIndex.length; j++) {

var lineageRPattern = pattern_assembler.get_pattern_by_key(pattern.lineageRIndex[j], patternlab);
var lineageRPattern = pattern_assembler.findPartial(pattern.lineageRIndex[j], patternlab);

//only set patternState if pattern.patternState "is less than" the lineageRPattern.patternstate
//this makes patternlab apply the lowest common ancestor denominator
if (patternlab.config.patternStateCascade.indexOf(pattern.patternState)
< patternlab.config.patternStateCascade.indexOf(lineageRPattern.patternState)) {

if (patternlab.config.debug) {
console.log('Found a lower common denominator pattern state: ' + pattern.patternState + ' on ' + pattern.key + '. Setting reverse lineage pattern ' + lineageRPattern.key + ' from ' + lineageRPattern.patternState);
console.log('Found a lower common denominator pattern state: ' + pattern.patternState + ' on ' + pattern.patternPartial + '. Setting reverse lineage pattern ' + lineageRPattern.patternPartial + ' from ' + lineageRPattern.patternState);
}

lineageRPattern.patternState = pattern.patternState;
Expand Down
20 changes: 10 additions & 10 deletions core/lib/list_item_hunter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* patternlab-node - v1.2.1 - 2016
*
/*
* patternlab-node - v1.2.1 - 2016
*
* Brian Muenzenmeyer, and the web community.
* Licensed under the MIT license.
*
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
* Licensed under the MIT license.
*
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
*
*/

Expand All @@ -30,7 +30,7 @@ var list_item_hunter = function () {
matches.forEach(function (liMatch) {

if (patternlab.config.debug) {
console.log('found listItem of size ' + liMatch + ' inside ' + pattern.key);
console.log('found listItem of size ' + liMatch + ' inside ' + pattern.patternPartial);
}

//find the boundaries of the block
Expand Down Expand Up @@ -76,9 +76,9 @@ var list_item_hunter = function () {

//get the partial
var partialName = foundPartials[j].match(/([\w\-\.\/~]+)/g)[0];
var partialPattern = pattern_assembler.get_pattern_by_key(partialName, patternlab);
var partialPattern = pattern_assembler.findPartial(partialName, patternlab);

//create a copy of the partial so as to not pollute it after the get_pattern_by_key call.
//create a copy of the partial so as to not pollute it after the findPartial call.
var cleanPartialPattern = JSON.parse(JSON.stringify(partialPattern));

//if partial has style modifier data, replace the styleModifier value
Expand Down Expand Up @@ -107,7 +107,7 @@ var list_item_hunter = function () {
pattern.extendedTemplate = pattern.extendedTemplate.replace(repeatingBlock, repeatedBlockHtml);

//update the extendedTemplate in the partials object in case this pattern is consumed later
patternlab.partials[pattern.key] = pattern.extendedTemplate;
patternlab.partials[pattern.patternPartial] = pattern.extendedTemplate;

});
}
Expand Down
38 changes: 19 additions & 19 deletions core/lib/object_factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ var oPattern = function (abspath, subdir, filename, data) {
this.patternGroup = this.name.substring(this.name.indexOf('-') + 1, this.name.indexOf('-', 4) + 1 - this.name.indexOf('-') + 1);
this.patternSubGroup = subdir.substring(subdir.indexOf('/') + 4);
this.flatPatternPath = subdir.replace(/[\/\\]/g, '-');
this.key = this.patternGroup + '-' + this.patternName;
this.patternPartial = this.patternGroup + '-' + this.patternName;
this.template = '';
this.patternPartial = '';
this.patternPartialCode = '';
this.lineage = [];
this.lineageIndex = [];
this.lineageR = [];
Expand Down Expand Up @@ -76,8 +76,8 @@ oPattern.prototype = {
return this.engine.findListItems(this);
},

findPartialKey: function (partialString) {
return this.engine.findPartialKey(partialString);
findPartial: function (partialString) {
return this.engine.findPartial(partialString);
}
};

Expand All @@ -99,31 +99,31 @@ oPattern.create = function (abspath, subdir, filename, data, customProps) {
};


var oBucket = function (name) {
this.bucketNameLC = name;
this.bucketNameUC = name.split('-').reduce(function (val, working) {
var oPatternType = function (name) {
this.patternTypeLC = name;
this.patternTypeUC = name.split('-').reduce(function (val, working) {
return val.charAt(0).toUpperCase() + val.slice(1) + ' ' + working.charAt(0).toUpperCase() + working.slice(1);
}, '').trim();
this.navItems = [];
this.navItemsIndex = [];
this.patternTypeItems = [];
this.patternTypeItemsIndex = [];
this.patternItems = [];
this.patternItemsIndex = [];
};


var oNavItem = function (name) {
this.sectionNameLC = name;
this.sectionNameUC = name.split('-').reduce(function (val, working) {
var oPatternSubType = function (name) {
this.patternSubtypeLC = name;
this.patternSubtypeUC = name.split('-').reduce(function (val, working) {
return val.charAt(0).toUpperCase() + val.slice(1) + ' ' + working.charAt(0).toUpperCase() + working.slice(1);
}, '').trim();
this.navSubItems = [];
this.navSubItemsIndex = [];
this.patternSubtypeItems = [];
this.patternSubtypeItemsIndex = [];
};


var oNavSubItem = function (name) {
var oPatternSubTypeItem = function (name) {
this.patternPath = '';
this.patternPartial = '';
this.patternPartialCode = '';
this.patternName = name.split(' ').reduce(function (val, working) {
return val.charAt(0).toUpperCase() + val.slice(1) + ' ' + working.charAt(0).toUpperCase() + working.slice(1);
}, '').trim();
Expand All @@ -132,7 +132,7 @@ var oNavSubItem = function (name) {

module.exports = {
oPattern: oPattern,
oBucket: oBucket,
oNavItem: oNavItem,
oNavSubItem: oNavSubItem
oPatternType: oPatternType,
oPatternSubType: oPatternSubType,
oPatternSubTypeItem: oPatternSubTypeItem
};
26 changes: 13 additions & 13 deletions core/lib/parameter_hunter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* patternlab-node - v1.2.1 - 2016
*
/*
* patternlab-node - v1.2.1 - 2016
*
* Brian Muenzenmeyer, and the web community.
* Licensed under the MIT license.
*
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
* Licensed under the MIT license.
*
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
*
*/

Expand All @@ -29,13 +29,13 @@ var parameter_hunter = function () {

do {

//if param key is wrapped in single quotes, replace with double quotes.
//if param partial is wrapped in single quotes, replace with double quotes.
paramString = paramString.replace(/(^\s*[\{|\,]\s*)'([^']+)'(\s*\:)/, '$1"$2"$3');

//if params key is not wrapped in any quotes, wrap in double quotes.
//if params partial is not wrapped in any quotes, wrap in double quotes.
paramString = paramString.replace(/(^\s*[\{|\,]\s*)([^\s"'\:]+)(\s*\:)/, '$1"$2"$3');

//move param key to paramStringWellFormed var.
//move param partial to paramStringWellFormed var.
colonPos = paramString.indexOf(':');

//except to prevent infinite loops.
Expand Down Expand Up @@ -73,7 +73,7 @@ var parameter_hunter = function () {
paramStringTmp = paramStringTmp.replace(/^'/, '"');
paramStringTmp = paramStringTmp.replace(/'$/, '"');

//move param key to paramStringWellFormed var.
//move param partial to paramStringWellFormed var.
paramStringWellFormed += paramStringTmp;
paramString = paramString.substring(quotePos, paramString.length).trim();
}
Expand All @@ -90,7 +90,7 @@ var parameter_hunter = function () {
quotePos += 2;
}

//move param key to paramStringWellFormed var.
//move param partial to paramStringWellFormed var.
paramStringWellFormed += paramString.substring(0, quotePos);
paramString = paramString.substring(quotePos, paramString.length).trim();
}
Expand Down Expand Up @@ -130,7 +130,7 @@ var parameter_hunter = function () {
pattern.parameteredPartials.forEach(function (pMatch) {
//find the partial's name and retrieve it
var partialName = pMatch.match(/([\w\-\.\/~]+)/g)[0];
var partialPattern = pattern_assembler.get_pattern_by_key(partialName, patternlab);
var partialPattern = pattern_assembler.findPartial(partialName, patternlab);

//if we retrieved a pattern we should make sure that its extendedTemplate is reset. looks to fix #190
partialPattern.extendedTemplate = partialPattern.template;
Expand Down Expand Up @@ -174,7 +174,7 @@ var parameter_hunter = function () {
pattern.extendedTemplate = pattern.extendedTemplate.replace(pMatch, renderedPartial);

//update the extendedTemplate in the partials object in case this pattern is consumed later
patternlab.partials[pattern.key] = pattern.extendedTemplate;
patternlab.partials[pattern.patternPartial] = pattern.extendedTemplate;
});
}
}
Expand Down
Loading