How to use the consolidate.nunjucks function in consolidate

To help you get started, we’ve selected a few consolidate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shmoop207 / appolo / test / mock / config / middlewares / all.js View on Github external
module.exports = function (app, env) {
    app.use(bodyParser.urlencoded({
        extended: true,
        parameterLimit: 10000,
        limit: 1024 * 1024 * 10
    }));
    app.use(bodyParser.json({
        //parameterLimit: 10000,
        limit: 1024 * 1024 * 10
    }));
    app.viewEngine(consolidate.nunjucks);
    app.use(cookieParser());
    app.use(serve(path.join(__dirname, "../../uploads")));
    app.use(function (req, res, next) {
        res.setHeader("Access-Control-Allow-Origin", req.headers.origin || '*');
        res.setHeader("Access-Control-Allow-Credentials", "true");
        res.setHeader("Cache-Control", "max-age=0, no-cache, must-revalidate, proxy-revalidate");
        res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
        res.setHeader("P3P", 'CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
        res.setHeader("Access-Control-Allow-Methods", "GET, PUT, PATCH, DELETE, HEAD, OPTIONS");
        res.setHeader("Allow", "GET, PUT, PATCH, DELETE, HEAD, OPTIONS");
        //
        // intercept OPTIONS method
        if (req.method == 'OPTIONS') {
            res.setHeader('Content-Length', '0');
            res.statusCode = 204;
            res.end();
github coralproject / talk / app.js View on Github external
//==============================================================================

// configure the default views directory.
const views = path.join(__dirname, 'views');
app.set('views', views);

// reconfigure nunjucks.
cons.requires.nunjucks = nunjucks.configure(views, {
  autoescape: true,
  trimBlocks: true,
  lstripBlocks: true,
  watch: process.env.NODE_ENV === 'development',
});

// assign the nunjucks engine to .njk files.
app.engine('njk', cons.nunjucks);

// assign the ejs engine to .ejs and .html files.
app.engine('ejs', cons.ejs);
app.engine('html', cons.ejs);

// set .ejs as the default extension.
app.set('view engine', 'ejs');

//==============================================================================
// ROUTES
//==============================================================================

debug(`mounting routes on the ${MOUNT_PATH} path`);

// Actually apply the routes.
app.use(MOUNT_PATH, routes);
github coralproject / talk / src / core / server / app / index.ts View on Github external
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");
}
github forwardemail / email-templates / src / template-manager.js View on Github external
/**
 * Small utility module for compling HTML templates or pre-processed CSS.
 *
 * @author: [@jasonsims]('https://github.com/jasonsims')
 */

import {extname, dirname, basename} from 'path'
import cons from 'consolidate'
import P from 'bluebird'

var engineMap = {
  // HTML Template engines
  'html': renderDefault,
  'hbs': cons.handlebars.render,
  'njk': cons.nunjucks.render,
  'emblem': renderEmblem,
  // CSS pre-processors
  'less': renderLess,
  'stylus': renderStylus,
  'styl': renderStyl,
  'sass': renderSass,
  'scss': renderSass,
  // Handle plain CSS also
  'css': renderDefault,
  // Handle plain text
  'txt': renderDefault,
  // Handle missing extension
  '': renderDefault
}

export function render (file, locals = {}, callback) {
github tchapi / mlmmj-simple-web-interface / index.js View on Github external
// 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 }))

  // .. parse application/json
  app.use(bodyParser.json())

  // Assign the swig engine to .html files
  app.engine('html', cons.nunjucks)

  // Set .html as the default extension
  app.set('view engine', 'html')
  app.set('views', __dirname + '/views')

/* End Express Configuration
*/

// Passport users setup.
function findByUsername(username, fn) {
  for (var i = 0, len = config.get('users').length; i < len; i++) {
    var user = config.get('users')[i]
    if (user.username === username) {
      return fn(null, user)
    }
  }

consolidate

Modern and maintained fork of the template engine consolidation library. Maintained and supported by Forward Email <https://forwardemail.net>, the 100% open-source and privacy-focused email service.

MIT
Latest version published 4 months ago

Package Health Score

81 / 100
Full package analysis