-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathindex.js
More file actions
29 lines (23 loc) · 815 Bytes
/
index.js
File metadata and controls
29 lines (23 loc) · 815 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
var execPHP = require('exec-php');
var twigOptions = {
root: null,
extensions: [],
context: {}
};
exports.renderFile = function(entry, options, cb) {
// Merge the global options with the local ones.
options = Object.assign({}, twigOptions, options);
execPHP('php/Twig.php', null, function (error, php) {
// Call the callback on error or the render function on success.
error ? cb(error) : php.render(entry, options, function (error, stdout) {
// Call the callback with an error or the trimmed output.
error ? cb(error) : cb(null, stdout.trim());
});
});
};
exports.createEngine = function (options) {
// Merge the options with default options.
twigOptions = Object.assign(twigOptions, options);
return exports.renderFile;
};
exports.__express = exports.renderFile;