How to use the ejs.resolveInclude 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 koajs / ejs / index.js View on Github external
settings.root = path.resolve(process.cwd(), settings.root);

  /**
   * cache the generate package
   * @type {Object}
   */
  const cache = Object.create(null);

  settings = Object.assign({}, defaultSettings, settings);

  settings.viewExt = settings.viewExt
    ? '.' + settings.viewExt.replace(/^\./, '')
    : '';

  // override `ejs` node_module `resolveInclude` function
  ejs.resolveInclude = function(name, filename, isDir) {
    if (!path.extname(name)) {
      name += settings.viewExt;
    }
    return parentResolveInclude(name, filename, isDir);
  }

  /**
   * generate html with view name and options
   * @param {String} view
   * @param {Object} options
   * @return {String} html
   */
  async function render(view, options) {
    view += settings.viewExt;
    const viewPath = path.join(settings.root, view);
    debug(`render: ${viewPath}`);
github koajs / ejs / index.js View on Github external

'use strict';

/**
 * Module dependencies.
 */

const debug = require('debug')('koa-ejs');
const fs = require('mz').fs;
const path = require('path');
const ejs = require('ejs');

/**
 * Temp assigned for override later
 */
const parentResolveInclude = ejs.resolveInclude;

/**
 * default render options
 * @type {Object}
 */
const defaultSettings = {
  cache: true,
  layout: 'layout',
  viewExt: 'html',
  locals: {},
  compileDebug: false,
  debug: false,
  writeResp: true,
  async: false
};