How to use the ejs.compile function in ejs

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 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', () => {
  });
};
github baidu / san / test / perf / list.js View on Github external
<p>$\{ item.desc }</p>
            <div class="todo-meta">
                
                <span>$\{ item.category.title } | </span>
                
            </div>
            <a href="/edit/$\{ item.id }" class="fa fa-pencil"></a>
            <i class="fa fa-check></i>
            <i class="></i>
        
        
    

`);

let ejsRenderer = ejs.compile(`
<div class="todos">
    <a class="todo-add" href="#/add"><i class="fa fa-plus-square"></i></a>
    <ul class="filter-category">
        &lt;% for(let i = 0; i &lt; categories.length; i++){ let item = categories[i]; %&gt;
        <li style="background: <%= item.color %>">
            <a href="/todos/category/<%= item.id %>">&lt;%= item.title %&gt;</a>
        </li>
        &lt;% } %&gt;
    </ul>

    <ul class="todo-list">
        &lt;% for(let index = 0; index &lt; todos.length; index++){ let item = todos[index]; %&gt;
        <li class="<%= item.done ? 'todo-done' : ''%>" style="border-color: <%= item.category.color%>">
            <h3>&lt;%=  item.title %&gt;</h3></li></ul></div>
github windsome / koa3-wechat / src / wechat.js View on Github external
'&lt;% } else if (msgType === "transfer_customer_service") { %&gt;',
  '&lt;% if (content &amp;&amp; content.kfAccount) { %&gt;',
  '',
  ']]&gt;',
  '',
  '&lt;% } %&gt;',
  '&lt;% } else { %&gt;',
  '<content>]]&gt;</content>',
  '&lt;% } %&gt;',
  ''
].join('');

/*!
 * 编译过后的模版
 */
const compiled = ejs.compile(tpl);

const wrapTpl =
  '' +
  ']]&gt;' +
  ']]&gt;' +
  '&lt;%-timestamp%&gt;' +
  ']]&gt;' +
  '';

const encryptWrap = ejs.compile(wrapTpl);

export default class Wechat {
  static propTypes = {
    goBack: -1
  };
github aigis-styleguide / aigis / lib / renderer / tree.js View on Github external
function renderCategoryTree(tree, depth, root) {
  var ul = ejs.compile(
    '<ul data-path-depth="<%- depth %>" class="aigis-categoryList">' +
      '&lt;% children.forEach(function(child) { %&gt;&lt;%- child %&gt;&lt;% }) %&gt;' +
    '</ul>'
  );

  var li = ejs.compile(
    '<li data-path-depth="<%- depth %>" class="aigis-categoryList__item">' +
      ' href="&lt;%- href %&gt;"&lt;% } %&gt;&gt;&lt;%- name %&gt;' +
      '&lt;%- children %&gt;' +
    '</li>'
  );

  if (!tree) {
    return '';
  }
  var node = ul({
github vivocha / arrest / src / resource.js View on Github external
function _getTemplate(name) {
  var data = fs.readFileSync(__dirname + '/../data/defaults/' + name + '.json', 'ascii');
  return ejs.compile(data, {});
}
function _mergeRoutes() {
github fibjs / fibjs / tools / util / gen_docs.js View on Github external
function gen_idl() {
        var _idl = ejs.compile(fs.readTextFile(path.join(__dirname, './tmpl/idl.md')));

        for (var m in defs) {
            var p = path.join(docsFolder, defs[m].declare.type == 'module' ? "module" : "object", "ifs", m + ".md");
            var md = _idl(defs[m]);
            md = md.replace(/\n\s+```/g, '\n```');

            md = md.replace(/\n```JavaScript\s+((.|\n)*?)\s+```\s+/gi, function (s, p1, p2, p3) {
                return '\n\n```JavaScript\n' + beautify(p1.replace(/\n( |\t)*/g, '\n')).replace(/^static\(/g, 'static (') + '\n```\n\n';
            });

            md = md.replace(/\n\n+/g, '\n\n');

            fs.writeFile(p, md);
        }
    }
github fraunhoferfokus / peer-upnp / lib / peer-upnp.js View on Github external
var http = require('http');
var util = require('util');
var UUID = require('node-uuid');
var ssdp = require('peer-ssdp');
//var ssdp = require('ssdp');
var ROOT_DEVICE = "upnp:rootdevice";
var UPNP_VERSION = "UPnP/1.1";
var OS_NAME = os.type() || "unknown";
var OS_VERSION = os.release() || "0.0";
var INTERVAL = 10000;
var DEVICE_TEMPLATE = fs.readFileSync(__dirname + '/../xml/device-desc.xml', 'utf8');
var SERVICE_TEMPLATE = fs.readFileSync(__dirname + '/../xml/service-desc.xml', 'utf8');
var SOAP_REQ_TEMPLATE = fs.readFileSync(__dirname + '/../xml/soap-req.xml', 'utf8');
var SOAP_RSP_TEMPLATE = fs.readFileSync(__dirname + '/../xml/soap-rsp.xml', 'utf8');
var EVENT_TEMPLATE = fs.readFileSync(__dirname + '/../xml/event.xml', 'utf8');
var RENDER_DEVICE = ejs.compile(DEVICE_TEMPLATE);
var RENDER_SERVICE = ejs.compile(SERVICE_TEMPLATE);
var RENDER_SOAP_REQ = ejs.compile(SOAP_REQ_TEMPLATE);
var RENDER_SOAP_RSP = ejs.compile(SOAP_RSP_TEMPLATE);
var RENDER_EVENT = ejs.compile(EVENT_TEMPLATE);

var SSDP_ALL = "ssdp:all";
var UPnPError = function(message,code) {
	Error.call(this);
	Error.captureStackTrace(this, this.constructor);
	this.name = "UPnPError";
	this.message = message;
	this.code = parseInt(code) || 0;
};
util.inherits(UPnPError, Error);

var createPeer = function(options){