Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_.forEach(opts.map, engine => {
if (!consolidate.requires[engine]) {
// Try to require them using `consolidate` or throw an error.
try {
consolidate.requires[engine] = require(path.resolve(
strapi.config.appPath,
'node_modules',
engine
));
} catch (err) {
strapi.log.error(
'`' + engine + '` template engine not installed.'
);
strapi.log.error(
'Execute `$ npm install ' + engine + ' --save` to install it.'
);
process.exit(1);
}
}
// Initialize the engine with `consolidate`.
if (typeof opts === 'string') {
opts = {engine: opts};
}
// An engine should be specified
if (!opts.engine) {
throw new Error('"engine" option required');
}
// Throw an error for unsupported engines or typos
if (!consolidate[opts.engine]) {
throw new Error('Unknown template engine: "' + opts.engine + '"');
}
if (typeof opts.exposeConsolidate === 'function') {
opts.exposeConsolidate(consolidate.requires)
}
// Map options to local variables
var engine = opts.engine;
var partials = opts.partials;
var pattern = opts.pattern;
var rename = opts.rename;
// Move all unrecognised options to params
var params = omit(opts, settings);
/**
* Main plugin function
*/
return function(files, metalsmith, done){
var metadata = metalsmith.metadata();
_.forEach(opts.map, engine => {
if (!consolidate.requires[engine]) {
// Try to require them using `consolidate` or throw an error.
try {
consolidate.requires[engine] = require(path.resolve(
strapi.config.appPath,
'node_modules',
engine
));
} catch (err) {
strapi.log.error(
'`' + engine + '` template engine not installed.'
);
strapi.log.error(
'Execute `$ npm install ' + engine + ' --save` to install it.'
);
process.exit(1);
}
// Consolidate, to make beautiful templates in nunjucks
var cons = require('consolidate')
, nunjucks = require('nunjucks')
// Add mlmmj service wrapper module
var Mlmmj = require('./services/MlmmjWrapper')
var app = express()
/* Configuration is done here
*/
// add nunjucks to requires so filters can be
// added and the same instance will be used inside the render method
cons.requires.nunjucks = nunjucks.configure();
cons.requires.nunjucks.addGlobal('website_name', config.get('app').name);
// Handy flash messages
app.use(flash())
// Use sessions
app.use(session({ name: "mlmmj.web.session.id", secret: 'mlmmjNotSoSecretPhrase', cookie: { maxAge: null }, resave: true, saveUninitialized: true }))
// Use passport-local auth system with persistent sessions
app.use(passport.initialize())
app.use(passport.session())
// Static content
app.use(express.static(__dirname + '/public'))
// .. parse application/x-www-form-urlencoded
function setupViews(options: AppOptions) {
const { parent } = options;
// Configure the default views directory.
const views = path.join(__dirname, "views");
parent.set("views", views);
// Reconfigure nunjucks.
(cons.requires as any).nunjucks = nunjucks.configure(views, {
// In development, we should enable file watch mode, and prevent file
// caching.
watch: options.config.get("env") === "development",
noCache: options.config.get("env") === "development",
});
// assign the nunjucks engine to .njk and .html files.
parent.engine("html", cons.nunjucks);
// set .html as the default extension.
parent.set("view engine", "html");
}
// Consolidate, to make beautiful templates in nunjucks
var cons = require('consolidate')
, nunjucks = require('nunjucks')
// Add mlmmj service wrapper module
var Mlmmj = require('./services/MlmmjWrapper')
var app = express()
/* Configuration is done here
*/
// add nunjucks to requires so filters can be
// added and the same instance will be used inside the render method
cons.requires.nunjucks = nunjucks.configure();
cons.requires.nunjucks.addGlobal('website_name', config.get('app').name);
// Handy flash messages
app.use(flash())
// Use sessions
app.use(session({ name: "mlmmj.web.session.id", secret: 'mlmmjNotSoSecretPhrase', cookie: { maxAge: null }, resave: true, saveUninitialized: true }))
// Use passport-local auth system with persistent sessions
app.use(passport.initialize())
app.use(passport.session())
// Static content
app.use(express.static(__dirname + '/public'))
// .. parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
et.render(locals, function (err, result) {
result = result || {}
next(err, result.html, result.text, result.subject, result.deeplink)
})
})
}
et.render(locals, function (err, result) {
result = result || {}
callback(err, result.html, result.text, result.subject, result.deeplink)
})
}
}
exportable.EmailTemplate = EmailTemplate
exportable.requires = require('consolidate').requires
module.exports = exportable
constructor (options) {
this.options = Object.assign({
input:(ctx) => Promise.resolve(ctx),
render: consolidate.ejs,
renderString: consolidate.requires.ejs.render,
modules: {}
}, options);
}