Skip to content
This repository was archived by the owner on Dec 10, 2019. It is now read-only.

Commit 968aad9

Browse files
committed
get the handlebars engine file out of the past and into the present;
change mustache strings to handlebars
1 parent 6390e2c commit 968aad9

File tree

4 files changed

+89
-285
lines changed

4 files changed

+89
-285
lines changed

lib/engine_handlebars.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* handlebars pattern engine for patternlab-node - v0.15.1 - 2015
3+
*
4+
* Geoffrey Pursell, Brian Muenzenmeyer, and the web community.
5+
* Licensed under the MIT license.
6+
*
7+
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
8+
*
9+
*/
10+
11+
/*
12+
* ENGINE SUPPORT LEVEL:
13+
*
14+
* Full. Partial calls and lineage hunting are supported. Handlebars does not
15+
* support the mustache-specific syntax extensions, style modifiers and pattern
16+
* parameters, because their use cases are addressed by the core Handlebars
17+
* feature set.
18+
*
19+
*/
20+
21+
"use strict";
22+
23+
var Handlebars = require('handlebars');
24+
25+
var engine_handlebars = {
26+
engine: Handlebars,
27+
engineName: 'handlebars',
28+
engineFileExtension: '.hbs',
29+
30+
// partial expansion is only necessary for Mustache templates that have
31+
// style modifiers or pattern parameters (I think)
32+
expandPartials: false,
33+
34+
// regexes, stored here so they're only compiled once
35+
findPartialsRE: /{{#?>\s*([\w-\/.]+)(?:.|\s+)*?}}/g,
36+
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,
37+
38+
// render it
39+
renderPattern: function renderPattern(template, data, partials) {
40+
if (partials) {
41+
Handlebars.registerPartial(partials);
42+
}
43+
var compiled = Handlebars.compile(template);
44+
return compiled(data);
45+
},
46+
47+
registerPartial: function (oPattern) {
48+
Handlebars.registerPartial(oPattern.key, oPattern.template);
49+
},
50+
51+
// find and return any {{> template-name }} within pattern
52+
findPartials: function findPartials(pattern) {
53+
var matches = pattern.template.match(this.findPartialsRE);
54+
return matches;
55+
},
56+
findPartialsWithStyleModifiers: function () {
57+
// TODO: make the call to this from oPattern objects conditional on their
58+
// being implemented here.
59+
return [];
60+
},
61+
62+
// returns any patterns that match {{> value(foo:"bar") }} or {{>
63+
// value:mod(foo:"bar") }} within the pattern
64+
findPartialsWithPatternParameters: function () {
65+
// TODO: make the call to this from oPattern objects conditional on their
66+
// being implemented here.
67+
return [];
68+
},
69+
findListItems: function (pattern) {
70+
var matches = pattern.template.match(this.findListItemsRE);
71+
return matches;
72+
},
73+
74+
// given a pattern, and a partial string, tease out the "pattern key" and
75+
// return it.
76+
findPartialKey: function (partialString) {
77+
var partialKey = partialString.replace(this.findPartialsRE, '$1');
78+
return partialKey;
79+
}
80+
};
81+
82+
module.exports = engine_handlebars;

lib/engine_mustache.js

Lines changed: 0 additions & 119 deletions
This file was deleted.

lib/util_mustache.js

Lines changed: 0 additions & 158 deletions
This file was deleted.

package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
{
2-
"name": "patternengine-node-mustache",
3-
"description": "The Mustache engine for Pattern Lab / Node",
2+
"name": "patternengine-node-handlebars",
3+
"description": "The Handlebars engine for Pattern Lab / Node",
44
"version": "1.0.0",
5-
"main": "lib/engine_mustache.js",
5+
"main": "lib/engine_handlebars.js",
66
"dependencies": {
7-
"mustache": "^2.2.0"
8-
},
9-
"devDependencies": {
7+
"handlebars": "^4.0.5"
108
},
9+
"devDependencies": {},
1110
"keywords": [
1211
"Pattern Lab",
1312
"Atomic Web Design",
1413
"Node",
1514
"Grunt",
1615
"Gulp",
1716
"Javascript",
18-
"Mustache"
17+
"Handlebars"
1918
],
2019
"repository": {
2120
"type": "git",
22-
"url": "https://github.com/pattern-lab/patternengine-node-mustache.git"
21+
"url": "https://github.com/pattern-lab/patternengine-node-handlebars.git"
2322
},
2423
"bugs": "https://github.com/pattern-lab/patternlab-node/issues",
2524
"author": "Brian Muenzenmeyer & Geoffrey Pursell",

0 commit comments

Comments
 (0)