2016-12-18 12:57:25 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Native
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
// Externals
|
|
|
|
const co = require('co');
|
2019-07-19 11:26:56 +02:00
|
|
|
const render = require('koa-ejs');
|
2016-12-18 12:57:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* EJS hook
|
|
|
|
*/
|
|
|
|
|
2019-08-14 14:15:45 +02:00
|
|
|
module.exports = function(strapi) {
|
2016-12-18 12:57:25 +01:00
|
|
|
const hook = {
|
|
|
|
/**
|
|
|
|
* Default options
|
|
|
|
*/
|
|
|
|
|
2016-12-20 20:42:52 +01:00
|
|
|
defaults: {
|
|
|
|
root: path.join(strapi.config.appPath, strapi.config.paths.views),
|
|
|
|
layout: 'layout',
|
|
|
|
viewExt: 'ejs',
|
|
|
|
cache: true,
|
2019-08-14 14:15:45 +02:00
|
|
|
debug: true,
|
2016-12-20 20:42:52 +01:00
|
|
|
},
|
2016-12-18 12:57:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the hook
|
|
|
|
*/
|
|
|
|
|
2019-10-01 17:56:52 +02:00
|
|
|
initialize() {
|
2017-01-15 17:52:20 +01:00
|
|
|
// Force cache mode in production
|
|
|
|
if (strapi.config.environment === 'production') {
|
2017-07-31 12:12:51 +02:00
|
|
|
strapi.config.hook.settings.ejs.cache = true;
|
2017-01-15 17:52:20 +01:00
|
|
|
}
|
|
|
|
|
2019-10-01 17:56:52 +02:00
|
|
|
render(
|
|
|
|
strapi.app,
|
|
|
|
Object.assign(this.defaults, strapi.config.hook.settings.ejs)
|
|
|
|
);
|
2016-12-18 12:57:25 +01:00
|
|
|
|
|
|
|
strapi.app.context.render = co.wrap(strapi.app.context.render);
|
2019-08-14 14:15:45 +02:00
|
|
|
},
|
2016-12-18 12:57:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return hook;
|
|
|
|
};
|