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

works with recursive parametered-partials functionality #3

Closed
wants to merge 1 commit into from
Closed
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: 19 additions & 2 deletions lib/engine_handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,26 @@ var engine_handlebars = {
Handlebars.registerPartial(pattern.patternPartial, pattern.template);
},

/**
* Find regex matches within both pattern strings and pattern objects.
*
* @param {string|object} pattern Either a string or a pattern object.
* @param {object} regex A JavaScript RegExp object.
* @returns {array|null} An array if a match is found, null if not.
*/
patternMatcher: function patternMatcher(pattern, regex) {
var matches;
if (typeof pattern === 'string') {
matches = pattern.match(regex);
} else if (typeof pattern === 'object' && typeof pattern.extendedTemplate === 'string') {
matches = pattern.extendedTemplate.match(regex);
}
return matches;
},

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

Expand Down