How to use ejs - 10 common examples

To help you get started, we’ve selected a few ejs 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 nrstott / bogart / tests / bogart / ejs-tests.js View on Github external
exports["test model variable is available in view"] = function() {
    // Arrange
    var name = "Bob";
    var view = "<h1>&lt;%= name %&gt;</h1>";
    var viewEJS = new EJS({ text: view });
    var layoutRenderer = new EjsLayoutRenderer(layoutEJS, {});

    // Act
    var result = layoutRenderer.render(viewEJS, { name: name });

    // Assert
    assert.isEqual(simpleLayout.replace("&lt;%= hold() %&gt;", view.replace("&lt;%= name %&gt;", name)), result);
};
github contentjet / contentjet-api / src / viewsets / ProjectInviteViewSet.ts View on Github external
const projectInvite = await super.create(ctx);
    let token = await ProjectInvite.generateInviteToken(
      projectInvite.id, project.name, project.id
    );
    token = token.replace(/\./g, '~');
    const context = {
      url: url.resolve(config.FRONTEND_URL, `/accept-invite/${token}`),
      projectName: project.name,
      name
    };
    const mailOptions = {
      from: config.MAIL_FROM,
      to: email,
      subject: 'You have been invited to join a project',
      text: ejs.render(projectInviteTXT, context),
      html: ejs.render(projectInviteHTML, context)
    };
    this.options.mail.sendMail(mailOptions)
      .then(info => {
        console.log('Message sent: %s', info.messageId); // tslint:disable-line
      })
      .catch(err => {
        console.error(err);
      });
    return projectInvite;
  }
github fengshi123 / express_project / app.js View on Github external
res.header('Content-Type', 'application/json;charset=utf-8');
  res.header('Content-Type', 'video/mp4');
  res.header('Content-Type', 'audio/mp3');
  if (mimeType[req.url.split('.').pop()]) {
    res.header('Content-Type', mimeType[req.url.split('.').pop()] + ';charset:UTF-8');
  }
  next();
});

app.post('*', bodyParser.urlencoded({ extended: true }),
  function (req, res, next) {
    next();
  });

// view engine setup
app.engine('html', ejs.__express);
app.set('view engine', 'html');
app.use('/public', function (req, res, next) {
  // 判断是否为音视频,注意移动版微信会带参数from=message
  const videoParamsIndex = req.url.indexOf('.mp4?');
  const audioParamsIndex = req.url.indexOf('.mp3?');
  let noParamsUrl = req.url;
  if (videoParamsIndex > -1 || audioParamsIndex > -1) {
    noParamsUrl = req.url.split('?').shift();
  }
  if (noParamsUrl.split('.').pop() === 'mp4') {
    res.header('Content-Type', 'video/mp4');
  } else if (noParamsUrl.split('.').pop() === 'mp3') {
    res.header('Content-Type', 'audio/mp3');
  } else {
    res.type('html');
  }
github vpetrov / survana / index.js View on Github external
*/

var express =   require('express'),
    DB      =   require('./db'),
    sconfig =   require("./config"),
    log     =   require('logule').init(module),
    path    =   require('path'),
    ejs     =   require('ejs'),
    ursa    =   require('ursa'),
    fs      =   require('fs'),
    util    =   require('./util'),
    //constants
    HTTP_SERVER_ERROR = 500;

ejs.open    =   '{{';
ejs.close   =   '}}';

/* Globals */
global.obj          =   require('./lib/obj');
global.arrays       =   require('./lib/arrays');
global.ClientError  =   require('./lib/clienterror');
global.ROOT         =   path.dirname(process.mainModule.filename);

/**
 * Mount a new Survana module
 * @param app
 * @param name
 * @param mconf
 * @return {Object}
 */
function addModule(app,name,mconf)
{
github vpetrov / survana / index.js View on Github external
* @license New BSD License (see LICENSE file for details).
 */

var express =   require('express'),
    DB      =   require('./db'),
    sconfig =   require("./config"),
    log     =   require('logule').init(module),
    path    =   require('path'),
    ejs     =   require('ejs'),
    ursa    =   require('ursa'),
    fs      =   require('fs'),
    util    =   require('./util'),
    //constants
    HTTP_SERVER_ERROR = 500;

ejs.open    =   '{{';
ejs.close   =   '}}';

/* Globals */
global.obj          =   require('./lib/obj');
global.arrays       =   require('./lib/arrays');
global.ClientError  =   require('./lib/clienterror');
global.ROOT         =   path.dirname(process.mainModule.filename);

/**
 * Mount a new Survana module
 * @param app
 * @param name
 * @param mconf
 * @return {Object}
 */
function addModule(app,name,mconf)
github LaurentVB / mongoose-manager / lib / express.js View on Github external
app.engine('html', viewEngine);
    app.set('view engine', 'html');
    app.set('views', __dirname + '/../views');

    app.use(express.favicon());
    app.use(express.static(__dirname + '/../public', {'maxAge': 0}));
    app.use(express.logger('dev'));
    app.use(express.bodyParser());
    app.use(express.methodOverride());
    app.use(express.cookieParser(options.secret || 'mongoose manager cookie secret'));
    app.use(express.session());
    app.use(require('connect-flash')());
    app.use(require('../views/helpers').init(this));
    app.use(app.router);

    _.extend(require('ejs').filters, require('../views/filters'));

    // development only
    if ('development' == app.get('env')) {
        app.use(express.errorHandler());
    }

    return app;
};
github fossasia / susper.com / node_modules / license-webpack-plugin / dist / LicenseWebpackPlugin.js View on Github external
.forEach(function (file) {
                            compilation.assets[file] = new webpack_sources_1.ConcatSource(ejs.render(_this.options.bannerTemplate, {
                                filename: outputPath,
                                licenseInfo: renderedFile.replace(/\*\//g, '') // remove premature comment endings
                            }), '\n', compilation.assets[file]);
                        });
                    }
github antwarjs / antwar / packages / antwar / src / build / worker.js View on Github external
context: {
            ...context,
            ...page.file,
            ...templates.page,
            cssFiles: [...templates.page.cssFiles, ...cssFiles],
            jsFiles: [...templates.page.jsFiles, ...jsFiles],
            html: $.html(),
          },
        });

        return writePage({ console, path, data, page }, cb);
      });
    }

    // No need to go through webpack so go only through ejs
    const data = ejs.compile(templates.page.file)({
      context: {
        ...context,
        ...page.file,
        ...templates.page,
        jsFiles: [...templates.page.jsFiles, ...jsFiles],
        html,
      },
    });

    return writePage({ console, path, data }, cb);
  });
}
github atomicjolt / react_client_starter_app / client / libs / build / content.js View on Github external
const parsed = frontMatter(content);
  const metadata = parsed.attributes;
  const title = metadata.title;
  const destination = metadata.permalink;
  const data = _.merge({
    _,
    title,
    metadata,
    url: destination
  }, app.templateData);

  let html = parsed.body;

  try {
    // Allow ejs code in content
    html = ejs.compile(html, {
      cache: false,
      filename: fullPath
    })(data);

    // Parse any markdown in the resulting html
    if (_.includes(app.htmlOptions.markdownExtensions, ext)) {
      html = marked(html);
    }
  } catch (err) {
    log.error(`Unable to compile html from ${fullPath}`);
    throw err;
    // Uncomment the following for more details
    // log.error(err);
    // log.error('Call stack');
    // log.error(err.stack);
  }
github chiedolabs / swag-doctor / swag-doctor.js View on Github external
#! /usr/bin/env node
'use strict';
require('babel-register');
let argv   = require('yargs').argv;
let path   = require('path');
let _      = require('lodash');
let fs     = require('fs');
let ncp    = require('ncp').ncp;
let ejs    = require('ejs');
let chalk = require('chalk');
let pjson = require('./package.json');
// Get the execution directory
let cwd = path.resolve('.');

let templateFile = fs.readFileSync(`${__dirname}/templates/index.ejs`).toString();
let template     = ejs.compile(templateFile);

let outputDir = _.trimEnd(argv.o, '/');

const generateDocs = (data, key) => {

  let html         = template({
    swagDocData: data,
    js: 'static/js/react-bundle.js',
    css: 'static/css/style.css',
  });

  // Save the doc data file
  fs.writeFile(`${cwd}/${outputDir}/${key.toLowerCase()}.html`, html , 'utf8', () => {
  });
};