2017-08-16 18:47:02 +02:00

54 lines
888 B
JavaScript
Executable File

'use strict';
/**
* Module dependencies
*/
// Native
const path = require('path');
// Externals
const co = require('co');
const render = require('koa-ejs');
const _ = require('lodash');
/**
* EJS hook
*/
module.exports = function (strapi) {
const hook = {
/**
* Default options
*/
defaults: {
root: path.join(strapi.config.appPath, strapi.config.paths.views),
layout: 'layout',
viewExt: 'ejs',
cache: true,
debug: true
},
/**
* Initialize the hook
*/
initialize: cb => {
// Force cache mode in production
if (strapi.config.environment === 'production') {
strapi.config.hook.settings.ejs.cache = true;
}
render(strapi.app, strapi.config.hook.settings.ejs);
strapi.app.context.render = co.wrap(strapi.app.context.render);
cb();
}
};
return hook;
};