| 
									
										
										
										
											2016-12-18 12:57:25 +01:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Module dependencies | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Native
 | 
					
						
							|  |  |  | const path = require('path'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Externals
 | 
					
						
							|  |  |  | const co = require('co'); | 
					
						
							|  |  |  | const render = require('koa-ejs'); | 
					
						
							| 
									
										
										
										
											2017-07-24 19:58:03 +02:00
										 |  |  | const _ = require('lodash'); | 
					
						
							| 
									
										
										
										
											2016-12-18 12:57:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * EJS hook | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = function (strapi) { | 
					
						
							|  |  |  |   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, | 
					
						
							|  |  |  |       debug: true | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2016-12-18 12:57:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Initialize the hook | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     initialize: cb => { | 
					
						
							| 
									
										
										
										
											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
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-26 18:53:48 +02:00
										 |  |  |       render(strapi.app, strapi.config.hook.settings.ejs); | 
					
						
							| 
									
										
										
										
											2016-12-18 12:57:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       strapi.app.context.render = co.wrap(strapi.app.context.render); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       cb(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return hook; | 
					
						
							|  |  |  | }; |