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

Commit 828a7c6

Browse files
committed
grab the actual twig engine out of the past and bring it forward,
changing all relevant strings and version numbers
1 parent 01df245 commit 828a7c6

File tree

3 files changed

+93
-11
lines changed

3 files changed

+93
-11
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
## The Underscore engine for Pattern Lab / Node
1+
## The Twig engine for Pattern Lab / Node
22

3-
To install the Underscore engine in your edition, `npm install patternengine-node-underscore` should do the trick.
3+
To install the Twig engine in your edition, `npm install patternengine-node-twig` should do the trick.
44

5-
Level of support is basic; you can author patterns in Underscore, but support for calling pattern partials is accomplished through an Underscore mixin, and is considered experimental.
5+
Level of Support is more or less full. Partial calls and lineage hunting are supported. Twig does not support the mustache-specific syntax extensions, style modifiers and pattern parameters, because their use cases are addressed by the core Twig feature set.

lib/engine_twig.js

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* twig 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. Twig does not support
15+
* the mustache-specific syntax extensions, style modifiers and pattern
16+
* parameters, because their use cases are addressed by the core Twig feature
17+
* set.
18+
*
19+
*/
20+
21+
"use strict";
22+
23+
var Twig = require('twig');
24+
var twig = Twig.twig;
25+
26+
var engine_twig = {
27+
engine: Twig,
28+
engineName: 'twig',
29+
engineFileExtension: '.twig',
30+
31+
//Important! Needed for Twig compilation. Can't resolve paths otherwise.
32+
expandPartials: true,
33+
34+
// regexes, stored here so they're only compiled once
35+
findPartialsRE: /{%\s*(?:extends|include|embed)\s+('[^']+'|"[^"]+").*?%}/g,
36+
findPartialKeyRE: /"((?:\\.|[^"\\])*)"/,
37+
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, // TODO
38+
39+
// render it
40+
renderPattern: function renderPattern(pattern, data) {
41+
var result = twig({
42+
data: pattern.extendedTemplate
43+
}).render(data);
44+
45+
return result;
46+
},
47+
48+
// find and return any {% include 'template-name' %} within pattern
49+
findPartials: function findPartials(pattern) {
50+
var matches = pattern.template.match(this.findPartialsRE);
51+
return matches;
52+
},
53+
findPartialsWithStyleModifiers: function () {
54+
// TODO: make the call to this from oPattern objects conditional on their
55+
// being implemented here.
56+
return [];
57+
},
58+
59+
// returns any patterns that match {{> value(foo:"bar") }} or {{>
60+
// value:mod(foo:"bar") }} within the pattern
61+
findPartialsWithPatternParameters: function () {
62+
// TODO: make the call to this from oPattern objects conditional on their
63+
// being implemented here.
64+
return [];
65+
},
66+
findListItems: function (pattern) {
67+
var matches = pattern.template.match(this.findListItemsRE);
68+
return matches;
69+
},
70+
71+
// given a pattern, and a partial string, tease out the "pattern key" and
72+
// return it.
73+
findPartial: function (partialString) {
74+
//var partialKey = partialString.replace(this.findPartialsRE, '$1');
75+
var partial = partialString.match(this.findPartialKeyRE)[0];
76+
partial = partial.replace(/"/g, '');
77+
78+
return partial;
79+
}
80+
};
81+
82+
module.exports = engine_twig;

package.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"name": "patternengine-node-underscore",
3-
"description": "The Underscore engine for Pattern Lab / Node",
4-
"version": "1.1.1",
5-
"main": "lib/engine_underscore.js",
2+
"name": "patternengine-node-twig",
3+
"description": "The Twig engine for Pattern Lab / Node",
4+
"version": "0.1.0",
5+
"main": "lib/engine_twig.js",
66
"dependencies": {
7-
"underscore": "^1.8.3"
7+
"twig": "^0.9.5"
88
},
99
"devDependencies": {},
1010
"keywords": [
@@ -14,13 +14,13 @@
1414
"Grunt",
1515
"Gulp",
1616
"Javascript",
17-
"Underscore"
17+
"Twig"
1818
],
1919
"repository": {
2020
"type": "git",
21-
"url": "https://github.com/pattern-lab/patternengine-node-underscore.git"
21+
"url": "https://github.com/pattern-lab/patternengine-node-twig.git"
2222
},
23-
"bugs": "https://github.com/pattern-lab/patternengine-node-underscore/issues",
23+
"bugs": "https://github.com/pattern-lab/patternengine-node-twig/issues",
2424
"author": "Brian Muenzenmeyer & Geoffrey Pursell",
2525
"license": "MIT",
2626
"scripts": {

0 commit comments

Comments
 (0)