-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (17 loc) · 697 Bytes
/
index.js
File metadata and controls
27 lines (17 loc) · 697 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
const ejs = require('ejs')
, p = require('path')
;
module.exports = (config = {}) => (plugin) => {
const {ext = 'ejs', views = [], ...options} = config;
// tell ejs the root directory so includes with absolute paths can be resolved
if (!options.root) options.root = plugin.source;
plugin.registerRenderer(ext, (template, metadata, templateHelpers) => {
// add the current file's directory to the views array so that includes with relative paths can be resolved
const allViews = views.concat([p.join(plugin.source, metadata.dirname)]);
return ejs.render(
template,
{...metadata, ...templateHelpers},
{views: allViews, ...options},
);
});
}