-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
29 lines (22 loc) · 749 Bytes
/
index.js
File metadata and controls
29 lines (22 loc) · 749 Bytes
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
'use strict'
const {TwingEnvironment, TwingLoaderFilesystem} = require('twing')
exports.name = 'twing'
exports.inputFormats = ['twing', 'twig']
exports.outputFormat = 'html'
exports.renderFile = function (filename, options, locals) {
// Construct the Twig options.
options = options || {}
if ('filename' in options && !('path' in options)) {
options.path = options.filename
}
if (!options.root) {
options.root = process.cwd()
}
// Initialize Twing
const loader = new TwingLoaderFilesystem(options.root)
const twing = new TwingEnvironment(loader)
// Remove the root from the filename if it's present.
filename = filename.replace(options.root, '')
const output = twing.render(filename, locals)
return output
}