1 (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(){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}return e})()({1:[function(require,module,exports){
3 * EJS Embedded JavaScript templates
4 * Copyright 2112 Matthew Eernisse (mde@fleegix.org)
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 * @file Embedded JavaScript templating engine. {@link http://ejs.co}
24 * @author Matthew Eernisse <mde@fleegix.org>
25 * @author Tiancheng "Timothy" Gu <timothygu99@gmail.com>
27 * @license {@link http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0}
31 * EJS internal functions.
33 * Technically this "module" lies in the same file as {@link module:ejs}, for
34 * the sake of organization all the private functions re grouped into this
37 * @module ejs-internal
42 * Embedded JavaScript templating engine.
48 var fs = require('fs');
49 var path = require('path');
50 var utils = require('./utils');
52 var scopeOptionWarned = false;
53 var _VERSION_STRING = require('../package.json').version;
54 var _DEFAULT_OPEN_DELIMITER = '<';
55 var _DEFAULT_CLOSE_DELIMITER = '>';
56 var _DEFAULT_DELIMITER = '%';
57 var _DEFAULT_LOCALS_NAME = 'locals';
59 var _REGEX_STRING = '(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)';
60 var _OPTS_PASSABLE_WITH_DATA = ['delimiter', 'scope', 'context', 'debug', 'compileDebug',
61 'client', '_with', 'rmWhitespace', 'strict', 'filename', 'async'];
62 // We don't allow 'cache' option to be passed in the data obj for
63 // the normal `render` call, but this is where Express 2 & 3 put it
64 // so we make an exception for `renderFile`
65 var _OPTS_PASSABLE_WITH_DATA_EXPRESS = _OPTS_PASSABLE_WITH_DATA.concat('cache');
69 * EJS template function cache. This can be a LRU object from lru-cache NPM
70 * module. By default, it is {@link module:utils.cache}, a simple in-process
71 * cache that grows continuously.
76 exports.cache = utils.cache;
79 * Custom file loader. Useful for template preprocessing or restricting access
80 * to a certain part of the filesystem.
85 exports.fileLoader = fs.readFileSync;
88 * Name of the object containing the locals.
90 * This variable is overridden by {@link Options}`.localsName` if it is not
97 exports.localsName = _DEFAULT_LOCALS_NAME;
100 * Promise implementation -- defaults to the native implementation if available
101 * This is mostly just for testability
107 exports.promiseImpl = (new Function('return this;'))().Promise;
110 * Get the path to the included file from the parent file path and the
113 * @param {String} name specified path
114 * @param {String} filename parent file path
115 * @param {Boolean} isDir parent file path whether is directory
118 exports.resolveInclude = function(name, filename, isDir) {
119 var dirname = path.dirname;
120 var extname = path.extname;
121 var resolve = path.resolve;
122 var includePath = resolve(isDir ? filename : dirname(filename), name);
123 var ext = extname(name);
125 includePath += '.ejs';
131 * Get the path to the included file by Options
133 * @param {String} path specified path
134 * @param {Options} options compilation options
137 function getIncludePath(path, options) {
140 var views = options.views;
141 var match = /^[A-Za-z]+:\\|^\//.exec(path);
144 if (match && match.length) {
145 includePath = exports.resolveInclude(path.replace(/^\/*/,''), options.root || '/', true);
149 // Look relative to a passed filename first
150 if (options.filename) {
151 filePath = exports.resolveInclude(path, options.filename);
152 if (fs.existsSync(filePath)) {
153 includePath = filePath;
156 // Then look in any views directories
158 if (Array.isArray(views) && views.some(function (v) {
159 filePath = exports.resolveInclude(path, v, true);
160 return fs.existsSync(filePath);
162 includePath = filePath;
166 throw new Error('Could not find the include file "' +
167 options.escapeFunction(path) + '"');
174 * Get the template from a string or a file, either compiled on-the-fly or
175 * read from cache (if enabled), and cache the template if needed.
177 * If `template` is not set, the file specified in `options.filename` will be
180 * If `options.cache` is true, this function reads the file from
181 * `options.filename` so it must be set prior to calling this function.
183 * @memberof module:ejs-internal
184 * @param {Options} options compilation options
185 * @param {String} [template] template source
186 * @return {(TemplateFunction|ClientFunction)}
187 * Depending on the value of `options.client`, either type might be returned.
191 function handleCache(options, template) {
193 var filename = options.filename;
194 var hasTemplate = arguments.length > 1;
198 throw new Error('cache option requires a filename');
200 func = exports.cache.get(filename);
205 template = fileLoader(filename).toString().replace(_BOM, '');
208 else if (!hasTemplate) {
209 // istanbul ignore if: should not happen at all
211 throw new Error('Internal EJS error: no file name or template '
214 template = fileLoader(filename).toString().replace(_BOM, '');
216 func = exports.compile(template, options);
218 exports.cache.set(filename, func);
224 * Try calling handleCache with the given options and data and call the
225 * callback with the result. If an error occurs, call the callback with
226 * the error. Used by renderFile().
228 * @memberof module:ejs-internal
229 * @param {Options} options compilation options
230 * @param {Object} data template data
231 * @param {RenderFileCallback} cb callback
235 function tryHandleCache(options, data, cb) {
238 if (typeof exports.promiseImpl == 'function') {
239 return new exports.promiseImpl(function (resolve, reject) {
241 result = handleCache(options)(data);
250 throw new Error('Please provide a callback function');
255 result = handleCache(options)(data);
266 * fileLoader is independent
268 * @param {String} filePath ejs file path.
269 * @return {String} The contents of the specified file.
273 function fileLoader(filePath){
274 return exports.fileLoader(filePath);
278 * Get the template function.
280 * If `options.cache` is `true`, then the template is cached.
282 * @memberof module:ejs-internal
283 * @param {String} path path for the specified file
284 * @param {Options} options compilation options
285 * @return {(TemplateFunction|ClientFunction)}
286 * Depending on the value of `options.client`, either type might be returned
290 function includeFile(path, options) {
291 var opts = utils.shallowCopy({}, options);
292 opts.filename = getIncludePath(path, opts);
293 return handleCache(opts);
297 * Get the JavaScript source of an included file.
299 * @memberof module:ejs-internal
300 * @param {String} path path for the specified file
301 * @param {Options} options compilation options
306 function includeSource(path, options) {
307 var opts = utils.shallowCopy({}, options);
310 includePath = getIncludePath(path, opts);
311 template = fileLoader(includePath).toString().replace(_BOM, '');
312 opts.filename = includePath;
313 var templ = new Template(template, opts);
314 templ.generateSource();
316 source: templ.source,
317 filename: includePath,
323 * Re-throw the given `err` in context to the `str` of ejs, `filename`, and
326 * @implements RethrowCallback
327 * @memberof module:ejs-internal
328 * @param {Error} err Error object
329 * @param {String} str EJS source
330 * @param {String} filename file name of the EJS file
331 * @param {String} lineno line number of the error
335 function rethrow(err, str, flnm, lineno, esc){
336 var lines = str.split('\n');
337 var start = Math.max(lineno - 3, 0);
338 var end = Math.min(lines.length, lineno + 3);
339 var filename = esc(flnm); // eslint-disable-line
341 var context = lines.slice(start, end).map(function (line, i){
342 var curr = i + start + 1;
343 return (curr == lineno ? ' >> ' : ' ')
349 // Alter exception message
351 err.message = (filename || 'ejs') + ':'
359 function stripSemi(str){
360 return str.replace(/;(\s*$)/, '$1');
364 * Compile the given `str` of ejs into a template function.
366 * @param {String} template EJS template
368 * @param {Options} opts compilation options
370 * @return {(TemplateFunction|ClientFunction)}
371 * Depending on the value of `opts.client`, either type might be returned.
372 * Note that the return type of the function also depends on the value of `opts.async`.
376 exports.compile = function compile(template, opts) {
380 // 'scope' is 'context'
381 // FIXME: Remove this in a future version
382 if (opts && opts.scope) {
383 if (!scopeOptionWarned){
384 console.warn('`scope` option is deprecated and will be removed in EJS 3');
385 scopeOptionWarned = true;
388 opts.context = opts.scope;
392 templ = new Template(template, opts);
393 return templ.compile();
397 * Render the given `template` of ejs.
399 * If you would like to include options but not data, you need to explicitly
400 * call this function with `data` being an empty object or `null`.
402 * @param {String} template EJS template
403 * @param {Object} [data={}] template data
404 * @param {Options} [opts={}] compilation and rendering options
405 * @return {(String|Promise<String>)}
406 * Return value type depends on `opts.async`.
410 exports.render = function (template, d, o) {
414 // No options object -- if there are optiony names
415 // in the data, copy them to options
416 if (arguments.length == 2) {
417 utils.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA);
420 return handleCache(opts, template)(data);
424 * Render an EJS file at the given `path` and callback `cb(err, str)`.
426 * If you would like to include options but not data, you need to explicitly
427 * call this function with `data` being an empty object or `null`.
429 * @param {String} path path to the EJS file
430 * @param {Object} [data={}] template data
431 * @param {Options} [opts={}] compilation and rendering options
432 * @param {RenderFileCallback} cb callback
436 exports.renderFile = function () {
437 var args = Array.prototype.slice.call(arguments);
438 var filename = args.shift();
440 var opts = {filename: filename};
444 // Do we have a callback?
445 if (typeof arguments[arguments.length - 1] == 'function') {
448 // Do we have data/opts?
450 // Should always have data obj
452 // Normal passed opts (data obj + opts obj)
454 // Use shallowCopy so we don't pollute passed in opts obj with new vals
455 utils.shallowCopy(opts, args.pop());
457 // Special casing for Express (settings + opts-in-data)
461 // Pull a few things from known locations
462 if (data.settings.views) {
463 opts.views = data.settings.views;
465 if (data.settings['view cache']) {
468 // Undocumented after Express 2, but still usable, esp. for
469 // items that are unsafe to be passed along with data, like `root`
470 viewOpts = data.settings['view options'];
472 utils.shallowCopy(opts, viewOpts);
475 // Express 2 and lower, values set in app.locals, or people who just
476 // want to pass options in their data. NOTE: These values will override
477 // anything previously set in settings or settings['view options']
478 utils.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA_EXPRESS);
480 opts.filename = filename;
486 return tryHandleCache(opts, data, cb);
490 * Clear intermediate JavaScript cache. Calls {@link Cache#reset}.
498 exports.Template = Template;
500 exports.clearCache = function () {
501 exports.cache.reset();
504 function Template(text, opts) {
507 this.templateText = text;
509 this.truncate = false;
510 this.currentLine = 1;
512 this.dependencies = [];
513 options.client = opts.client || false;
514 options.escapeFunction = opts.escape || opts.escapeFunction || utils.escapeXML;
515 options.compileDebug = opts.compileDebug !== false;
516 options.debug = !!opts.debug;
517 options.filename = opts.filename;
518 options.openDelimiter = opts.openDelimiter || exports.openDelimiter || _DEFAULT_OPEN_DELIMITER;
519 options.closeDelimiter = opts.closeDelimiter || exports.closeDelimiter || _DEFAULT_CLOSE_DELIMITER;
520 options.delimiter = opts.delimiter || exports.delimiter || _DEFAULT_DELIMITER;
521 options.strict = opts.strict || false;
522 options.context = opts.context;
523 options.cache = opts.cache || false;
524 options.rmWhitespace = opts.rmWhitespace;
525 options.root = opts.root;
526 options.outputFunctionName = opts.outputFunctionName;
527 options.localsName = opts.localsName || exports.localsName || _DEFAULT_LOCALS_NAME;
528 options.views = opts.views;
529 options.async = opts.async;
531 if (options.strict) {
532 options._with = false;
535 options._with = typeof opts._with != 'undefined' ? opts._with : true;
540 this.regex = this.createRegex();
551 Template.prototype = {
552 createRegex: function () {
553 var str = _REGEX_STRING;
554 var delim = utils.escapeRegExpChars(this.opts.delimiter);
555 var open = utils.escapeRegExpChars(this.opts.openDelimiter);
556 var close = utils.escapeRegExpChars(this.opts.closeDelimiter);
557 str = str.replace(/%/g, delim)
559 .replace(/>/g, close);
560 return new RegExp(str);
563 compile: function () {
566 var opts = this.opts;
569 var escapeFn = opts.escapeFunction;
573 this.generateSource();
574 prepended += ' var __output = [], __append = __output.push.bind(__output);' + '\n';
575 if (opts.outputFunctionName) {
576 prepended += ' var ' + opts.outputFunctionName + ' = __append;' + '\n';
578 if (opts._with !== false) {
579 prepended += ' with (' + opts.localsName + ' || {}) {' + '\n';
580 appended += ' }' + '\n';
582 appended += ' return __output.join("");' + '\n';
583 this.source = prepended + this.source + appended;
586 if (opts.compileDebug) {
587 src = 'var __line = 1' + '\n'
588 + ' , __lines = ' + JSON.stringify(this.templateText) + '\n'
589 + ' , __filename = ' + (opts.filename ?
590 JSON.stringify(opts.filename) : 'undefined') + ';' + '\n'
593 + '} catch (e) {' + '\n'
594 + ' rethrow(e, __lines, __filename, __line, escapeFn);' + '\n'
602 src = 'escapeFn = escapeFn || ' + escapeFn.toString() + ';' + '\n' + src;
603 if (opts.compileDebug) {
604 src = 'rethrow = rethrow || ' + rethrow.toString() + ';' + '\n' + src;
609 src = '"use strict";\n' + src;
617 // Have to use generated function for this, since in envs without support,
618 // it breaks in parsing
620 ctor = (new Function('return (async function(){}).constructor;'))();
623 if (e instanceof SyntaxError) {
624 throw new Error('This environment does not support async/await');
634 fn = new ctor(opts.localsName + ', escapeFn, include, rethrow', src);
637 // istanbul ignore else
638 if (e instanceof SyntaxError) {
640 e.message += ' in ' + opts.filename;
642 e.message += ' while compiling ejs\n\n';
643 e.message += 'If the above error is not helpful, you may want to try EJS-Lint:\n';
644 e.message += 'https://github.com/RyanZim/EJS-Lint';
647 e.message += 'Or, if you meant to create an async function, pass async: true as an option.';
654 fn.dependencies = this.dependencies;
658 // Return a callable function which will execute the function
659 // created by the source-code, with the passed data as locals
660 // Adds a local `include` function which allows full recursive include
661 var returnedFn = function (data) {
662 var include = function (path, includeData) {
663 var d = utils.shallowCopy({}, data);
665 d = utils.shallowCopy(d, includeData);
667 return includeFile(path, opts)(d);
669 return fn.apply(opts.context, [data || {}, escapeFn, include, rethrow]);
671 returnedFn.dependencies = this.dependencies;
675 generateSource: function () {
676 var opts = this.opts;
678 if (opts.rmWhitespace) {
679 // Have to use two separate replace here as `^` and `$` operators don't
680 // work well with `\r` and empty lines don't work well with the `m` flag.
682 this.templateText.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
685 // Slurp spaces and tabs before <%_ and after _%>
687 this.templateText.replace(/[ \t]*<%_/gm, '<%_').replace(/_%>[ \t]*/gm, '_%>');
690 var matches = this.parseTemplateText();
691 var d = this.opts.delimiter;
692 var o = this.opts.openDelimiter;
693 var c = this.opts.closeDelimiter;
695 if (matches && matches.length) {
696 matches.forEach(function (line, index) {
703 // If this is an opening tag, check for closing tags
704 // FIXME: May end up with some false positives here
705 // Better to store modes as k/v with openDelimiter + delimiter as key
706 // Then this can simply check against the map
707 if ( line.indexOf(o + d) === 0 // If it is a tag
708 && line.indexOf(o + d + d) !== 0) { // and is not escaped
709 closing = matches[index + 2];
710 if (!(closing == d + c || closing == '-' + d + c || closing == '_' + d + c)) {
711 throw new Error('Could not find matching close tag for "' + line + '".');
714 // HACK: backward-compat `include` preprocessor directives
715 if ((include = line.match(/^\s*include\s+(\S+)/))) {
716 opening = matches[index - 1];
717 // Must be in EVAL or RAW mode
718 if (opening && (opening == o + d || opening == o + d + '-' || opening == o + d + '_')) {
719 includeOpts = utils.shallowCopy({}, self.opts);
720 includeObj = includeSource(include[1], includeOpts);
721 if (self.opts.compileDebug) {
723 ' ; (function(){' + '\n'
724 + ' var __line = 1' + '\n'
725 + ' , __lines = ' + JSON.stringify(includeObj.template) + '\n'
726 + ' , __filename = ' + JSON.stringify(includeObj.filename) + ';' + '\n'
729 + ' } catch (e) {' + '\n'
730 + ' rethrow(e, __lines, __filename, __line, escapeFn);' + '\n'
732 + ' ; }).call(this)' + '\n';
734 includeSrc = ' ; (function(){' + '\n' + includeObj.source +
735 ' ; }).call(this)' + '\n';
737 self.source += includeSrc;
738 self.dependencies.push(exports.resolveInclude(include[1],
739 includeOpts.filename));
749 parseTemplateText: function () {
750 var str = this.templateText;
751 var pat = this.regex;
752 var result = pat.exec(str);
757 firstPos = result.index;
759 if (firstPos !== 0) {
760 arr.push(str.substring(0, firstPos));
761 str = str.slice(firstPos);
765 str = str.slice(result[0].length);
766 result = pat.exec(str);
776 _addOutput: function (line) {
778 // Only replace single leading linebreak in the line after
779 // -%> tag -- this is the single, trailing linebreak
780 // after the tag that the truncation mode replaces
781 // Handle Win / Unix / old Mac linebreaks -- do the \r\n
782 // combo first in the regex-or
783 line = line.replace(/^(?:\r\n|\r|\n)/, '');
784 this.truncate = false;
790 // Preserve literal slashes
791 line = line.replace(/\\/g, '\\\\');
793 // Convert linebreaks
794 line = line.replace(/\n/g, '\\n');
795 line = line.replace(/\r/g, '\\r');
797 // Escape double-quotes
798 // - this will be the delimiter during execution
799 line = line.replace(/"/g, '\\"');
800 this.source += ' ; __append("' + line + '")' + '\n';
803 scanLine: function (line) {
805 var d = this.opts.delimiter;
806 var o = this.opts.openDelimiter;
807 var c = this.opts.closeDelimiter;
808 var newLineCount = 0;
810 newLineCount = (line.split('\n').length - 1);
815 this.mode = Template.modes.EVAL;
818 this.mode = Template.modes.ESCAPED;
821 this.mode = Template.modes.RAW;
824 this.mode = Template.modes.COMMENT;
827 this.mode = Template.modes.LITERAL;
828 this.source += ' ; __append("' + line.replace(o + d + d, o + d) + '")' + '\n';
831 this.mode = Template.modes.LITERAL;
832 this.source += ' ; __append("' + line.replace(d + d + c, d + c) + '")' + '\n';
837 if (this.mode == Template.modes.LITERAL) {
838 this._addOutput(line);
842 this.truncate = line.indexOf('-') === 0 || line.indexOf('_') === 0;
845 // In script mode, depends on type of tag
847 // If '//' is found without a line break, add a line break.
849 case Template.modes.EVAL:
850 case Template.modes.ESCAPED:
851 case Template.modes.RAW:
852 if (line.lastIndexOf('//') > line.lastIndexOf('\n')) {
857 // Just executing code
858 case Template.modes.EVAL:
859 this.source += ' ; ' + line + '\n';
861 // Exec, esc, and output
862 case Template.modes.ESCAPED:
863 this.source += ' ; __append(escapeFn(' + stripSemi(line) + '))' + '\n';
866 case Template.modes.RAW:
867 this.source += ' ; __append(' + stripSemi(line) + ')' + '\n';
869 case Template.modes.COMMENT:
872 // Literal <%% mode, append as raw output
873 case Template.modes.LITERAL:
874 this._addOutput(line);
878 // In string mode, just add the output
880 this._addOutput(line);
884 if (self.opts.compileDebug && newLineCount) {
885 this.currentLine += newLineCount;
886 this.source += ' ; __line = ' + this.currentLine + '\n';
892 * Escape characters reserved in XML.
894 * This is simply an export of {@link module:utils.escapeXML}.
896 * If `markup` is `undefined` or `null`, the empty string is returned.
898 * @param {String} markup Input string
899 * @return {String} Escaped string
903 exports.escapeXML = utils.escapeXML;
906 * Express.js support.
908 * This is an alias for {@link module:ejs.renderFile}, in order to support
909 * Express.js out-of-the-box.
914 exports.__express = exports.renderFile;
916 // Add require support
917 /* istanbul ignore else */
918 if (require.extensions) {
919 require.extensions['.ejs'] = function (module, flnm) {
920 var filename = flnm || /* istanbul ignore next */ module.filename;
925 var template = fileLoader(filename).toString();
926 var fn = exports.compile(template, options);
927 module._compile('module.exports = ' + fn.toString() + ';', filename);
939 exports.VERSION = _VERSION_STRING;
942 * Name for detection of EJS.
949 exports.name = _NAME;
951 /* istanbul ignore if */
952 if (typeof window != 'undefined') {
953 window.ejs = exports;
956 },{"../package.json":6,"./utils":2,"fs":3,"path":4}],2:[function(require,module,exports){
958 * EJS Embedded JavaScript templates
959 * Copyright 2112 Matthew Eernisse (mde@fleegix.org)
961 * Licensed under the Apache License, Version 2.0 (the "License");
962 * you may not use this file except in compliance with the License.
963 * You may obtain a copy of the License at
965 * http://www.apache.org/licenses/LICENSE-2.0
967 * Unless required by applicable law or agreed to in writing, software
968 * distributed under the License is distributed on an "AS IS" BASIS,
969 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
970 * See the License for the specific language governing permissions and
971 * limitations under the License.
976 * Private utility functions
983 var regExpChars = /[|\\{}()[\]^$+*?.]/g;
986 * Escape characters reserved in regular expressions.
988 * If `string` is `undefined` or `null`, the empty string is returned.
990 * @param {String} string Input string
991 * @return {String} Escaped string
995 exports.escapeRegExpChars = function (string) {
996 // istanbul ignore if
1000 return String(string).replace(regExpChars, '\\$&');
1003 var _ENCODE_HTML_RULES = {
1010 var _MATCH_HTML = /[&<>'"]/g;
1012 function encode_char(c) {
1013 return _ENCODE_HTML_RULES[c] || c;
1017 * Stringified version of constants used by {@link module:utils.escapeXML}.
1019 * It is used in the process of generating {@link ClientFunction}s.
1026 'var _ENCODE_HTML_RULES = {\n'
1028 + ' , "<": "<"\n'
1029 + ' , ">": ">"\n'
1030 + ' , \'"\': """\n'
1031 + ' , "\'": "'"\n'
1033 + ' , _MATCH_HTML = /[&<>\'"]/g;\n'
1034 + 'function encode_char(c) {\n'
1035 + ' return _ENCODE_HTML_RULES[c] || c;\n'
1039 * Escape characters reserved in XML.
1041 * If `markup` is `undefined` or `null`, the empty string is returned.
1043 * @implements {EscapeCallback}
1044 * @param {String} markup Input string
1045 * @return {String} Escaped string
1050 exports.escapeXML = function (markup) {
1051 return markup == undefined
1054 .replace(_MATCH_HTML, encode_char);
1056 exports.escapeXML.toString = function () {
1057 return Function.prototype.toString.call(this) + ';\n' + escapeFuncStr;
1061 * Naive copy of properties from one object to another.
1062 * Does not recurse into non-scalar properties
1063 * Does not check to see if the property has a value before copying
1065 * @param {Object} to Destination object
1066 * @param {Object} from Source object
1067 * @return {Object} Destination object
1071 exports.shallowCopy = function (to, from) {
1073 for (var p in from) {
1080 * Naive copy of a list of key names, from one object to another.
1081 * Only copies property if it is actually defined
1082 * Does not recurse into non-scalar properties
1084 * @param {Object} to Destination object
1085 * @param {Object} from Source object
1086 * @param {Array} list List of properties to copy
1087 * @return {Object} Destination object
1091 exports.shallowCopyFromList = function (to, from, list) {
1092 for (var i = 0; i < list.length; i++) {
1094 if (typeof from[p] != 'undefined') {
1102 * Simple in-process cache implementation. Does not implement limits of any
1111 set: function (key, val) {
1112 this._data[key] = val;
1114 get: function (key) {
1115 return this._data[key];
1117 remove: function (key) {
1118 delete this._data[key];
1120 reset: function () {
1125 },{}],3:[function(require,module,exports){
1127 },{}],4:[function(require,module,exports){
1128 (function (process){
1129 // Copyright Joyent, Inc. and other Node contributors.
1131 // Permission is hereby granted, free of charge, to any person obtaining a
1132 // copy of this software and associated documentation files (the
1133 // "Software"), to deal in the Software without restriction, including
1134 // without limitation the rights to use, copy, modify, merge, publish,
1135 // distribute, sublicense, and/or sell copies of the Software, and to permit
1136 // persons to whom the Software is furnished to do so, subject to the
1137 // following conditions:
1139 // The above copyright notice and this permission notice shall be included
1140 // in all copies or substantial portions of the Software.
1142 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1143 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1144 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
1145 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
1146 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1147 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
1148 // USE OR OTHER DEALINGS IN THE SOFTWARE.
1150 // resolves . and .. elements in a path array with directory names there
1151 // must be no slashes, empty elements, or device names (c:\) in the array
1152 // (so also no leading and trailing slashes - it does not distinguish
1153 // relative and absolute paths)
1154 function normalizeArray(parts, allowAboveRoot) {
1155 // if the path tries to go above the root, `up` ends up > 0
1157 for (var i = parts.length - 1; i >= 0; i--) {
1158 var last = parts[i];
1161 } else if (last === '..') {
1170 // if the path is allowed to go above the root, restore leading ..s
1171 if (allowAboveRoot) {
1173 parts.unshift('..');
1180 // Split a filename into [root, dir, basename, ext], unix version
1181 // 'root' is just a slash, or nothing.
1183 /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
1184 var splitPath = function(filename) {
1185 return splitPathRe.exec(filename).slice(1);
1188 // path.resolve([from ...], to)
1190 exports.resolve = function() {
1191 var resolvedPath = '',
1192 resolvedAbsolute = false;
1194 for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
1195 var path = (i >= 0) ? arguments[i] : process.cwd();
1197 // Skip empty and invalid entries
1198 if (typeof path !== 'string') {
1199 throw new TypeError('Arguments to path.resolve must be strings');
1204 resolvedPath = path + '/' + resolvedPath;
1205 resolvedAbsolute = path.charAt(0) === '/';
1208 // At this point the path should be resolved to a full absolute path, but
1209 // handle relative paths to be safe (might happen when process.cwd() fails)
1211 // Normalize the path
1212 resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
1214 }), !resolvedAbsolute).join('/');
1216 return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
1219 // path.normalize(path)
1221 exports.normalize = function(path) {
1222 var isAbsolute = exports.isAbsolute(path),
1223 trailingSlash = substr(path, -1) === '/';
1225 // Normalize the path
1226 path = normalizeArray(filter(path.split('/'), function(p) {
1228 }), !isAbsolute).join('/');
1230 if (!path && !isAbsolute) {
1233 if (path && trailingSlash) {
1237 return (isAbsolute ? '/' : '') + path;
1241 exports.isAbsolute = function(path) {
1242 return path.charAt(0) === '/';
1246 exports.join = function() {
1247 var paths = Array.prototype.slice.call(arguments, 0);
1248 return exports.normalize(filter(paths, function(p, index) {
1249 if (typeof p !== 'string') {
1250 throw new TypeError('Arguments to path.join must be strings');
1257 // path.relative(from, to)
1259 exports.relative = function(from, to) {
1260 from = exports.resolve(from).substr(1);
1261 to = exports.resolve(to).substr(1);
1263 function trim(arr) {
1265 for (; start < arr.length; start++) {
1266 if (arr[start] !== '') break;
1269 var end = arr.length - 1;
1270 for (; end >= 0; end--) {
1271 if (arr[end] !== '') break;
1274 if (start > end) return [];
1275 return arr.slice(start, end - start + 1);
1278 var fromParts = trim(from.split('/'));
1279 var toParts = trim(to.split('/'));
1281 var length = Math.min(fromParts.length, toParts.length);
1282 var samePartsLength = length;
1283 for (var i = 0; i < length; i++) {
1284 if (fromParts[i] !== toParts[i]) {
1285 samePartsLength = i;
1290 var outputParts = [];
1291 for (var i = samePartsLength; i < fromParts.length; i++) {
1292 outputParts.push('..');
1295 outputParts = outputParts.concat(toParts.slice(samePartsLength));
1297 return outputParts.join('/');
1301 exports.delimiter = ':';
1303 exports.dirname = function(path) {
1304 var result = splitPath(path),
1308 if (!root && !dir) {
1309 // No dirname whatsoever
1314 // It has a dirname, strip trailing slash
1315 dir = dir.substr(0, dir.length - 1);
1322 exports.basename = function(path, ext) {
1323 var f = splitPath(path)[2];
1324 // TODO: make this comparison case-insensitive on windows?
1325 if (ext && f.substr(-1 * ext.length) === ext) {
1326 f = f.substr(0, f.length - ext.length);
1332 exports.extname = function(path) {
1333 return splitPath(path)[3];
1336 function filter (xs, f) {
1337 if (xs.filter) return xs.filter(f);
1339 for (var i = 0; i < xs.length; i++) {
1340 if (f(xs[i], i, xs)) res.push(xs[i]);
1345 // String.prototype.substr - negative index don't work in IE8
1346 var substr = 'ab'.substr(-1) === 'b'
1347 ? function (str, start, len) { return str.substr(start, len) }
1348 : function (str, start, len) {
1349 if (start < 0) start = str.length + start;
1350 return str.substr(start, len);
1354 }).call(this,require('_process'))
1355 },{"_process":5}],5:[function(require,module,exports){
1356 // shim for using process in browser
1357 var process = module.exports = {};
1359 // cached from whatever global is present so that test runners that stub it
1360 // don't break things. But we need to wrap it in a try catch in case it is
1361 // wrapped in strict mode code which doesn't define any globals. It's inside a
1362 // function because try/catches deoptimize in certain engines.
1364 var cachedSetTimeout;
1365 var cachedClearTimeout;
1367 function defaultSetTimout() {
1368 throw new Error('setTimeout has not been defined');
1370 function defaultClearTimeout () {
1371 throw new Error('clearTimeout has not been defined');
1375 if (typeof setTimeout === 'function') {
1376 cachedSetTimeout = setTimeout;
1378 cachedSetTimeout = defaultSetTimout;
1381 cachedSetTimeout = defaultSetTimout;
1384 if (typeof clearTimeout === 'function') {
1385 cachedClearTimeout = clearTimeout;
1387 cachedClearTimeout = defaultClearTimeout;
1390 cachedClearTimeout = defaultClearTimeout;
1393 function runTimeout(fun) {
1394 if (cachedSetTimeout === setTimeout) {
1395 //normal enviroments in sane situations
1396 return setTimeout(fun, 0);
1398 // if setTimeout wasn't available but was latter defined
1399 if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
1400 cachedSetTimeout = setTimeout;
1401 return setTimeout(fun, 0);
1404 // when when somebody has screwed with setTimeout but no I.E. maddness
1405 return cachedSetTimeout(fun, 0);
1408 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
1409 return cachedSetTimeout.call(null, fun, 0);
1411 // 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
1412 return cachedSetTimeout.call(this, fun, 0);
1418 function runClearTimeout(marker) {
1419 if (cachedClearTimeout === clearTimeout) {
1420 //normal enviroments in sane situations
1421 return clearTimeout(marker);
1423 // if clearTimeout wasn't available but was latter defined
1424 if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
1425 cachedClearTimeout = clearTimeout;
1426 return clearTimeout(marker);
1429 // when when somebody has screwed with setTimeout but no I.E. maddness
1430 return cachedClearTimeout(marker);
1433 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
1434 return cachedClearTimeout.call(null, marker);
1436 // 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.
1437 // Some versions of I.E. have different rules for clearTimeout vs setTimeout
1438 return cachedClearTimeout.call(this, marker);
1446 var draining = false;
1448 var queueIndex = -1;
1450 function cleanUpNextTick() {
1451 if (!draining || !currentQueue) {
1455 if (currentQueue.length) {
1456 queue = currentQueue.concat(queue);
1465 function drainQueue() {
1469 var timeout = runTimeout(cleanUpNextTick);
1472 var len = queue.length;
1474 currentQueue = queue;
1476 while (++queueIndex < len) {
1478 currentQueue[queueIndex].run();
1484 currentQueue = null;
1486 runClearTimeout(timeout);
1489 process.nextTick = function (fun) {
1490 var args = new Array(arguments.length - 1);
1491 if (arguments.length > 1) {
1492 for (var i = 1; i < arguments.length; i++) {
1493 args[i - 1] = arguments[i];
1496 queue.push(new Item(fun, args));
1497 if (queue.length === 1 && !draining) {
1498 runTimeout(drainQueue);
1502 // v8 likes predictible objects
1503 function Item(fun, array) {
1507 Item.prototype.run = function () {
1508 this.fun.apply(null, this.array);
1510 process.title = 'browser';
1511 process.browser = true;
1514 process.version = ''; // empty string to avoid regexp issues
1515 process.versions = {};
1520 process.addListener = noop;
1521 process.once = noop;
1523 process.removeListener = noop;
1524 process.removeAllListeners = noop;
1525 process.emit = noop;
1526 process.prependListener = noop;
1527 process.prependOnceListener = noop;
1529 process.listeners = function (name) { return [] }
1531 process.binding = function (name) {
1532 throw new Error('process.binding is not supported');
1535 process.cwd = function () { return '/' };
1536 process.chdir = function (dir) {
1537 throw new Error('process.chdir is not supported');
1539 process.umask = function() { return 0; };
1541 },{}],6:[function(require,module,exports){
1544 "description": "Embedded JavaScript templates",
1551 "author": "Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)",
1553 "Timothy Gu <timothygu99@gmail.com> (https://timothygu.github.io)"
1555 "license": "Apache-2.0",
1556 "main": "./lib/ejs.js",
1559 "url": "git://github.com/mde/ejs.git"
1561 "bugs": "https://github.com/mde/ejs/issues",
1562 "homepage": "https://github.com/mde/ejs",
1564 "devDependencies": {
1565 "browserify": "^13.1.1",
1566 "eslint": "^4.14.0",
1567 "git-directory-deploy": "^1.5.1",
1568 "istanbul": "~0.4.3",
1571 "lru-cache": "^4.0.1",
1573 "uglify-js": "^3.3.16"
1579 "test": "jake test",
1580 "lint": "eslint \"**/*.js\" Jakefile",
1581 "coverage": "istanbul cover node_modules/mocha/bin/_mocha",
1583 "devdoc": "jake doc[dev]"