Update api reference docs from review comments. Uses latest brodocs release.

This commit is contained in:
Phillip Wittrock
2017-01-03 08:51:38 -08:00
parent 39fe9ab8e8
commit cc12b16d99
240 changed files with 14530 additions and 9984 deletions
+51 -26
View File
@@ -1,10 +1,11 @@
var fs = require('fs')
, buildOpts = {
printStdout: true
, printStderr: true
};
var execSync = require('child_process').execSync;
var exec = function (cmd) {
execSync(cmd, {stdio: 'inherit'});
};
task('build', ['browserify', 'minify'], function () {
/* global jake, task, desc, publishTask */
task('build', ['lint', 'clean', 'browserify', 'minify'], function () {
console.log('Build completed.');
});
@@ -12,33 +13,57 @@ desc('Cleans browerified/minified files and package files');
task('clean', ['clobber'], function () {
jake.rmRf('./ejs.js');
jake.rmRf('./ejs.min.js');
console.log('Cleaned up compiled files.');
});
task('browserify', {async: true}, function () {
jake.exec('./node_modules/browserify/bin/cmd.js --standalone ejs lib/ejs.js > ejs.js',
buildOpts, function () {
console.log('Browserification completed.');
setTimeout(complete, 0);
});
desc('Lints the source code');
task('lint', function () {
exec('./node_modules/.bin/eslint \"**/*.js\" Jakefile');
console.log('Linting completed.');
});
task('minify', {async: true}, function () {
jake.exec('./node_modules/uglify-js/bin/uglifyjs ejs.js > ejs.min.js',
buildOpts, function () {
console.log('Minification completed.');
setTimeout(complete, 0);
});
task('browserify', function () {
exec('./node_modules/browserify/bin/cmd.js --standalone ejs lib/ejs.js > ejs.js');
console.log('Browserification completed.');
});
task('minify', function () {
exec('./node_modules/uglify-js/bin/uglifyjs ejs.js > ejs.min.js');
console.log('Minification completed.');
});
task('doc', function (dev) {
jake.rmRf('out');
var p = dev ? '-p' : '';
exec('./node_modules/.bin/jsdoc ' + p + ' -c jsdoc.json lib/* docs/jsdoc/*');
console.log('Documentation generated.');
});
task('docPublish', ['doc'], function () {
console.log('Pushing docs to gh-pages...');
exec('./node_modules/.bin/git-directory-deploy --directory out/');
console.log('Docs published to gh-pages.');
});
task('test', ['lint'], function () {
exec('./node_modules/.bin/mocha');
});
publishTask('ejs', ['build'], function () {
this.packageFiles.include([
'Jakefile'
, 'README.md'
, 'LICENSE'
, 'package.json'
, 'ejs.js'
, 'ejs.min.js'
, 'lib/**'
, 'test/**'
'Jakefile',
'README.md',
'LICENSE',
'package.json',
'ejs.js',
'ejs.min.js',
'lib/**',
'test/**'
]);
});
jake.Task.publish.on('complete', function () {
console.log('Updating hosted docs...');
console.log('If this fails, run jake docPublish to re-try.');
jake.Task.docPublish.invoke();
});
+265 -121
View File
@@ -1,4 +1,4 @@
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.ejs=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ejs = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/*
* EJS Embedded JavaScript templates
* Copyright 2112 Matthew Eernisse (mde@fleegix.org)
@@ -53,11 +53,10 @@ var scopeOptionWarned = false;
var _VERSION_STRING = require('../package.json').version;
var _DEFAULT_DELIMITER = '%';
var _DEFAULT_LOCALS_NAME = 'locals';
var _NAME = 'ejs';
var _REGEX_STRING = '(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)';
var _OPTS = [ 'cache', 'filename', 'delimiter', 'scope', 'context',
'debug', 'compileDebug', 'client', '_with', 'root', 'rmWhitespace',
'strict', 'localsName'];
var _TRAILING_SEMCOL = /;\s*$/;
var _OPTS = ['delimiter', 'scope', 'context', 'debug', 'compileDebug',
'client', '_with', 'rmWhitespace', 'strict', 'filename'];
var _BOM = /^\uFEFF/;
/**
@@ -73,7 +72,7 @@ exports.cache = utils.cache;
/**
* Name of the object containing the locals.
*
* This variable is overriden by {@link Options}`.localsName` if it is not
* This variable is overridden by {@link Options}`.localsName` if it is not
* `undefined`.
*
* @type {String}
@@ -105,7 +104,7 @@ exports.resolveInclude = function(name, filename, isDir) {
/**
* Get the path to the included file by Options
*
*
* @param {String} path specified path
* @param {Options} options compilation options
* @return {String}
@@ -119,7 +118,7 @@ function getIncludePath(path, options){
if (!options.filename) {
throw new Error('`include` use relative path requires the \'filename\' option.');
}
includePath = exports.resolveInclude(path, options.filename);
includePath = exports.resolveInclude(path, options.filename);
}
return includePath;
}
@@ -232,10 +231,11 @@ function includeSource(path, options) {
* @static
*/
function rethrow(err, str, filename, lineno){
function rethrow(err, str, flnm, lineno){
var lines = str.split('\n');
var start = Math.max(lineno - 3, 0);
var end = Math.min(lines.length, lineno + 3);
var filename = utils.escapeXML(flnm);
// Error context
var context = lines.slice(start, end).map(function (line, i){
var curr = i + start + 1;
@@ -255,24 +255,8 @@ function rethrow(err, str, filename, lineno){
throw err;
}
/**
* Copy properties in data object that are recognized as options to an
* options object.
*
* This is used for compatibility with earlier versions of EJS and Express.js.
*
* @memberof module:ejs-internal
* @param {Object} data data object
* @param {Options} opts options object
* @static
*/
function cpOptsInData(data, opts) {
_OPTS.forEach(function (p) {
if (typeof data[p] != 'undefined') {
opts[p] = data[p];
}
});
function stripSemi(str) {
return str.replace(/;(\s*$)/, '$1');
}
/**
@@ -327,7 +311,7 @@ exports.render = function (template, d, o) {
// No options object -- if there are optiony names
// in the data, copy them to options
if (arguments.length == 2) {
cpOptsInData(data, opts);
utils.shallowCopyFromList(opts, data, _OPTS);
}
return handleCache(opts, template)(data);
@@ -352,21 +336,27 @@ exports.renderFile = function () {
var cb = args.pop();
var data = args.shift() || {};
var opts = args.pop() || {};
var optsKeys =_OPTS.slice();
var result;
// Don't pollute passed in opts obj with new vals
opts = utils.shallowCopy({}, opts);
// We don't allow 'cache' option to be passed in the data obj
// for the normal `render` call, but this is where Expres puts it
// so we make an exception for `renderFile`
optsKeys.push('cache');
// No options object -- if there are optiony names
// in the data, copy them to options
if (arguments.length == 3) {
// Express 4
if (data.settings && data.settings['view options']) {
cpOptsInData(data.settings['view options'], opts);
utils.shallowCopyFromList(opts, data.settings['view options'], optsKeys);
}
// Express 3 and lower
else {
cpOptsInData(data, opts);
utils.shallowCopyFromList(opts, data, optsKeys);
}
}
opts.filename = filename;
@@ -497,7 +487,9 @@ Template.prototype = {
if (opts.filename) {
e.message += ' in ' + opts.filename;
}
e.message += ' while compiling ejs';
e.message += ' while compiling ejs\n\n';
e.message += 'If the above error is not helpful, you may want to try EJS-Lint:\n';
e.message += 'https://github.com/RyanZim/EJS-Lint';
}
throw e;
}
@@ -639,9 +631,8 @@ Template.prototype = {
self.truncate = false;
}
else if (self.opts.rmWhitespace) {
// Gotta be more careful here.
// .replace(/^(\s*)\n/, '$1') might be more appropriate here but as
// rmWhitespace already removes trailing spaces anyway so meh.
// rmWhitespace has already removed trailing spaces, just need
// to remove linebreaks
line = line.replace(/^\n/, '');
}
if (!line) {
@@ -664,77 +655,75 @@ Template.prototype = {
newLineCount = (line.split('\n').length - 1);
switch (line) {
case '<' + d:
case '<' + d + '_':
this.mode = Template.modes.EVAL;
break;
case '<' + d + '=':
this.mode = Template.modes.ESCAPED;
break;
case '<' + d + '-':
this.mode = Template.modes.RAW;
break;
case '<' + d + '#':
this.mode = Template.modes.COMMENT;
break;
case '<' + d + d:
this.mode = Template.modes.LITERAL;
this.source += ' ; __append("' + line.replace('<' + d + d, '<' + d) + '")' + '\n';
break;
case d + d + '>':
this.mode = Template.modes.LITERAL;
this.source += ' ; __append("' + line.replace(d + d + '>', d + '>') + '")' + '\n';
break;
case d + '>':
case '-' + d + '>':
case '_' + d + '>':
if (this.mode == Template.modes.LITERAL) {
_addOutput();
}
case '<' + d:
case '<' + d + '_':
this.mode = Template.modes.EVAL;
break;
case '<' + d + '=':
this.mode = Template.modes.ESCAPED;
break;
case '<' + d + '-':
this.mode = Template.modes.RAW;
break;
case '<' + d + '#':
this.mode = Template.modes.COMMENT;
break;
case '<' + d + d:
this.mode = Template.modes.LITERAL;
this.source += ' ; __append("' + line.replace('<' + d + d, '<' + d) + '")' + '\n';
break;
case d + d + '>':
this.mode = Template.modes.LITERAL;
this.source += ' ; __append("' + line.replace(d + d + '>', d + '>') + '")' + '\n';
break;
case d + '>':
case '-' + d + '>':
case '_' + d + '>':
if (this.mode == Template.modes.LITERAL) {
_addOutput();
}
this.mode = null;
this.truncate = line.indexOf('-') === 0 || line.indexOf('_') === 0;
break;
default:
this.mode = null;
this.truncate = line.indexOf('-') === 0 || line.indexOf('_') === 0;
break;
default:
// In script mode, depends on type of tag
if (this.mode) {
if (this.mode) {
// If '//' is found without a line break, add a line break.
switch (this.mode) {
case Template.modes.EVAL:
case Template.modes.ESCAPED:
case Template.modes.RAW:
if (line.lastIndexOf('//') > line.lastIndexOf('\n')) {
line += '\n';
}
switch (this.mode) {
case Template.modes.EVAL:
case Template.modes.ESCAPED:
case Template.modes.RAW:
if (line.lastIndexOf('//') > line.lastIndexOf('\n')) {
line += '\n';
}
switch (this.mode) {
}
switch (this.mode) {
// Just executing code
case Template.modes.EVAL:
this.source += ' ; ' + line + '\n';
break;
case Template.modes.EVAL:
this.source += ' ; ' + line + '\n';
break;
// Exec, esc, and output
case Template.modes.ESCAPED:
this.source += ' ; __append(escape(' +
line.replace(_TRAILING_SEMCOL, '').trim() + '))' + '\n';
break;
case Template.modes.ESCAPED:
this.source += ' ; __append(escape(' + stripSemi(line) + '))' + '\n';
break;
// Exec and output
case Template.modes.RAW:
this.source += ' ; __append(' +
line.replace(_TRAILING_SEMCOL, '').trim() + ')' + '\n';
break;
case Template.modes.COMMENT:
case Template.modes.RAW:
this.source += ' ; __append(' + stripSemi(line) + ')' + '\n';
break;
case Template.modes.COMMENT:
// Do nothing
break;
break;
// Literal <%% mode, append as raw output
case Template.modes.LITERAL:
_addOutput();
break;
}
}
// In string mode, just add the output
else {
case Template.modes.LITERAL:
_addOutput();
break;
}
}
// In string mode, just add the output
else {
_addOutput();
}
}
if (self.opts.compileDebug && newLineCount) {
@@ -775,9 +764,9 @@ if (require.extensions) {
require.extensions['.ejs'] = function (module, flnm) {
var filename = flnm || /* istanbul ignore next */ module.filename;
var options = {
filename: filename,
client: true
};
filename: filename,
client: true
};
var template = fs.readFileSync(filename).toString();
var fn = exports.compile(template, options);
module._compile('module.exports = ' + fn.toString() + ';', filename);
@@ -794,6 +783,16 @@ if (require.extensions) {
exports.VERSION = _VERSION_STRING;
/**
* Name for detection of EJS.
*
* @readonly
* @type {String}
* @public
*/
exports.name = _NAME;
/* istanbul ignore if */
if (typeof window != 'undefined') {
window.ejs = exports;
@@ -847,17 +846,17 @@ exports.escapeRegExpChars = function (string) {
};
var _ENCODE_HTML_RULES = {
'&': '&amp;'
, '<': '&lt;'
, '>': '&gt;'
, '"': '&#34;'
, "'": '&#39;'
}
, _MATCH_HTML = /[&<>\'"]/g;
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&#34;',
"'": '&#39;'
};
var _MATCH_HTML = /[&<>\'"]/g;
function encode_char(c) {
return _ENCODE_HTML_RULES[c] || c;
};
}
/**
* Stringified version of constants used by {@link module:utils.escapeXML}.
@@ -900,11 +899,13 @@ exports.escapeXML = function (markup) {
.replace(_MATCH_HTML, encode_char);
};
exports.escapeXML.toString = function () {
return Function.prototype.toString.call(this) + ';\n' + escapeFuncStr
return Function.prototype.toString.call(this) + ';\n' + escapeFuncStr;
};
/**
* Copy all properties from one object to another, in a shallow fashion.
* Naive copy of properties from one object to another.
* Does not recurse into non-scalar properties
* Does not check to see if the property has a value before copying
*
* @param {Object} to Destination object
* @param {Object} from Source object
@@ -920,6 +921,27 @@ exports.shallowCopy = function (to, from) {
return to;
};
/**
* Naive copy of a list of key names, from one object to another.
* Only copies property if it is actually defined
* Does not recurse into non-scalar properties
*
* @param {Object} to Destination object
* @param {Object} from Source object
* @param {Array} list List of properties to copy
* @return {Object} Destination object
* @static
* @private
*/
exports.shallowCopyFromList = function (to, from, list) {
list.forEach(function (p) {
if (typeof from[p] != 'undefined') {
to[p] = from[p];
}
});
return to;
};
/**
* Simple in-process cache implementation. Does not implement limits of any
* sort.
@@ -941,7 +963,6 @@ exports.cache = {
}
};
},{}],3:[function(require,module,exports){
},{}],4:[function(require,module,exports){
@@ -1174,36 +1195,159 @@ var substr = 'ab'.substr(-1) === 'b'
}).call(this,require('_process'))
},{"_process":5}],5:[function(require,module,exports){
// shim for using process in browser
var process = module.exports = {};
// cached from whatever global is present so that test runners that stub it
// don't break things. But we need to wrap it in a try catch in case it is
// wrapped in strict mode code which doesn't define any globals. It's inside a
// function because try/catches deoptimize in certain engines.
var cachedSetTimeout;
var cachedClearTimeout;
function defaultSetTimout() {
throw new Error('setTimeout has not been defined');
}
function defaultClearTimeout () {
throw new Error('clearTimeout has not been defined');
}
(function () {
try {
if (typeof setTimeout === 'function') {
cachedSetTimeout = setTimeout;
} else {
cachedSetTimeout = defaultSetTimout;
}
} catch (e) {
cachedSetTimeout = defaultSetTimout;
}
try {
if (typeof clearTimeout === 'function') {
cachedClearTimeout = clearTimeout;
} else {
cachedClearTimeout = defaultClearTimeout;
}
} catch (e) {
cachedClearTimeout = defaultClearTimeout;
}
} ())
function runTimeout(fun) {
if (cachedSetTimeout === setTimeout) {
//normal enviroments in sane situations
return setTimeout(fun, 0);
}
// if setTimeout wasn't available but was latter defined
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
cachedSetTimeout = setTimeout;
return setTimeout(fun, 0);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedSetTimeout(fun, 0);
} catch(e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedSetTimeout.call(null, fun, 0);
} catch(e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
return cachedSetTimeout.call(this, fun, 0);
}
}
}
function runClearTimeout(marker) {
if (cachedClearTimeout === clearTimeout) {
//normal enviroments in sane situations
return clearTimeout(marker);
}
// if clearTimeout wasn't available but was latter defined
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
cachedClearTimeout = clearTimeout;
return clearTimeout(marker);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedClearTimeout(marker);
} catch (e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedClearTimeout.call(null, marker);
} catch (e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
return cachedClearTimeout.call(this, marker);
}
}
}
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
if (!draining || !currentQueue) {
return;
}
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = runTimeout(cleanUpNextTick);
draining = true;
var currentQueue;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
var i = -1;
while (++i < len) {
currentQueue[i]();
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
runClearTimeout(timeout);
}
process.nextTick = function (fun) {
queue.push(fun);
if (!draining) {
setTimeout(drainQueue, 0);
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
runTimeout(drainQueue);
}
};
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
process.title = 'browser';
process.browser = true;
process.env = {};
@@ -1225,7 +1369,6 @@ process.binding = function (name) {
throw new Error('process.binding is not supported');
};
// TODO(shtylman)
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
@@ -1241,7 +1384,7 @@ module.exports={
"engine",
"ejs"
],
"version": "2.5.1",
"version": "2.5.4",
"author": "Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)",
"contributors": [
"Timothy Gu <timothygu99@gmail.com> (https://timothygu.github.io)"
@@ -1258,12 +1401,12 @@ module.exports={
"devDependencies": {
"browserify": "^13.0.1",
"eslint": "^3.0.0",
"git-directory-deploy": "^1.5.1",
"istanbul": "~0.4.3",
"jake": "^8.0.0",
"jsdoc": "^3.4.0",
"lru-cache": "^4.0.1",
"mocha": "^3.0.2",
"rimraf": "^2.2.8",
"uglify-js": "^2.6.2"
},
"engines": {
@@ -1271,9 +1414,10 @@ module.exports={
},
"scripts": {
"test": "mocha",
"lint": "eslint \"**/*.js\" Jakefile",
"coverage": "istanbul cover node_modules/mocha/bin/_mocha",
"doc": "rimraf out && jsdoc -c jsdoc.json lib/* docs/jsdoc/*",
"devdoc": "rimraf out && jsdoc -p -c jsdoc.json lib/* docs/jsdoc/*"
"doc": "jake doc",
"devdoc": "jake doc[dev]"
}
}
File diff suppressed because one or more lines are too long
+95 -96
View File
@@ -52,11 +52,10 @@ var scopeOptionWarned = false;
var _VERSION_STRING = require('../package.json').version;
var _DEFAULT_DELIMITER = '%';
var _DEFAULT_LOCALS_NAME = 'locals';
var _NAME = 'ejs';
var _REGEX_STRING = '(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)';
var _OPTS = [ 'cache', 'filename', 'delimiter', 'scope', 'context',
'debug', 'compileDebug', 'client', '_with', 'root', 'rmWhitespace',
'strict', 'localsName'];
var _TRAILING_SEMCOL = /;\s*$/;
var _OPTS = ['delimiter', 'scope', 'context', 'debug', 'compileDebug',
'client', '_with', 'rmWhitespace', 'strict', 'filename'];
var _BOM = /^\uFEFF/;
/**
@@ -72,7 +71,7 @@ exports.cache = utils.cache;
/**
* Name of the object containing the locals.
*
* This variable is overriden by {@link Options}`.localsName` if it is not
* This variable is overridden by {@link Options}`.localsName` if it is not
* `undefined`.
*
* @type {String}
@@ -104,7 +103,7 @@ exports.resolveInclude = function(name, filename, isDir) {
/**
* Get the path to the included file by Options
*
*
* @param {String} path specified path
* @param {Options} options compilation options
* @return {String}
@@ -118,7 +117,7 @@ function getIncludePath(path, options){
if (!options.filename) {
throw new Error('`include` use relative path requires the \'filename\' option.');
}
includePath = exports.resolveInclude(path, options.filename);
includePath = exports.resolveInclude(path, options.filename);
}
return includePath;
}
@@ -231,10 +230,11 @@ function includeSource(path, options) {
* @static
*/
function rethrow(err, str, filename, lineno){
function rethrow(err, str, flnm, lineno){
var lines = str.split('\n');
var start = Math.max(lineno - 3, 0);
var end = Math.min(lines.length, lineno + 3);
var filename = utils.escapeXML(flnm);
// Error context
var context = lines.slice(start, end).map(function (line, i){
var curr = i + start + 1;
@@ -254,24 +254,8 @@ function rethrow(err, str, filename, lineno){
throw err;
}
/**
* Copy properties in data object that are recognized as options to an
* options object.
*
* This is used for compatibility with earlier versions of EJS and Express.js.
*
* @memberof module:ejs-internal
* @param {Object} data data object
* @param {Options} opts options object
* @static
*/
function cpOptsInData(data, opts) {
_OPTS.forEach(function (p) {
if (typeof data[p] != 'undefined') {
opts[p] = data[p];
}
});
function stripSemi(str) {
return str.replace(/;(\s*$)/, '$1');
}
/**
@@ -326,7 +310,7 @@ exports.render = function (template, d, o) {
// No options object -- if there are optiony names
// in the data, copy them to options
if (arguments.length == 2) {
cpOptsInData(data, opts);
utils.shallowCopyFromList(opts, data, _OPTS);
}
return handleCache(opts, template)(data);
@@ -351,21 +335,27 @@ exports.renderFile = function () {
var cb = args.pop();
var data = args.shift() || {};
var opts = args.pop() || {};
var optsKeys =_OPTS.slice();
var result;
// Don't pollute passed in opts obj with new vals
opts = utils.shallowCopy({}, opts);
// We don't allow 'cache' option to be passed in the data obj
// for the normal `render` call, but this is where Expres puts it
// so we make an exception for `renderFile`
optsKeys.push('cache');
// No options object -- if there are optiony names
// in the data, copy them to options
if (arguments.length == 3) {
// Express 4
if (data.settings && data.settings['view options']) {
cpOptsInData(data.settings['view options'], opts);
utils.shallowCopyFromList(opts, data.settings['view options'], optsKeys);
}
// Express 3 and lower
else {
cpOptsInData(data, opts);
utils.shallowCopyFromList(opts, data, optsKeys);
}
}
opts.filename = filename;
@@ -496,7 +486,9 @@ Template.prototype = {
if (opts.filename) {
e.message += ' in ' + opts.filename;
}
e.message += ' while compiling ejs';
e.message += ' while compiling ejs\n\n';
e.message += 'If the above error is not helpful, you may want to try EJS-Lint:\n';
e.message += 'https://github.com/RyanZim/EJS-Lint';
}
throw e;
}
@@ -638,9 +630,8 @@ Template.prototype = {
self.truncate = false;
}
else if (self.opts.rmWhitespace) {
// Gotta be more careful here.
// .replace(/^(\s*)\n/, '$1') might be more appropriate here but as
// rmWhitespace already removes trailing spaces anyway so meh.
// rmWhitespace has already removed trailing spaces, just need
// to remove linebreaks
line = line.replace(/^\n/, '');
}
if (!line) {
@@ -663,77 +654,75 @@ Template.prototype = {
newLineCount = (line.split('\n').length - 1);
switch (line) {
case '<' + d:
case '<' + d + '_':
this.mode = Template.modes.EVAL;
break;
case '<' + d + '=':
this.mode = Template.modes.ESCAPED;
break;
case '<' + d + '-':
this.mode = Template.modes.RAW;
break;
case '<' + d + '#':
this.mode = Template.modes.COMMENT;
break;
case '<' + d + d:
this.mode = Template.modes.LITERAL;
this.source += ' ; __append("' + line.replace('<' + d + d, '<' + d) + '")' + '\n';
break;
case d + d + '>':
this.mode = Template.modes.LITERAL;
this.source += ' ; __append("' + line.replace(d + d + '>', d + '>') + '")' + '\n';
break;
case d + '>':
case '-' + d + '>':
case '_' + d + '>':
if (this.mode == Template.modes.LITERAL) {
_addOutput();
}
case '<' + d:
case '<' + d + '_':
this.mode = Template.modes.EVAL;
break;
case '<' + d + '=':
this.mode = Template.modes.ESCAPED;
break;
case '<' + d + '-':
this.mode = Template.modes.RAW;
break;
case '<' + d + '#':
this.mode = Template.modes.COMMENT;
break;
case '<' + d + d:
this.mode = Template.modes.LITERAL;
this.source += ' ; __append("' + line.replace('<' + d + d, '<' + d) + '")' + '\n';
break;
case d + d + '>':
this.mode = Template.modes.LITERAL;
this.source += ' ; __append("' + line.replace(d + d + '>', d + '>') + '")' + '\n';
break;
case d + '>':
case '-' + d + '>':
case '_' + d + '>':
if (this.mode == Template.modes.LITERAL) {
_addOutput();
}
this.mode = null;
this.truncate = line.indexOf('-') === 0 || line.indexOf('_') === 0;
break;
default:
this.mode = null;
this.truncate = line.indexOf('-') === 0 || line.indexOf('_') === 0;
break;
default:
// In script mode, depends on type of tag
if (this.mode) {
if (this.mode) {
// If '//' is found without a line break, add a line break.
switch (this.mode) {
case Template.modes.EVAL:
case Template.modes.ESCAPED:
case Template.modes.RAW:
if (line.lastIndexOf('//') > line.lastIndexOf('\n')) {
line += '\n';
}
switch (this.mode) {
case Template.modes.EVAL:
case Template.modes.ESCAPED:
case Template.modes.RAW:
if (line.lastIndexOf('//') > line.lastIndexOf('\n')) {
line += '\n';
}
switch (this.mode) {
}
switch (this.mode) {
// Just executing code
case Template.modes.EVAL:
this.source += ' ; ' + line + '\n';
break;
case Template.modes.EVAL:
this.source += ' ; ' + line + '\n';
break;
// Exec, esc, and output
case Template.modes.ESCAPED:
this.source += ' ; __append(escape(' +
line.replace(_TRAILING_SEMCOL, '').trim() + '))' + '\n';
break;
case Template.modes.ESCAPED:
this.source += ' ; __append(escape(' + stripSemi(line) + '))' + '\n';
break;
// Exec and output
case Template.modes.RAW:
this.source += ' ; __append(' +
line.replace(_TRAILING_SEMCOL, '').trim() + ')' + '\n';
break;
case Template.modes.COMMENT:
case Template.modes.RAW:
this.source += ' ; __append(' + stripSemi(line) + ')' + '\n';
break;
case Template.modes.COMMENT:
// Do nothing
break;
break;
// Literal <%% mode, append as raw output
case Template.modes.LITERAL:
_addOutput();
break;
}
}
// In string mode, just add the output
else {
case Template.modes.LITERAL:
_addOutput();
break;
}
}
// In string mode, just add the output
else {
_addOutput();
}
}
if (self.opts.compileDebug && newLineCount) {
@@ -774,9 +763,9 @@ if (require.extensions) {
require.extensions['.ejs'] = function (module, flnm) {
var filename = flnm || /* istanbul ignore next */ module.filename;
var options = {
filename: filename,
client: true
};
filename: filename,
client: true
};
var template = fs.readFileSync(filename).toString();
var fn = exports.compile(template, options);
module._compile('module.exports = ' + fn.toString() + ';', filename);
@@ -793,6 +782,16 @@ if (require.extensions) {
exports.VERSION = _VERSION_STRING;
/**
* Name for detection of EJS.
*
* @readonly
* @type {String}
* @public
*/
exports.name = _NAME;
/* istanbul ignore if */
if (typeof window != 'undefined') {
window.ejs = exports;
+33 -11
View File
@@ -45,17 +45,17 @@ exports.escapeRegExpChars = function (string) {
};
var _ENCODE_HTML_RULES = {
'&': '&amp;'
, '<': '&lt;'
, '>': '&gt;'
, '"': '&#34;'
, "'": '&#39;'
}
, _MATCH_HTML = /[&<>\'"]/g;
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&#34;',
"'": '&#39;'
};
var _MATCH_HTML = /[&<>\'"]/g;
function encode_char(c) {
return _ENCODE_HTML_RULES[c] || c;
};
}
/**
* Stringified version of constants used by {@link module:utils.escapeXML}.
@@ -98,11 +98,13 @@ exports.escapeXML = function (markup) {
.replace(_MATCH_HTML, encode_char);
};
exports.escapeXML.toString = function () {
return Function.prototype.toString.call(this) + ';\n' + escapeFuncStr
return Function.prototype.toString.call(this) + ';\n' + escapeFuncStr;
};
/**
* Copy all properties from one object to another, in a shallow fashion.
* Naive copy of properties from one object to another.
* Does not recurse into non-scalar properties
* Does not check to see if the property has a value before copying
*
* @param {Object} to Destination object
* @param {Object} from Source object
@@ -118,6 +120,27 @@ exports.shallowCopy = function (to, from) {
return to;
};
/**
* Naive copy of a list of key names, from one object to another.
* Only copies property if it is actually defined
* Does not recurse into non-scalar properties
*
* @param {Object} to Destination object
* @param {Object} from Source object
* @param {Array} list List of properties to copy
* @return {Object} Destination object
* @static
* @private
*/
exports.shallowCopyFromList = function (to, from, list) {
list.forEach(function (p) {
if (typeof from[p] != 'undefined') {
to[p] = from[p];
}
});
return to;
};
/**
* Simple in-process cache implementation. Does not implement limits of any
* sort.
@@ -138,4 +161,3 @@ exports.cache = {
this._data = {};
}
};
+14 -17
View File
@@ -14,19 +14,19 @@
]
],
"_from": "ejs@>=2.5.2 <3.0.0",
"_id": "ejs@2.5.2",
"_id": "ejs@2.5.5",
"_inCache": true,
"_location": "/ejs",
"_nodeVersion": "4.2.2",
"_nodeVersion": "6.9.1",
"_npmOperationalInternal": {
"host": "packages-12-west.internal.npmjs.com",
"tmp": "tmp/ejs-2.5.2.tgz_1473259584869_0.9678213631268591"
"host": "packages-18-east.internal.npmjs.com",
"tmp": "tmp/ejs-2.5.5.tgz_1481011535826_0.4493071837350726"
},
"_npmUser": {
"name": "mde",
"email": "mde@fleegix.org"
},
"_npmVersion": "2.14.7",
"_npmVersion": "3.10.8",
"_phantomChildren": {},
"_requested": {
"raw": "ejs@^2.5.2",
@@ -40,8 +40,8 @@
"_requiredBy": [
"#DEV:/"
],
"_resolved": "https://registry.npmjs.org/ejs/-/ejs-2.5.2.tgz",
"_shasum": "21444ba09386f0c65b6eafb96a3d51bcb3be80d1",
"_resolved": "https://registry.npmjs.org/ejs/-/ejs-2.5.5.tgz",
"_shasum": "6ef4e954ea7dcf54f66aad2fe7aa421932d9ed77",
"_shrinkwrap": null,
"_spec": "ejs@^2.5.2",
"_where": "/brodocs",
@@ -65,18 +65,18 @@
"devDependencies": {
"browserify": "^13.0.1",
"eslint": "^3.0.0",
"git-directory-deploy": "^1.5.1",
"istanbul": "~0.4.3",
"jake": "^8.0.0",
"jsdoc": "^3.4.0",
"lru-cache": "^4.0.1",
"mocha": "^3.0.2",
"rimraf": "^2.2.8",
"uglify-js": "^2.6.2"
},
"directories": {},
"dist": {
"shasum": "21444ba09386f0c65b6eafb96a3d51bcb3be80d1",
"tarball": "https://registry.npmjs.org/ejs/-/ejs-2.5.2.tgz"
"shasum": "6ef4e954ea7dcf54f66aad2fe7aa421932d9ed77",
"tarball": "https://registry.npmjs.org/ejs/-/ejs-2.5.5.tgz"
},
"engines": {
"node": ">=0.10.0"
@@ -90,10 +90,6 @@
"license": "Apache-2.0",
"main": "./lib/ejs.js",
"maintainers": [
{
"name": "tjholowaychuk",
"email": "tj@vision-media.ca"
},
{
"name": "mde",
"email": "mde@fleegix.org"
@@ -108,9 +104,10 @@
},
"scripts": {
"coverage": "istanbul cover node_modules/mocha/bin/_mocha",
"devdoc": "rimraf out && jsdoc -p -c jsdoc.json lib/* docs/jsdoc/*",
"doc": "rimraf out && jsdoc -c jsdoc.json lib/* docs/jsdoc/*",
"devdoc": "jake doc[dev]",
"doc": "jake doc",
"lint": "eslint \"**/*.js\" Jakefile",
"test": "mocha"
},
"version": "2.5.2"
"version": "2.5.5"
}
+153 -121
View File
@@ -1,15 +1,16 @@
/* jshint mocha: true */
/* eslint-env node, mocha */
/**
* Module dependencies.
*/
var ejs = require('..')
, fs = require('fs')
, read = fs.readFileSync
, assert = require('assert')
, path = require('path')
, LRU = require('lru-cache');
var ejs = require('..');
var fs = require('fs');
var read = fs.readFileSync;
var assert = require('assert');
var path = require('path');
var LRU = require('lru-cache');
try {
fs.mkdirSync(__dirname + '/tmp');
@@ -104,9 +105,9 @@ suite('ejs.compile(str, options)', function () {
});
test('have a working client option', function () {
var fn
, str
, preFn;
var fn;
var str;
var preFn;
fn = ejs.compile('<p><%= foo %></p>', {client: true});
str = fn.toString();
if (!process.env.running_under_istanbul) {
@@ -116,9 +117,9 @@ suite('ejs.compile(str, options)', function () {
});
test('support client mode without locals', function () {
var fn
, str
, preFn;
var fn;
var str;
var preFn;
fn = ejs.compile('<p><%= "foo" %></p>', {client: true});
str = fn.toString();
if (!process.env.running_under_istanbul) {
@@ -129,16 +130,16 @@ suite('ejs.compile(str, options)', function () {
test('not include rethrow() in client mode if compileDebug is false', function () {
var fn = ejs.compile('<p><%= "foo" %></p>', {
client: true
, compileDebug: false
});
client: true,
compileDebug: false
});
// There could be a `rethrow` in the function declaration
assert((fn.toString().match(/rethrow/g) || []).length <= 1);
});
test('support custom escape function', function () {
var customEscape
, fn;
var customEscape;
var fn;
customEscape = function customEscape(str) {
return !str ? '' : str.toUpperCase();
};
@@ -147,9 +148,9 @@ suite('ejs.compile(str, options)', function () {
});
test('support custom escape function in client mode', function () {
var customEscape
, fn
, str;
var customEscape;
var fn;
var str;
customEscape = function customEscape(str) {
return !str ? '' : str.toUpperCase();
};
@@ -157,7 +158,7 @@ suite('ejs.compile(str, options)', function () {
str = fn.toString();
if (!process.env.running_under_istanbul) {
eval('var preFn = ' + str);
assert.equal(preFn({name: 'world'}), 'HELLO WORLD');
assert.equal(preFn({name: 'world'}), 'HELLO WORLD'); // eslint-disable-line no-undef
}
});
@@ -167,6 +168,21 @@ suite('ejs.compile(str, options)', function () {
});
/* Old API -- remove when this shim goes away */
suite('ejs.render(str, dataAndOpts)', function () {
test('render the template with data/opts passed together', function () {
assert.equal(ejs.render('<p><?= foo ?></p>', {foo: 'yay', delimiter: '?'}),
'<p>yay</p>');
});
test('disallow unsafe opts passed along in data', function () {
assert.equal(ejs.render('<p><?= locals.foo ?></p>',
// localsName should not get reset because it's blacklisted
{_with: false, foo: 'yay', delimiter: '?', localsName: '_'}),
'<p>yay</p>');
});
});
suite('ejs.render(str, data, opts)', function () {
test('render the template', function () {
assert.equal(ejs.render('<p>yay</p>'), '<p>yay</p>');
@@ -228,10 +244,10 @@ suite('ejs.render(str, data, opts)', function () {
});
test('support caching', function () {
var file = __dirname + '/tmp/render.ejs'
, options = {cache: true, filename: file}
, out = ejs.render('<p>Old</p>', {}, options)
, expected = '<p>Old</p>';
var file = __dirname + '/tmp/render.ejs';
var options = {cache: true, filename: file};
var out = ejs.render('<p>Old</p>', {}, options);
var expected = '<p>Old</p>';
assert.equal(out, expected);
// Assert no change, still in cache
out = ejs.render('<p>New</p>', {}, options);
@@ -239,11 +255,11 @@ suite('ejs.render(str, data, opts)', function () {
});
test('support LRU caching', function () {
var oldCache = ejs.cache
, file = __dirname + '/tmp/render.ejs'
, options = {cache: true, filename: file}
, out
, expected = '<p>Old</p>';
var oldCache = ejs.cache;
var file = __dirname + '/tmp/render.ejs';
var options = {cache: true, filename: file};
var out;
var expected = '<p>Old</p>';
// Switch to LRU
ejs.cache = LRU();
@@ -259,8 +275,8 @@ suite('ejs.render(str, data, opts)', function () {
});
test('opts.context', function () {
var ctxt = {foo: 'FOO'}
, out = ejs.render('<%= this.foo %>', {}, {context: ctxt});
var ctxt = {foo: 'FOO'};
var out = ejs.render('<%= this.foo %>', {}, {context: ctxt});
assert.equal(out, ctxt.foo);
});
});
@@ -277,8 +293,8 @@ suite('ejs.renderFile(path, [data], [options], fn)', function () {
});
test('accept locals', function(done) {
var data = {name: 'fonebone'}
, options = {delimiter: '$'};
var data = {name: 'fonebone'};
var options = {delimiter: '$'};
ejs.renderFile('test/fixtures/user.ejs', data, options, function(err, html) {
if (err) {
return done(err);
@@ -289,11 +305,10 @@ suite('ejs.renderFile(path, [data], [options], fn)', function () {
});
test('accept locals without using with() {}', function(done) {
var data = {name: 'fonebone'}
, options = {delimiter: '$', _with: false}
, doneCount = 0;
ejs.renderFile('test/fixtures/user-no-with.ejs', data, options,
function(err, html) {
var data = {name: 'fonebone'};
var options = {delimiter: '$', _with: false};
var doneCount = 0;
ejs.renderFile('test/fixtures/user-no-with.ejs', data, options, function(err, html) {
if (err) {
if (doneCount === 2) {
return;
@@ -323,9 +338,9 @@ suite('ejs.renderFile(path, [data], [options], fn)', function () {
});
test('not catch err thrown by callback', function(done) {
var data = {name: 'fonebone'}
, options = {delimiter: '$'}
, counter = 0;
var data = {name: 'fonebone'};
var options = {delimiter: '$'};
var counter = 0;
var d = require('domain').create();
d.on('error', function (err) {
@@ -340,8 +355,7 @@ suite('ejs.renderFile(path, [data], [options], fn)', function () {
// domains. Have to make it async. Ticket closed because: "domains are
// deprecated :D"
process.nextTick(function () {
ejs.renderFile('test/fixtures/user.ejs', data, options,
function(err) {
ejs.renderFile('test/fixtures/user.ejs', data, options, function(err) {
counter++;
if (err) {
assert.notEqual(err.message, 'Exception in callback');
@@ -354,9 +368,9 @@ suite('ejs.renderFile(path, [data], [options], fn)', function () {
});
test('support caching', function (done) {
var expected = '<p>Old</p>'
, file = __dirname + '/tmp/renderFile.ejs'
, options = {cache: true};
var expected = '<p>Old</p>';
var file = __dirname + '/tmp/renderFile.ejs';
var options = {cache: true};
fs.writeFileSync(file, '<p>Old</p>');
ejs.renderFile(file, {}, options, function (err, out) {
@@ -379,8 +393,7 @@ suite('ejs.renderFile(path, [data], [options], fn)', function () {
test('opts.context', function (done) {
var ctxt = {foo: 'FOO'};
ejs.renderFile('test/fixtures/with-context.ejs', {},
{context: ctxt}, function(err, html) {
ejs.renderFile('test/fixtures/with-context.ejs', {}, {context: ctxt}, function(err, html) {
if (err) {
return done(err);
}
@@ -393,10 +406,10 @@ suite('ejs.renderFile(path, [data], [options], fn)', function () {
suite('cache specific', function () {
test('`clearCache` work properly', function () {
var expected = '<p>Old</p>'
, file = __dirname + '/tmp/clearCache.ejs'
, options = {cache: true, filename: file}
, out = ejs.render('<p>Old</p>', {}, options);
var expected = '<p>Old</p>';
var file = __dirname + '/tmp/clearCache.ejs';
var options = {cache: true, filename: file};
var out = ejs.render('<p>Old</p>', {}, options);
assert.equal(out, expected);
ejs.clearCache();
@@ -407,11 +420,11 @@ suite('cache specific', function () {
});
test('`clearCache` work properly, LRU', function () {
var expected = '<p>Old</p>'
, oldCache = ejs.cache
, file = __dirname + '/tmp/clearCache.ejs'
, options = {cache: true, filename: file}
, out;
var expected = '<p>Old</p>';
var oldCache = ejs.cache;
var file = __dirname + '/tmp/clearCache.ejs';
var options = {cache: true, filename: file};
var out;
ejs.cache = LRU();
@@ -426,11 +439,11 @@ suite('cache specific', function () {
});
test('LRU with cache-size 1', function () {
var oldCache = ejs.cache
, options
, out
, expected
, file;
var oldCache = ejs.cache;
var options;
var out;
var expected;
var file;
ejs.cache = LRU(1);
@@ -476,6 +489,11 @@ suite('<%', function () {
});
suite('<%=', function () {
test('should not throw an error with a // comment on the final line', function () {
assert.equal(ejs.render('<%=\n// a comment\nname\n// another comment %>', {name: '&nbsp;<script>'}),
'&amp;nbsp;&lt;script&gt;');
});
test('escape &amp;<script>', function () {
assert.equal(ejs.render('<%= name %>', {name: '&nbsp;<script>'}),
'&amp;nbsp;&lt;script&gt;');
@@ -505,6 +523,11 @@ suite('<%=', function () {
});
suite('<%-', function () {
test('should not throw an error with a // comment on the final line', function () {
assert.equal(ejs.render('<%-\n// a comment\nname\n// another comment %>', {name: '&nbsp;<script>'}),
'&nbsp;<script>');
});
test('not escape', function () {
assert.equal(ejs.render('<%- name %>', {name: '<script>'}),
'<script>');
@@ -555,13 +578,13 @@ suite('-%>', function () {
});
test('works with unix style', function () {
var content = "<ul><% -%>\n"
+ "<% users.forEach(function(user){ -%>\n"
+ "<li><%= user.name -%></li>\n"
+ "<% }) -%>\n"
+ "</ul><% -%>\n";
var content = '<ul><% -%>\n'
+ '<% users.forEach(function(user){ -%>\n'
+ '<li><%= user.name -%></li>\n'
+ '<% }) -%>\n'
+ '</ul><% -%>\n';
var expectedResult = "<ul><li>geddy</li>\n<li>neil</li>\n<li>alex</li>\n</ul>";
var expectedResult = '<ul><li>geddy</li>\n<li>neil</li>\n<li>alex</li>\n</ul>';
var fn;
fn = ejs.compile(content);
assert.equal(fn({users: users}),
@@ -569,13 +592,13 @@ suite('-%>', function () {
});
test('works with windows style', function () {
var content = "<ul><% -%>\r\n"
+ "<% users.forEach(function(user){ -%>\r\n"
+ "<li><%= user.name -%></li>\r\n"
+ "<% }) -%>\r\n"
+ "</ul><% -%>\r\n";
var content = '<ul><% -%>\r\n'
+ '<% users.forEach(function(user){ -%>\r\n'
+ '<li><%= user.name -%></li>\r\n'
+ '<% }) -%>\r\n'
+ '</ul><% -%>\r\n';
var expectedResult = "<ul><li>geddy</li>\r\n<li>neil</li>\r\n<li>alex</li>\r\n</ul>";
var expectedResult = '<ul><li>geddy</li>\r\n<li>neil</li>\r\n<li>alex</li>\r\n</ul>';
var fn;
fn = ejs.compile(content);
assert.equal(fn({users: users}),
@@ -669,8 +692,8 @@ suite('exceptions', function () {
var unhook = null;
test('log JS source when debug is set', function (done) {
var out = ''
, needToExit = false;
var out = '';
var needToExit = false;
unhook = hook_stdio(process.stdout, function (str) {
out += str;
if (needToExit) {
@@ -741,11 +764,10 @@ suite('include()', function () {
});
test('include ejs with set root path', function () {
var file = 'test/fixtures/include-root.ejs',
viewsPath = path.join(__dirname, 'fixtures');
var file = 'test/fixtures/include-root.ejs';
var viewsPath = path.join(__dirname, 'fixtures');
assert.equal(ejs.render(fixture('include-root.ejs'), {pets: users}, {filename: file, delimiter: '@',root:viewsPath}),
fixture('include.html'));
});
test('work when nested', function () {
@@ -755,8 +777,8 @@ suite('include()', function () {
});
test('work with a variable path', function () {
var file = 'test/fixtures/menu_var.ejs',
includePath = 'includes/menu-item';
var file = 'test/fixtures/menu_var.ejs';
var includePath = 'includes/menu-item';
assert.equal(ejs.render(fixture('menu.ejs'), {pets: users, varPath: includePath}, {filename: file}),
fixture('menu.html'));
});
@@ -768,12 +790,12 @@ suite('include()', function () {
});
test('pass compileDebug to include', function () {
var file = 'test/fixtures/include.ejs'
, fn;
var file = 'test/fixtures/include.ejs';
var fn;
fn = ejs.compile(fixture('include.ejs'), {
filename: file
, delimiter: '@'
, compileDebug: false
filename: file,
delimiter: '@',
compileDebug: false
});
try {
// Render without a required variable reference
@@ -789,9 +811,9 @@ suite('include()', function () {
test('is dynamic', function () {
fs.writeFileSync(__dirname + '/tmp/include.ejs', '<p>Old</p>');
var file = 'test/fixtures/include_cache.ejs'
, options = {filename: file}
, out = ejs.compile(fixture('include_cache.ejs'), options);
var file = 'test/fixtures/include_cache.ejs';
var options = {filename: file};
var out = ejs.compile(fixture('include_cache.ejs'), options);
assert.equal(out(), '<p>Old</p>\n');
fs.writeFileSync(__dirname + '/tmp/include.ejs', '<p>New</p>');
@@ -800,10 +822,10 @@ suite('include()', function () {
test('support caching', function () {
fs.writeFileSync(__dirname + '/tmp/include.ejs', '<p>Old</p>');
var file = 'test/fixtures/include_cache.ejs'
, options = {cache: true, filename: file}
, out = ejs.render(fixture('include_cache.ejs'), {}, options)
, expected = fixture('include_cache.html');
var file = 'test/fixtures/include_cache.ejs';
var options = {cache: true, filename: file};
var out = ejs.render(fixture('include_cache.ejs'), {}, options);
var expected = fixture('include_cache.html');
assert.equal(out, expected);
out = ejs.render(fixture('include_cache.ejs'), {}, options);
// No change, still in cache
@@ -851,8 +873,8 @@ suite('preprocessor include', function () {
});
test('tracks dependency correctly', function () {
var file = 'test/fixtures/menu_preprocessor.ejs'
, fn = ejs.compile(fixture('menu_preprocessor.ejs'), {filename: file});
var file = 'test/fixtures/menu_preprocessor.ejs';
var fn = ejs.compile(fixture('menu_preprocessor.ejs'), {filename: file});
assert(fn.dependencies.length);
});
@@ -863,12 +885,12 @@ suite('preprocessor include', function () {
});
test('pass compileDebug to include', function () {
var file = 'test/fixtures/include_preprocessor.ejs'
, fn;
var file = 'test/fixtures/include_preprocessor.ejs';
var fn;
fn = ejs.compile(fixture('include_preprocessor.ejs'), {
filename: file
, delimiter: '@'
, compileDebug: false
filename: file,
delimiter: '@',
compileDebug: false
});
try {
// Render without a required variable reference
@@ -884,9 +906,9 @@ suite('preprocessor include', function () {
test('is static', function () {
fs.writeFileSync(__dirname + '/tmp/include_preprocessor.ejs', '<p>Old</p>');
var file = 'test/fixtures/include_preprocessor_cache.ejs'
, options = {filename: file}
, out = ejs.compile(fixture('include_preprocessor_cache.ejs'), options);
var file = 'test/fixtures/include_preprocessor_cache.ejs';
var options = {filename: file};
var out = ejs.compile(fixture('include_preprocessor_cache.ejs'), options);
assert.equal(out(), '<p>Old</p>\n');
fs.writeFileSync(__dirname + '/tmp/include_preprocessor.ejs', '<p>New</p>');
@@ -895,10 +917,10 @@ suite('preprocessor include', function () {
test('support caching', function () {
fs.writeFileSync(__dirname + '/tmp/include_preprocessor.ejs', '<p>Old</p>');
var file = 'test/fixtures/include_preprocessor_cache.ejs'
, options = {cache: true, filename: file}
, out = ejs.render(fixture('include_preprocessor_cache.ejs'), {}, options)
, expected = fixture('include_preprocessor_cache.html');
var file = 'test/fixtures/include_preprocessor_cache.ejs';
var options = {cache: true, filename: file};
var out = ejs.render(fixture('include_preprocessor_cache.ejs'), {}, options);
var expected = fixture('include_preprocessor_cache.html');
assert.equal(out, expected);
fs.writeFileSync(__dirname + '/tmp/include_preprocessor.ejs', '<p>New</p>');
out = ejs.render(fixture('include_preprocessor_cache.ejs'), {}, options);
@@ -906,13 +928,13 @@ suite('preprocessor include', function () {
});
test('whitespace slurp and rmWhitespace work', function() {
var file = 'test/fixtures/include_preprocessor_line_slurp.ejs'
, template = fixture('include_preprocessor_line_slurp.ejs')
, expected = fixture('include_preprocessor_line_slurp.html')
, options = {rmWhitespace: true, filename: file};
assert.equal(ejs.render(template, options),
var file = 'test/fixtures/include_preprocessor_line_slurp.ejs';
var template = fixture('include_preprocessor_line_slurp.ejs');
var expected = fixture('include_preprocessor_line_slurp.html');
var options = {rmWhitespace: true, filename: file};
assert.equal(ejs.render(template, {}, options),
expected);
})
});
});
@@ -927,12 +949,12 @@ suite('require', function () {
// Only works with inline/preprocessor includes
test('allow ejs templates to be required as node modules', function () {
var file = 'test/fixtures/include_preprocessor.ejs'
, template = require(__dirname + '/fixtures/menu_preprocessor.ejs');
if (!process.env.running_under_istanbul) {
assert.equal(template({filename: file, pets: users}),
var file = 'test/fixtures/include_preprocessor.ejs';
var template = require(__dirname + '/fixtures/menu_preprocessor.ejs');
if (!process.env.running_under_istanbul) {
assert.equal(template({filename: file, pets: users}),
fixture('menu_preprocessor.html'));
}
}
});
});
@@ -944,8 +966,8 @@ suite('examples', function () {
}
suite(f, function () {
test('doesn\'t throw any errors', function () {
var stderr = hook_stdio(process.stderr, noop)
, stdout = hook_stdio(process.stdout, noop);
var stderr = hook_stdio(process.stderr, noop);
var stdout = hook_stdio(process.stdout, noop);
try {
require('../examples/' + f);
}
@@ -960,3 +982,13 @@ suite('examples', function () {
});
});
});
suite('meta information', function () {
test('has a version', function () {
assert.strictEqual(ejs.VERSION, require('../package.json').version);
});
test('had a name', function () {
assert.strictEqual(ejs.name, 'ejs');
});
});
@@ -1,5 +1,5 @@
AAA
<% data = "test"; -%>
<% var data = "test"; -%>
BBB
<%= qdata %>
CCC