-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
27 lines (23 loc) · 908 Bytes
/
app.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
'use strict';
const path = require('path');
const scratSwig = require('scrat-swig');
module.exports = app => {
const swigPagelet = app.config.swigPagelet;
const config = Object.assign({ swig: app.swig, map: swigPagelet.manifest }, swigPagelet);
scratSwig.configure(config);
// monkey patch `escape` with `app.helper.escape` provided by `egg-security` for better performance
const escape = app.Helper.prototype.escape;
if (escape) {
app.swig.filters.escape = app.swig.filters.e = escape;
app.swig.setFilter('escape', escape);
app.swig.setFilter('e', escape);
}
for (const unit of app.loader.getLoadUnits()) {
const filterPath = path.join(unit.path, 'app/extend/filter.js');
const filters = app.loader.loadFile(filterPath) || {};
for (const name of Object.keys(filters)) {
app.swig.setFilter(name, filters[name]);
}
}
app.pageletEngine = scratSwig;
};