-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from pattern-lab/dev
Dev to Master
- Loading branch information
Showing
28 changed files
with
554 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"ass": false, | ||
"bitwise": false, | ||
"browser": false, | ||
"closure": false, | ||
"continue": false, | ||
"couch": false, | ||
"debug": false, | ||
"devel": true, | ||
"eqeq": false, | ||
"eval": true, | ||
"evil": false, | ||
"forin": false, | ||
"indent": 2, | ||
"maxerr": 50, | ||
"maxlen": false, | ||
"newcap": false, | ||
"node": true, | ||
"nomen": false, | ||
"passfail": false, | ||
"plusplus": false, | ||
"predef": [ | ||
"node", | ||
"$", | ||
"require" | ||
], | ||
"regexp": false, | ||
"rhino": false, | ||
"sloppy": false, | ||
"stupid": false, | ||
"sub": false, | ||
"todo": false, | ||
"unparam": true, | ||
"vars": false, | ||
"white": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* patternlab-node - v0.10.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. | ||
* | ||
*/ | ||
|
||
(function () { | ||
"use strict"; | ||
|
||
var parameter_hunter = function(){ | ||
|
||
var extend = require('util')._extend, | ||
pa = require('./pattern_assembler'), | ||
mustache = require('mustache'), | ||
pattern_assembler = new pa(); | ||
|
||
function findparameters(pattern, patternlab){ | ||
|
||
//find the {{> template-name(*) }} within patterns | ||
var matches = pattern.template.match(/{{>([ ]+)?([A-Za-z0-9-]+)(\()(.+)(\))([ ]+)?}}/g); | ||
if(matches !== null){ | ||
matches.forEach(function(pMatch, index, matches){ | ||
//find the partial's name | ||
var partialName = pMatch.match(/([a-z-]+)/ig)[0] | ||
|
||
if(patternlab.config.debug){ | ||
console.log('found patternParameters for ' + partialName); | ||
} | ||
|
||
//strip out the additional data and eval | ||
var leftParen = pMatch.indexOf('('); | ||
var rightParen = pMatch.indexOf(')'); | ||
var paramString = '({' + pMatch.substring(leftParen + 1, rightParen) + '})'; | ||
|
||
//do no evil. there is no good way to do this that I can think of without using a split, which then makes commas and colons special characters and unusable within the pattern params | ||
var paramData = eval(paramString); | ||
|
||
//compile this partial immeadiately, essentially consuming it. | ||
//TODO: see how this affects lineage. perhaps add manually here. | ||
var partialPattern = pattern_assembler.get_pattern_by_key(partialName, patternlab); | ||
var existingData = pattern.data || patternlab.data; | ||
|
||
//merge paramData with any other data that exists. | ||
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 | ||
existingData.link = extend({}, patternlab.data.link); | ||
var renderedPartial = pattern_assembler.renderPattern(partialPattern.extendedTemplate, existingData, patternlab.partials); | ||
|
||
//remove the parameter from the partial and replace it with the rendered partial + paramData | ||
pattern.extendedTemplate = pattern.extendedTemplate.replace(pMatch, renderedPartial); | ||
|
||
//TODO: lineage is missing for this pattern | ||
|
||
}); | ||
} | ||
} | ||
|
||
return { | ||
find_parameters: function(pattern, patternlab){ | ||
findparameters(pattern, patternlab); | ||
} | ||
}; | ||
|
||
}; | ||
|
||
module.exports = parameter_hunter; | ||
|
||
}()); |
Oops, something went wrong.