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

Commit d3df3a3

Browse files
Ghoweri, Salem (BOS-GEN)Ghoweri, Salem (BOS-GEN)
authored andcommitted
Stashing changes - working Twig template includes!
1 parent 86ae226 commit d3df3a3

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
(function () {
22+
"use strict";
23+
24+
var Twig = require('twig/twig.js');
25+
var twig = Twig.twig;
26+
27+
var engine_twig = {
28+
engine: Twig,
29+
engineName: 'twig',
30+
engineFileExtension: '.twig',
31+
32+
//Important! Needed for Twig compilation. Can't resolve paths otherwise.
33+
expandPartials: true,
34+
35+
// regexes, stored here so they're only compiled once
36+
findPartialsRE: /{%([ ]+)?(?:extends|include|embed)(\s\S)(.*)%}/g,
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,
38+
39+
// render it
40+
renderPattern: function renderPattern(template, data) {
41+
var template = twig({
42+
data: template
43+
}).render(data);
44+
45+
return template;
46+
},
47+
48+
// find and return any {{> 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+
// returns any patterns that match {{> value(foo:"bar") }} or {{>
59+
// value:mod(foo:"bar") }} within the pattern
60+
findPartialsWithPatternParameters: function() {
61+
// TODO: make the call to this from oPattern objects conditional on their
62+
// being implemented here.
63+
return [];
64+
},
65+
findListItems: function(pattern) {
66+
var matches = pattern.template.match(this.findListItemsRE);
67+
return matches;
68+
},
69+
// given a pattern, and a partial string, tease out the "pattern key" and
70+
// return it.
71+
findPartialKey: function(partialString) {
72+
73+
// var partialKey = partialString.replace(this.findPartialsRE, '$1');
74+
var partialKey = partialString.match(/"((?:\\.|[^"\\])*)"/)[0];
75+
partialKey = partialKey.replace(/"/g, '');
76+
77+
return partialKey;
78+
}
79+
80+
81+
82+
83+
};
84+
85+
module.exports = engine_twig;
86+
})();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<style>
2+
.btn {
3+
padding: 10px;
4+
border-radius: 10px;
5+
display: inline-block;
6+
text-align: center;
7+
}
8+
</style>
9+
10+
<a href="#" class="btn">Button</a>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<img src="http://placeholdit.imgix.net/~text?txtsize=33&txt=280%C3%97220&w=280&h=220&fm=pjpg"
2+
srcset="http://placeholdit.imgix.net/~text?txtsize=33&txt=280%C3%97220&w=280&h=220&fm=pjpg 280w,
3+
http://placeholdit.imgix.net/~text?txtsize=33&txt=560%C3%97440&w=560&h=440&fm=pjpg 560w,
4+
http://placeholdit.imgix.net/~text?txtsize=33&txt=840%C3%97660&w=840&h=660&fm=pjpg 840w"
5+
sizes="100vw">
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<style>
2+
.Media {
3+
display: flex;
4+
align-items: flex-start;
5+
}
6+
7+
.Media > img {
8+
margin-right: 1em;
9+
max-width: 200px;
10+
}
11+
12+
.Media-body {
13+
flex: 1;
14+
}
15+
</style>
16+
17+
18+
<div class="Media">
19+
{% include "atoms-image" %}
20+
<p class="Media-body">Media Object body text</p>
21+
</div>

0 commit comments

Comments
 (0)