How to use the nunjucks.configure function in nunjucks

To help you get started, we’ve selected a few nunjucks 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 Adezandee / cucumber-mink / test / site / server.js View on Github external
const app = express();
const config = {
  port: 3000,
};

// Middlewares
app.use(express.static(path.join(__dirname, 'public')));
app.use(morgan('dev'));

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

// View engine
app.set('view engine', 'html');
nunjucks.configure(path.join(__dirname, 'views'), {
  express: app,
});

app.get('/', routes.index);
app.get('/action', routes.action);
app.get('/responsive', routes.responsive);
app.get('/form', routes.form);
app.get('/keys', routes.keys);
app.post('/result', routes.result);
app.get('/post/:id', routes.post);
app.get('/generate/:number', routes.generate);

app.listen(config.port, () => {
  console.log(`App server running at http://localhost:${config.port}`);
});
github umrum / umrum / config / app.js View on Github external
var app = express(),
    oneDay = 86400000;

app.use(express.compress(), {
    maxAge: oneDay
});
app.locals.assetsURL = env.assetsURL;
app.set('views', env.views);
app.set('redis', redis);
app.engine('html', nunjucks.render);
app.use(app.locals.assetsURL, express.static(env.assetsPath));
app.use(express.logger());
app.use(app.router);

nunjucks.configure(env.views, {
    autoescape: true,
    express: app
});

app.listen(env.port, function(err) {
    if (err) {
        console.error(err);
        process.exit(-1);
    }

    // if run as root, downgrade to the owner of this file
    if (process.platform.toLowerCase().indexOf('win') === -1) {
        if ( process.getuid() === 0 ) {
            fs.stat(__filename, function(err, stats) {
                if (err) {
                    return console.error(err);
github lore / lore / packages / lore-generate / src / fileWriters / TemplateFileWriter.js View on Github external
write: function(source, target, options) {
    // console.log(source);
    // console.log(options);

    var dirname = path.dirname(source);
    var basename = path.basename(source);

    nunjucks.configure(dirname);

    var data = nunjucks.render(basename, _.merge({}, options, {
      _: _
    }));

    return writeFile(target, data, options);
  }
github soomtong / blititor / core / index.js View on Github external
moment.locale(BLITITOR.config.locale);

// ready server
const app = express();
const server = http.Server(app);
const sio = socketIO(server);
const bootstrapArgv = args(process.argv.slice(2));

// set express app
app.set('views', 'theme');
app.set('view engine', 'html');
//app.set('view cache', false);
app.set('port', bootstrapArgv['port'] || bootstrapArgv.p || BLITITOR.site.service.port);

// set template engine
nunjucks.configure(app.get('views'), {
    express: app,
    noCache: true
});

// using Express behind nginx
if (BLITITOR.env === 'production') {
    app.enable('trust proxy');
    winston.info('Use trust proxy mode for Nginx');
}

// bind socket.io to global for convenience
if (!BLITITOR._socketIO) {
    BLITITOR._socketIO = sio;
}

// use express middleware
github alphagov / govuk-prototype-kit / server.js View on Github external
}

// Ask for username and password on production
if (env === 'production' && useAuth === 'true') {
  app.use(utils.basicAuth(username, password))
}

// Set up App
var appViews = [
  path.join(__dirname, '/node_modules/govuk-frontend/'),
  path.join(__dirname, '/node_modules/govuk-frontend/components'),
  path.join(__dirname, '/app/views/'),
  path.join(__dirname, '/lib/')
]

var nunjucksAppEnv = nunjucks.configure(appViews, {
  autoescape: true,
  express: app,
  noCache: true,
  watch: true
})

// Add Nunjucks filters
utils.addNunjucksFilters(nunjucksAppEnv)

// Set views engine
app.set('view engine', 'html')

// Middleware to serve static assets
app.use('/public', express.static(path.join(__dirname, '/public')))
app.use('/assets', express.static(path.join(__dirname, 'node_modules', 'govuk-frontend', 'assets')))
github node-weixin / node-weixin-express / lib / template.js View on Github external
}
  } else {
    templatePath = 'views';
    templatePath = path.resolve(__dirname, templatePath);
  }
  assert(templatePath);
  console.log(templatePath);
  console.log(file);
  if (file) {
    realFile = path.join(templatePath, file);
  }
  nunjucks.configure({
    autoescape: true
  });
  if (realFile && fs.existsSync(realFile)) {
    renderer = nunjucks.configure(
      templatePath,
      {
        watch: true
      }
    );
    return renderer.render(file, config);
  }

  renderer = nunjucks.configure(
    path.resolve(__dirname, 'views'),
    {
      watch: true
    }
  );
  return renderer.render('404.html');
};
github btford / quinoa / bin.js View on Github external
function getNunjucksEnviornment () {
  var env = nunjucks.configure(inputDirectory);
  env.addFilter('markdown', function (str) {
    return marked(str);
  });
  env = hackNunjucksEnviornment(env);
  return env;
}
github heiseonline / embetty-server / index.js View on Github external
const { NotFound } = require('./lib/exceptions')
const { URL } = require('url')
const Embetty = require('@heise/embetty-base')
const express = require('express')
const helmet = require('helmet')
const logger = require('morgan')
const nunjucks = require('nunjucks')
const routes = require('./routes')

const app = express()

nunjucks
  .configure('views', {
    autoescape: true,
    express: app
  })
  .addGlobal('urlFor', path => {
    const urlBase = process.env.URL_BASE
    if (!urlBase) throw new Error('URL_BASE not set.')
    const url = new URL(path, urlBase)
    return url.toString().replace(/\/$/, '')
  })

app.set('embetty', new Embetty())

app.use(logger(process.env.NODE_ENV === 'production' ? 'short' : 'dev', {
  skip: (req, res) => process.env.NODE_ENV === 'test'
}))
github open-ness / epcforedge / cnca / ui / cnca / server / server.js View on Github external
*/

const express = require('express');
const dotenv = require('dotenv');
const nunjucks = require('nunjucks');
const helmet = require('helmet');
const uuidv4 = require('uuid/v4');
const path = require('path');

const port = 80;

const app = express();

dotenv.config();

nunjucks.configure('build', {
  autoescape: true,
  express: app
});

app.use(helmet());

app.use((req, res, next) => {
  res.locals.styleNonce = Buffer.from(uuidv4()).toString('base64');
  next();
});

app.use(
  helmet.contentSecurityPolicy({
    directives: {
      defaultSrc: ["'self'"],
      styleSrc: ["'self'", (req, res) => `'nonce-${res.locals.styleNonce}'`],
github xtemplate / xtpl / benchmark / index.js View on Github external
* @author yiminghe@gmail.com
 */

var Benchmark = require('benchmark');
var xtpl = require('../index');
var path = require('path');
var jade = require('jade');
var ejs = require('ejs');
var dust = require('dustjs-linkedin');
var handlebars = require('handlebars');
var nunjucks = require('nunjucks');
var consolidate = require('consolidate');
var hbs = require('hbs').create(handlebars);
var util = require('kissy/lib/util');
hbs.registerPartials(__dirname + '/views/includes', done);
nunjucks.configure(__dirname + '/views/includes');

function done() {
    var data = {
        cache: true,
        settings: {
            views: __dirname + '/views/includes'
        },
        title: 'Demo',
        views: path.join(__dirname, 'views'),
        using: true,
        lis: [
            {
                d: 'one'
            },
            {
                d: 'two'