-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
35 lines (28 loc) · 968 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use strict'
const Handlebars = require('handlebars')
const transformer = {
name: 'handlebars',
inputFormats: ['hbs', 'handlebars'],
outputFormat: 'html',
handlebars: Handlebars,
}
transformer.compile = function (source, options) {
options = options || {}
for (const partial in options.partials || {}) {
if (Object.prototype.hasOwnProperty.call(options.partials, partial)) {
Handlebars.registerPartial(partial, options.partials[partial])
}
}
for (const helper in options.helpers || {}) {
if (Object.prototype.hasOwnProperty.call(options.helpers, helper)) {
Handlebars.registerHelper(helper, options.helpers[helper])
}
}
for (const decorator in options.decorators || {}) {
if (Object.prototype.hasOwnProperty.call(options.decorators, decorator)) {
Handlebars.registerDecorator(decorator, options.decorator[decorator])
}
}
return Handlebars.compile(source, options)
}
module.exports = transformer