context.js
945 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
const ContextView = require('../../lib/context_view');
const VIEW = Symbol('Context#view');
module.exports = {
/**
* Render a file, then set to body, the parameter is same as {@link @ContextView#render}
* @return {Promise} result
*/
render(...args) {
return this.renderView(...args).then(body => {
this.body = body;
});
},
/**
* Render a file, same as {@link @ContextView#render}
* @return {Promise} result
*/
renderView(...args) {
return this.view.render(...args);
},
/**
* Render template string, same as {@link @ContextView#renderString}
* @return {Promise} result
*/
renderString(...args) {
return this.view.renderString(...args);
},
/**
* View instance that is created every request
* @member {ContextView} Context#view
*/
get view() {
if (!this[VIEW]) {
this[VIEW] = new ContextView(this);
}
return this[VIEW];
},
};