/
ejs_engine.js
58 lines (43 loc) · 1.17 KB
/
ejs_engine.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* class EjsEngine
*
* Engine for the EJS compiler. You will need `ejs` Node module installed
* in order to use [[Mincer]] with `*.ejs` files:
*
* npm install ejs
*
* This is a mixed-type engine that can be used as a 'backend' of [[JstEngine]]
* as well as standalone 'middleware' processor in a pipeline.
*
*
* ##### SUBCLASS OF
*
* [[Template]]
**/
'use strict';
// 3rd-party
var ejs; // initialized later
// internal
var Template = require('../template');
////////////////////////////////////////////////////////////////////////////////
// Class constructor
var EjsEngine = module.exports = function EjsEngine() {
Template.apply(this, arguments);
ejs = ejs || Template.libs.ejs || require('ejs');
};
require('util').inherits(EjsEngine, Template);
// Render data
EjsEngine.prototype.evaluate = function (context, locals) {
if (this.nextProcessor && 'JstEngine' === this.nextProcessor.name) {
this.data = ejs.compile(this.data, {
filename: context.logicalPath,
client: true
}).toString();
return;
}
this.data = ejs.render(this.data, {
filename: context.pathname,
scope: context,
locals: locals
});
};