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

Dev #5

Merged
merged 2 commits into from
Nov 13, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions lib/engine_handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@

var Handlebars = require('handlebars');

// regexes, stored here so they're only compiled once
const findPartialsRE = /{{#?>\s*([\w-\/.]+)(?:.|\s+)*?}}/g;
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;
const findAtPartialBlockRE = /{{#?>\s*@partial-block\s*}}/g;

function escapeAtPartialBlock(partialString) {
var partial = partialString.replace(findAtPartialBlockRE, '{{> @partial-block }}')
return partial;
}

var engine_handlebars = {
engine: Handlebars,
engineName: 'handlebars',
Expand All @@ -33,15 +43,12 @@ var engine_handlebars = {
// style modifiers or pattern parameters (I think)
expandPartials: false,

// regexes, stored here so they're only compiled once
findPartialsRE: /{{#?>\s*([\w-\/.]+)(?:.|\s+)*?}}/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(pattern, data, partials) {
if (partials) {
Handlebars.registerPartial(partials);
}
pattern.extendedTemplate = escapeAtPartialBlock(pattern.extendedTemplate);
var compiled = Handlebars.compile(pattern.extendedTemplate);
return compiled(data);
},
Expand All @@ -56,7 +63,7 @@ var engine_handlebars = {

// find and return any {{> template-name }} within pattern
findPartials: function findPartials(pattern) {
var matches = pattern.template.match(this.findPartialsRE);
var matches = pattern.template.match(findPartialsRE);
return matches;
},
findPartialsWithStyleModifiers: function () {
Expand All @@ -73,14 +80,14 @@ var engine_handlebars = {
return [];
},
findListItems: function (pattern) {
var matches = pattern.template.match(this.findListItemsRE);
var matches = pattern.template.match(findListItemsRE);
return matches;
},

// given a pattern, and a partial string, tease out the "pattern key" and
// return it.
findPartial: function (partialString) {
var partial = partialString.replace(this.findPartialsRE, '$1');
var partial = partialString.replace(findPartialsRE, '$1');
return partial;
}
};
Expand Down