-
Notifications
You must be signed in to change notification settings - Fork 407
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 #208 from geoffp/pattern-engines
PatternEngines ongoing work, round 4
- Loading branch information
1 parent
d2dc6f5
commit e1ae249
Showing
33 changed files
with
765 additions
and
224 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 |
---|---|---|
@@ -1,9 +1,6 @@ | ||
{ | ||
"env": { | ||
"jasmine": true, | ||
"node": true, | ||
"mocha": true, | ||
"browser": true, | ||
"builtin": true | ||
}, | ||
"globals": {}, | ||
|
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 |
---|---|---|
|
@@ -16,3 +16,4 @@ branches: | |
only: | ||
- master | ||
- dev | ||
- pattern-engines |
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
2 changes: 1 addition & 1 deletion
2
packages/patternengine-node-underscore/builder/list_item_hunter.js
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
12 changes: 6 additions & 6 deletions
12
packages/patternengine-node-underscore/builder/parameter_hunter.js
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
70 changes: 70 additions & 0 deletions
70
packages/patternengine-node-underscore/builder/pattern_engines/engine_handlebars.js
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,70 @@ | ||
/* | ||
* handlebars pattern engine for patternlab-node - v0.15.1 - 2015 | ||
* | ||
* 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. | ||
* | ||
*/ | ||
|
||
(function () { | ||
"use strict"; | ||
|
||
var Handlebars = require('handlebars'); | ||
|
||
var engine_handlebars = { | ||
engine: Handlebars, | ||
engineName: 'handlebars', | ||
engineFileExtension: '.hbs', | ||
|
||
// regexes, stored here so they're only compiled once | ||
// GTP warning: unchanged copypasta from mustache engine | ||
// findPartialsRE: /{{>\s*((?:\d+-[\w-]+\/)+(\d+-[\w-]+(\.\w+)?)|[A-Za-z0-9-]+)(\:[\w-]+)?(\(\s*\w+\s*:\s*(?:'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*")\))?\s*}}/g, | ||
findPartialsRE: /{{#?>\s*([\w-\/.]+)(?:.|\s+)*?}}/g, | ||
findPartialsWithStyleModifiersRE: /{{>([ ])?([\w\-\.\/~]+)(?!\()(\:[A-Za-z0-9-_|]+)+(?:(| )\(.*)?([ ])?}}/g, | ||
findPartialsWithPatternParametersRE: /{{>([ ])?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-_|]+)?(?:(| )\(.*)+([ ])?}}/g, | ||
findListItemsRE: /({{#( )?)(list(I|i)tems.)(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty)( )?}}/g, | ||
|
||
// render it | ||
renderPattern: function renderPattern(template, data, partials) { | ||
if (partials) { | ||
Handlebars.registerPartial(partials); | ||
} | ||
var compiled = Handlebars.compile(template); | ||
return compiled(data); | ||
}, | ||
|
||
registerPartial: function (oPattern) { | ||
Handlebars.registerPartial(oPattern.key, oPattern.template); | ||
}, | ||
|
||
// find and return any {{> template-name }} within pattern | ||
findPartials: function findPartials(pattern) { | ||
var matches = pattern.template.match(this.findPartialsRE); | ||
return matches; | ||
}, | ||
findPartialsWithStyleModifiers: function(pattern) { | ||
var matches = pattern.template.match(this.findPartialsWithStyleModifiersRE); | ||
return matches; | ||
}, | ||
// returns any patterns that match {{> value(foo:"bar") }} or {{> | ||
// value:mod(foo:"bar") }} within the pattern | ||
findPartialsWithPatternParameters: function(pattern) { | ||
var matches = pattern.template.match(this.findPartialsWithPatternParametersRE); | ||
return matches; | ||
}, | ||
findListItems: function(pattern) { | ||
var matches = pattern.template.match(this.findListItemsRE); | ||
return matches; | ||
}, | ||
// given a pattern, and a partial string, tease out the "pattern key" and | ||
// return it. | ||
getPartialKey: function(pattern, partialString) { | ||
var partialKey = partialString.replace(this.findPartialsRE, '$1'); | ||
return partialKey; | ||
} | ||
}; | ||
|
||
module.exports = engine_handlebars; | ||
})(); |
Oops, something went wrong.