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

Commit 9cb20b5

Browse files
committed
Merge branch 'dev'
2 parents 47cc494 + 5e0b048 commit 9cb20b5

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

lib/engine_handlebars.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,26 @@
1414
* Full. Partial calls and lineage hunting are supported. Handlebars does not
1515
* support the mustache-specific syntax extensions, style modifiers and pattern
1616
* parameters, because their use cases are addressed by the core Handlebars
17-
* feature set.
17+
* feature set. It also does not support verbose partial syntax, because it
18+
* seems like it can't tolerate slashes in partial names. But honestly, did you
19+
* really want to use the verbose syntax anyway? I don't.
1820
*
1921
*/
2022

2123
"use strict";
2224

2325
var Handlebars = require('handlebars');
2426

27+
// regexes, stored here so they're only compiled once
28+
const findPartialsRE = /{{#?>\s*([\w-\/.]+)(?:.|\s+)*?}}/g;
29+
const 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;
30+
const findAtPartialBlockRE = /{{#?>\s*@partial-block\s*}}/g;
31+
32+
function escapeAtPartialBlock(partialString) {
33+
var partial = partialString.replace(findAtPartialBlockRE, '{{> @partial-block }}')
34+
return partial;
35+
}
36+
2537
var engine_handlebars = {
2638
engine: Handlebars,
2739
engineName: 'handlebars',
@@ -31,26 +43,27 @@ var engine_handlebars = {
3143
// style modifiers or pattern parameters (I think)
3244
expandPartials: false,
3345

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-
3846
// render it
3947
renderPattern: function renderPattern(pattern, data, partials) {
4048
if (partials) {
4149
Handlebars.registerPartial(partials);
4250
}
51+
pattern.extendedTemplate = escapeAtPartialBlock(pattern.extendedTemplate);
4352
var compiled = Handlebars.compile(pattern.extendedTemplate);
4453
return compiled(data);
4554
},
4655

4756
registerPartial: function (pattern) {
57+
// register exact partial name
4858
Handlebars.registerPartial(pattern.patternPartial, pattern.template);
59+
60+
// register verbose syntax? No, it seems that Handlebars can't tolerate
61+
// slashes in partial names.
4962
},
5063

5164
// find and return any {{> template-name }} within pattern
5265
findPartials: function findPartials(pattern) {
53-
var matches = pattern.template.match(this.findPartialsRE);
66+
var matches = pattern.template.match(findPartialsRE);
5467
return matches;
5568
},
5669
findPartialsWithStyleModifiers: function () {
@@ -67,14 +80,14 @@ var engine_handlebars = {
6780
return [];
6881
},
6982
findListItems: function (pattern) {
70-
var matches = pattern.template.match(this.findListItemsRE);
83+
var matches = pattern.template.match(findListItemsRE);
7184
return matches;
7285
},
7386

7487
// given a pattern, and a partial string, tease out the "pattern key" and
7588
// return it.
7689
findPartial: function (partialString) {
77-
var partial = partialString.replace(this.findPartialsRE, '$1');
90+
var partial = partialString.replace(findPartialsRE, '$1');
7891
return partial;
7992
}
8093
};

0 commit comments

Comments
 (0)