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){
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | 'use strict';
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | var fs = require('fs');
|
49 | var path = require('path');
|
50 | var utils = require('./utils');
|
51 |
|
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';
|
58 | var _NAME = 'ejs';
|
59 | var _REGEX_STRING = '(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)';
|
60 | var _OPTS_PASSABLE_WITH_DATA = ['delimiter', 'scope', 'context', 'debug', 'compileDebug',
|
61 | 'client', '_with', 'rmWhitespace', 'strict', 'filename', 'async'];
|
62 |
|
63 |
|
64 |
|
65 | var _OPTS_PASSABLE_WITH_DATA_EXPRESS = _OPTS_PASSABLE_WITH_DATA.concat('cache');
|
66 | var _BOM = /^\uFEFF/;
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | exports.cache = utils.cache;
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | exports.fileLoader = fs.readFileSync;
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 | exports.localsName = _DEFAULT_LOCALS_NAME;
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 | exports.promiseImpl = (new Function('return this;'))().Promise;
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
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);
|
124 | if (!ext) {
|
125 | includePath += '.ejs';
|
126 | }
|
127 | return includePath;
|
128 | };
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 | function getIncludePath(path, options) {
|
138 | var includePath;
|
139 | var filePath;
|
140 | var views = options.views;
|
141 | var match = /^[A-Za-z]+:\\|^\//.exec(path);
|
142 |
|
143 |
|
144 | if (match && match.length) {
|
145 | includePath = exports.resolveInclude(path.replace(/^\/*/,''), options.root || '/', true);
|
146 | }
|
147 |
|
148 | else {
|
149 |
|
150 | if (options.filename) {
|
151 | filePath = exports.resolveInclude(path, options.filename);
|
152 | if (fs.existsSync(filePath)) {
|
153 | includePath = filePath;
|
154 | }
|
155 | }
|
156 |
|
157 | if (!includePath) {
|
158 | if (Array.isArray(views) && views.some(function (v) {
|
159 | filePath = exports.resolveInclude(path, v, true);
|
160 | return fs.existsSync(filePath);
|
161 | })) {
|
162 | includePath = filePath;
|
163 | }
|
164 | }
|
165 | if (!includePath) {
|
166 | throw new Error('Could not find the include file "' +
|
167 | options.escapeFunction(path) + '"');
|
168 | }
|
169 | }
|
170 | return includePath;
|
171 | }
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 | function handleCache(options, template) {
|
192 | var func;
|
193 | var filename = options.filename;
|
194 | var hasTemplate = arguments.length > 1;
|
195 |
|
196 | if (options.cache) {
|
197 | if (!filename) {
|
198 | throw new Error('cache option requires a filename');
|
199 | }
|
200 | func = exports.cache.get(filename);
|
201 | if (func) {
|
202 | return func;
|
203 | }
|
204 | if (!hasTemplate) {
|
205 | template = fileLoader(filename).toString().replace(_BOM, '');
|
206 | }
|
207 | }
|
208 | else if (!hasTemplate) {
|
209 |
|
210 | if (!filename) {
|
211 | throw new Error('Internal EJS error: no file name or template '
|
212 | + 'provided');
|
213 | }
|
214 | template = fileLoader(filename).toString().replace(_BOM, '');
|
215 | }
|
216 | func = exports.compile(template, options);
|
217 | if (options.cache) {
|
218 | exports.cache.set(filename, func);
|
219 | }
|
220 | return func;
|
221 | }
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 | function tryHandleCache(options, data, cb) {
|
236 | var result;
|
237 | if (!cb) {
|
238 | if (typeof exports.promiseImpl == 'function') {
|
239 | return new exports.promiseImpl(function (resolve, reject) {
|
240 | try {
|
241 | result = handleCache(options)(data);
|
242 | resolve(result);
|
243 | }
|
244 | catch (err) {
|
245 | reject(err);
|
246 | }
|
247 | });
|
248 | }
|
249 | else {
|
250 | throw new Error('Please provide a callback function');
|
251 | }
|
252 | }
|
253 | else {
|
254 | try {
|
255 | result = handleCache(options)(data);
|
256 | }
|
257 | catch (err) {
|
258 | return cb(err);
|
259 | }
|
260 |
|
261 | cb(null, result);
|
262 | }
|
263 | }
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 | function fileLoader(filePath){
|
274 | return exports.fileLoader(filePath);
|
275 | }
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 | function includeFile(path, options) {
|
291 | var opts = utils.shallowCopy({}, options);
|
292 | opts.filename = getIncludePath(path, opts);
|
293 | return handleCache(opts);
|
294 | }
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 | function rethrow(err, str, flnm, lineno, esc){
|
310 | var lines = str.split('\n');
|
311 | var start = Math.max(lineno - 3, 0);
|
312 | var end = Math.min(lines.length, lineno + 3);
|
313 | var filename = esc(flnm);
|
314 |
|
315 | var context = lines.slice(start, end).map(function (line, i){
|
316 | var curr = i + start + 1;
|
317 | return (curr == lineno ? ' >> ' : ' ')
|
318 | + curr
|
319 | + '| '
|
320 | + line;
|
321 | }).join('\n');
|
322 |
|
323 |
|
324 | err.path = filename;
|
325 | err.message = (filename || 'ejs') + ':'
|
326 | + lineno + '\n'
|
327 | + context + '\n\n'
|
328 | + err.message;
|
329 |
|
330 | throw err;
|
331 | }
|
332 |
|
333 | function stripSemi(str){
|
334 | return str.replace(/;(\s*$)/, '$1');
|
335 | }
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 | exports.compile = function compile(template, opts) {
|
351 | var templ;
|
352 |
|
353 |
|
354 |
|
355 |
|
356 | if (opts && opts.scope) {
|
357 | if (!scopeOptionWarned){
|
358 | console.warn('`scope` option is deprecated and will be removed in EJS 3');
|
359 | scopeOptionWarned = true;
|
360 | }
|
361 | if (!opts.context) {
|
362 | opts.context = opts.scope;
|
363 | }
|
364 | delete opts.scope;
|
365 | }
|
366 | templ = new Template(template, opts);
|
367 | return templ.compile();
|
368 | };
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 | exports.render = function (template, d, o) {
|
385 | var data = d || {};
|
386 | var opts = o || {};
|
387 |
|
388 |
|
389 |
|
390 | if (arguments.length == 2) {
|
391 | utils.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA);
|
392 | }
|
393 |
|
394 | return handleCache(opts, template)(data);
|
395 | };
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 | exports.renderFile = function () {
|
411 | var args = Array.prototype.slice.call(arguments);
|
412 | var filename = args.shift();
|
413 | var cb;
|
414 | var opts = {filename: filename};
|
415 | var data;
|
416 | var viewOpts;
|
417 |
|
418 |
|
419 | if (typeof arguments[arguments.length - 1] == 'function') {
|
420 | cb = args.pop();
|
421 | }
|
422 |
|
423 | if (args.length) {
|
424 |
|
425 | data = args.shift();
|
426 |
|
427 | if (args.length) {
|
428 |
|
429 | utils.shallowCopy(opts, args.pop());
|
430 | }
|
431 |
|
432 | else {
|
433 |
|
434 | if (data.settings) {
|
435 |
|
436 | if (data.settings.views) {
|
437 | opts.views = data.settings.views;
|
438 | }
|
439 | if (data.settings['view cache']) {
|
440 | opts.cache = true;
|
441 | }
|
442 |
|
443 |
|
444 | viewOpts = data.settings['view options'];
|
445 | if (viewOpts) {
|
446 | utils.shallowCopy(opts, viewOpts);
|
447 | }
|
448 | }
|
449 |
|
450 |
|
451 |
|
452 | utils.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA_EXPRESS);
|
453 | }
|
454 | opts.filename = filename;
|
455 | }
|
456 | else {
|
457 | data = {};
|
458 | }
|
459 |
|
460 | return tryHandleCache(opts, data, cb);
|
461 | };
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 |
|
468 |
|
469 |
|
470 |
|
471 |
|
472 | exports.Template = Template;
|
473 |
|
474 | exports.clearCache = function () {
|
475 | exports.cache.reset();
|
476 | };
|
477 |
|
478 | function Template(text, opts) {
|
479 | opts = opts || {};
|
480 | var options = {};
|
481 | this.templateText = text;
|
482 | this.mode = null;
|
483 | this.truncate = false;
|
484 | this.currentLine = 1;
|
485 | this.source = '';
|
486 | this.dependencies = [];
|
487 | options.client = opts.client || false;
|
488 | options.escapeFunction = opts.escape || opts.escapeFunction || utils.escapeXML;
|
489 | options.compileDebug = opts.compileDebug !== false;
|
490 | options.debug = !!opts.debug;
|
491 | options.filename = opts.filename;
|
492 | options.openDelimiter = opts.openDelimiter || exports.openDelimiter || _DEFAULT_OPEN_DELIMITER;
|
493 | options.closeDelimiter = opts.closeDelimiter || exports.closeDelimiter || _DEFAULT_CLOSE_DELIMITER;
|
494 | options.delimiter = opts.delimiter || exports.delimiter || _DEFAULT_DELIMITER;
|
495 | options.strict = opts.strict || false;
|
496 | options.context = opts.context;
|
497 | options.cache = opts.cache || false;
|
498 | options.rmWhitespace = opts.rmWhitespace;
|
499 | options.root = opts.root;
|
500 | options.outputFunctionName = opts.outputFunctionName;
|
501 | options.localsName = opts.localsName || exports.localsName || _DEFAULT_LOCALS_NAME;
|
502 | options.views = opts.views;
|
503 | options.async = opts.async;
|
504 | options.destructuredLocals = opts.destructuredLocals;
|
505 | options.legacyInclude = typeof opts.legacyInclude != 'undefined' ? !!opts.legacyInclude : true;
|
506 |
|
507 | if (options.strict) {
|
508 | options._with = false;
|
509 | }
|
510 | else {
|
511 | options._with = typeof opts._with != 'undefined' ? opts._with : true;
|
512 | }
|
513 |
|
514 | this.opts = options;
|
515 |
|
516 | this.regex = this.createRegex();
|
517 | }
|
518 |
|
519 | Template.modes = {
|
520 | EVAL: 'eval',
|
521 | ESCAPED: 'escaped',
|
522 | RAW: 'raw',
|
523 | COMMENT: 'comment',
|
524 | LITERAL: 'literal'
|
525 | };
|
526 |
|
527 | Template.prototype = {
|
528 | createRegex: function () {
|
529 | var str = _REGEX_STRING;
|
530 | var delim = utils.escapeRegExpChars(this.opts.delimiter);
|
531 | var open = utils.escapeRegExpChars(this.opts.openDelimiter);
|
532 | var close = utils.escapeRegExpChars(this.opts.closeDelimiter);
|
533 | str = str.replace(/%/g, delim)
|
534 | .replace(/</g, open)
|
535 | .replace(/>/g, close);
|
536 | return new RegExp(str);
|
537 | },
|
538 |
|
539 | compile: function () {
|
540 | var src;
|
541 | var fn;
|
542 | var opts = this.opts;
|
543 | var prepended = '';
|
544 | var appended = '';
|
545 | var escapeFn = opts.escapeFunction;
|
546 | var ctor;
|
547 |
|
548 | if (!this.source) {
|
549 | this.generateSource();
|
550 | prepended +=
|
551 | ' var __output = "";\n' +
|
552 | ' function __append(s) { if (s !== undefined && s !== null) __output += s }\n';
|
553 | if (opts.outputFunctionName) {
|
554 | prepended += ' var ' + opts.outputFunctionName + ' = __append;' + '\n';
|
555 | }
|
556 | if (opts.destructuredLocals && opts.destructuredLocals.length) {
|
557 | var destructuring = ' var __locals = (' + opts.localsName + ' || {}),\n';
|
558 | for (var i = 0; i < opts.destructuredLocals.length; i++) {
|
559 | var name = opts.destructuredLocals[i];
|
560 | if (i > 0) {
|
561 | destructuring += ',\n ';
|
562 | }
|
563 | destructuring += name + ' = __locals.' + name;
|
564 | }
|
565 | prepended += destructuring + ';\n';
|
566 | }
|
567 | if (opts._with !== false) {
|
568 | prepended += ' with (' + opts.localsName + ' || {}) {' + '\n';
|
569 | appended += ' }' + '\n';
|
570 | }
|
571 | appended += ' return __output;' + '\n';
|
572 | this.source = prepended + this.source + appended;
|
573 | }
|
574 |
|
575 | if (opts.compileDebug) {
|
576 | src = 'var __line = 1' + '\n'
|
577 | + ' , __lines = ' + JSON.stringify(this.templateText) + '\n'
|
578 | + ' , __filename = ' + (opts.filename ?
|
579 | JSON.stringify(opts.filename) : 'undefined') + ';' + '\n'
|
580 | + 'try {' + '\n'
|
581 | + this.source
|
582 | + '} catch (e) {' + '\n'
|
583 | + ' rethrow(e, __lines, __filename, __line, escapeFn);' + '\n'
|
584 | + '}' + '\n';
|
585 | }
|
586 | else {
|
587 | src = this.source;
|
588 | }
|
589 |
|
590 | if (opts.client) {
|
591 | src = 'escapeFn = escapeFn || ' + escapeFn.toString() + ';' + '\n' + src;
|
592 | if (opts.compileDebug) {
|
593 | src = 'rethrow = rethrow || ' + rethrow.toString() + ';' + '\n' + src;
|
594 | }
|
595 | }
|
596 |
|
597 | if (opts.strict) {
|
598 | src = '"use strict";\n' + src;
|
599 | }
|
600 | if (opts.debug) {
|
601 | console.log(src);
|
602 | }
|
603 | if (opts.compileDebug && opts.filename) {
|
604 | src = src + '\n'
|
605 | + '//# sourceURL=' + opts.filename + '\n';
|
606 | }
|
607 |
|
608 | try {
|
609 | if (opts.async) {
|
610 |
|
611 |
|
612 | try {
|
613 | ctor = (new Function('return (async function(){}).constructor;'))();
|
614 | }
|
615 | catch(e) {
|
616 | if (e instanceof SyntaxError) {
|
617 | throw new Error('This environment does not support async/await');
|
618 | }
|
619 | else {
|
620 | throw e;
|
621 | }
|
622 | }
|
623 | }
|
624 | else {
|
625 | ctor = Function;
|
626 | }
|
627 | fn = new ctor(opts.localsName + ', escapeFn, include, rethrow', src);
|
628 | }
|
629 | catch(e) {
|
630 |
|
631 | if (e instanceof SyntaxError) {
|
632 | if (opts.filename) {
|
633 | e.message += ' in ' + opts.filename;
|
634 | }
|
635 | e.message += ' while compiling ejs\n\n';
|
636 | e.message += 'If the above error is not helpful, you may want to try EJS-Lint:\n';
|
637 | e.message += 'https://github.com/RyanZim/EJS-Lint';
|
638 | if (!opts.async) {
|
639 | e.message += '\n';
|
640 | e.message += 'Or, if you meant to create an async function, pass `async: true` as an option.';
|
641 | }
|
642 | }
|
643 | throw e;
|
644 | }
|
645 |
|
646 |
|
647 |
|
648 |
|
649 | var returnedFn = opts.client ? fn : function anonymous(data) {
|
650 | var include = function (path, includeData) {
|
651 | var d = utils.shallowCopy({}, data);
|
652 | if (includeData) {
|
653 | d = utils.shallowCopy(d, includeData);
|
654 | }
|
655 | return includeFile(path, opts)(d);
|
656 | };
|
657 | return fn.apply(opts.context, [data || {}, escapeFn, include, rethrow]);
|
658 | };
|
659 | returnedFn.dependencies = this.dependencies;
|
660 | if (opts.filename && typeof Object.defineProperty === 'function') {
|
661 | var filename = opts.filename;
|
662 | var basename = path.basename(filename, path.extname(filename));
|
663 | try {
|
664 | Object.defineProperty(returnedFn, 'name', {
|
665 | value: basename,
|
666 | writable: false,
|
667 | enumerable: false,
|
668 | configurable: true
|
669 | });
|
670 | } catch (e) {}
|
671 | }
|
672 | return returnedFn;
|
673 | },
|
674 |
|
675 | generateSource: function () {
|
676 | var opts = this.opts;
|
677 |
|
678 | if (opts.rmWhitespace) {
|
679 |
|
680 |
|
681 | this.templateText =
|
682 | this.templateText.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
|
683 | }
|
684 |
|
685 |
|
686 | this.templateText =
|
687 | this.templateText.replace(/[ \t]*<%_/gm, '<%_').replace(/_%>[ \t]*/gm, '_%>');
|
688 |
|
689 | var self = this;
|
690 | var matches = this.parseTemplateText();
|
691 | var d = this.opts.delimiter;
|
692 | var o = this.opts.openDelimiter;
|
693 | var c = this.opts.closeDelimiter;
|
694 |
|
695 | if (matches && matches.length) {
|
696 | matches.forEach(function (line, index) {
|
697 | var closing;
|
698 |
|
699 |
|
700 |
|
701 |
|
702 | if ( line.indexOf(o + d) === 0
|
703 | && line.indexOf(o + d + d) !== 0) {
|
704 | closing = matches[index + 2];
|
705 | if (!(closing == d + c || closing == '-' + d + c || closing == '_' + d + c)) {
|
706 | throw new Error('Could not find matching close tag for "' + line + '".');
|
707 | }
|
708 | }
|
709 | self.scanLine(line);
|
710 | });
|
711 | }
|
712 |
|
713 | },
|
714 |
|
715 | parseTemplateText: function () {
|
716 | var str = this.templateText;
|
717 | var pat = this.regex;
|
718 | var result = pat.exec(str);
|
719 | var arr = [];
|
720 | var firstPos;
|
721 |
|
722 | while (result) {
|
723 | firstPos = result.index;
|
724 |
|
725 | if (firstPos !== 0) {
|
726 | arr.push(str.substring(0, firstPos));
|
727 | str = str.slice(firstPos);
|
728 | }
|
729 |
|
730 | arr.push(result[0]);
|
731 | str = str.slice(result[0].length);
|
732 | result = pat.exec(str);
|
733 | }
|
734 |
|
735 | if (str) {
|
736 | arr.push(str);
|
737 | }
|
738 |
|
739 | return arr;
|
740 | },
|
741 |
|
742 | _addOutput: function (line) {
|
743 | if (this.truncate) {
|
744 |
|
745 |
|
746 |
|
747 |
|
748 |
|
749 | line = line.replace(/^(?:\r\n|\r|\n)/, '');
|
750 | this.truncate = false;
|
751 | }
|
752 | if (!line) {
|
753 | return line;
|
754 | }
|
755 |
|
756 |
|
757 | line = line.replace(/\\/g, '\\\\');
|
758 |
|
759 |
|
760 | line = line.replace(/\n/g, '\\n');
|
761 | line = line.replace(/\r/g, '\\r');
|
762 |
|
763 |
|
764 |
|
765 | line = line.replace(/"/g, '\\"');
|
766 | this.source += ' ; __append("' + line + '")' + '\n';
|
767 | },
|
768 |
|
769 | scanLine: function (line) {
|
770 | var self = this;
|
771 | var d = this.opts.delimiter;
|
772 | var o = this.opts.openDelimiter;
|
773 | var c = this.opts.closeDelimiter;
|
774 | var newLineCount = 0;
|
775 |
|
776 | newLineCount = (line.split('\n').length - 1);
|
777 |
|
778 | switch (line) {
|
779 | case o + d:
|
780 | case o + d + '_':
|
781 | this.mode = Template.modes.EVAL;
|
782 | break;
|
783 | case o + d + '=':
|
784 | this.mode = Template.modes.ESCAPED;
|
785 | break;
|
786 | case o + d + '-':
|
787 | this.mode = Template.modes.RAW;
|
788 | break;
|
789 | case o + d + '#':
|
790 | this.mode = Template.modes.COMMENT;
|
791 | break;
|
792 | case o + d + d:
|
793 | this.mode = Template.modes.LITERAL;
|
794 | this.source += ' ; __append("' + line.replace(o + d + d, o + d) + '")' + '\n';
|
795 | break;
|
796 | case d + d + c:
|
797 | this.mode = Template.modes.LITERAL;
|
798 | this.source += ' ; __append("' + line.replace(d + d + c, d + c) + '")' + '\n';
|
799 | break;
|
800 | case d + c:
|
801 | case '-' + d + c:
|
802 | case '_' + d + c:
|
803 | if (this.mode == Template.modes.LITERAL) {
|
804 | this._addOutput(line);
|
805 | }
|
806 |
|
807 | this.mode = null;
|
808 | this.truncate = line.indexOf('-') === 0 || line.indexOf('_') === 0;
|
809 | break;
|
810 | default:
|
811 |
|
812 | if (this.mode) {
|
813 |
|
814 | switch (this.mode) {
|
815 | case Template.modes.EVAL:
|
816 | case Template.modes.ESCAPED:
|
817 | case Template.modes.RAW:
|
818 | if (line.lastIndexOf('//') > line.lastIndexOf('\n')) {
|
819 | line += '\n';
|
820 | }
|
821 | }
|
822 | switch (this.mode) {
|
823 |
|
824 | case Template.modes.EVAL:
|
825 | this.source += ' ; ' + line + '\n';
|
826 | break;
|
827 |
|
828 | case Template.modes.ESCAPED:
|
829 | this.source += ' ; __append(escapeFn(' + stripSemi(line) + '))' + '\n';
|
830 | break;
|
831 |
|
832 | case Template.modes.RAW:
|
833 | this.source += ' ; __append(' + stripSemi(line) + ')' + '\n';
|
834 | break;
|
835 | case Template.modes.COMMENT:
|
836 |
|
837 | break;
|
838 |
|
839 | case Template.modes.LITERAL:
|
840 | this._addOutput(line);
|
841 | break;
|
842 | }
|
843 | }
|
844 |
|
845 | else {
|
846 | this._addOutput(line);
|
847 | }
|
848 | }
|
849 |
|
850 | if (self.opts.compileDebug && newLineCount) {
|
851 | this.currentLine += newLineCount;
|
852 | this.source += ' ; __line = ' + this.currentLine + '\n';
|
853 | }
|
854 | }
|
855 | };
|
856 |
|
857 |
|
858 |
|
859 |
|
860 |
|
861 |
|
862 |
|
863 |
|
864 |
|
865 |
|
866 |
|
867 |
|
868 |
|
869 | exports.escapeXML = utils.escapeXML;
|
870 |
|
871 |
|
872 |
|
873 |
|
874 |
|
875 |
|
876 |
|
877 |
|
878 |
|
879 |
|
880 | exports.__express = exports.renderFile;
|
881 |
|
882 |
|
883 |
|
884 |
|
885 |
|
886 |
|
887 |
|
888 |
|
889 |
|
890 | exports.VERSION = _VERSION_STRING;
|
891 |
|
892 |
|
893 |
|
894 |
|
895 |
|
896 |
|
897 |
|
898 |
|
899 |
|
900 | exports.name = _NAME;
|
901 |
|
902 |
|
903 | if (typeof window != 'undefined') {
|
904 | window.ejs = exports;
|
905 | }
|
906 |
|
907 | },{"../package.json":6,"./utils":2,"fs":3,"path":4}],2:[function(require,module,exports){
|
908 |
|
909 |
|
910 |
|
911 |
|
912 |
|
913 |
|
914 |
|
915 |
|
916 |
|
917 |
|
918 |
|
919 |
|
920 |
|
921 |
|
922 |
|
923 |
|
924 |
|
925 |
|
926 |
|
927 |
|
928 |
|
929 |
|
930 |
|
931 |
|
932 | 'use strict';
|
933 |
|
934 | var regExpChars = /[|\\{}()[\]^$+*?.]/g;
|
935 |
|
936 |
|
937 |
|
938 |
|
939 |
|
940 |
|
941 |
|
942 |
|
943 |
|
944 |
|
945 |
|
946 | exports.escapeRegExpChars = function (string) {
|
947 |
|
948 | if (!string) {
|
949 | return '';
|
950 | }
|
951 | return String(string).replace(regExpChars, '\\$&');
|
952 | };
|
953 |
|
954 | var _ENCODE_HTML_RULES = {
|
955 | '&': '&',
|
956 | '<': '<',
|
957 | '>': '>',
|
958 | '"': '"',
|
959 | "'": '''
|
960 | };
|
961 | var _MATCH_HTML = /[&<>'"]/g;
|
962 |
|
963 | function encode_char(c) {
|
964 | return _ENCODE_HTML_RULES[c] || c;
|
965 | }
|
966 |
|
967 |
|
968 |
|
969 |
|
970 |
|
971 |
|
972 |
|
973 |
|
974 |
|
975 |
|
976 | var escapeFuncStr =
|
977 | 'var _ENCODE_HTML_RULES = {\n'
|
978 | + ' "&": "&"\n'
|
979 | + ' , "<": "<"\n'
|
980 | + ' , ">": ">"\n'
|
981 | + ' , \'"\': """\n'
|
982 | + ' , "\'": "'"\n'
|
983 | + ' }\n'
|
984 | + ' , _MATCH_HTML = /[&<>\'"]/g;\n'
|
985 | + 'function encode_char(c) {\n'
|
986 | + ' return _ENCODE_HTML_RULES[c] || c;\n'
|
987 | + '};\n';
|
988 |
|
989 |
|
990 |
|
991 |
|
992 |
|
993 |
|
994 |
|
995 |
|
996 |
|
997 |
|
998 |
|
999 |
|
1000 |
|
1001 | exports.escapeXML = function (markup) {
|
1002 | return markup == undefined
|
1003 | ? ''
|
1004 | : String(markup)
|
1005 | .replace(_MATCH_HTML, encode_char);
|
1006 | };
|
1007 | exports.escapeXML.toString = function () {
|
1008 | return Function.prototype.toString.call(this) + ';\n' + escapeFuncStr;
|
1009 | };
|
1010 |
|
1011 |
|
1012 |
|
1013 |
|
1014 |
|
1015 |
|
1016 |
|
1017 |
|
1018 |
|
1019 |
|
1020 |
|
1021 |
|
1022 | exports.shallowCopy = function (to, from) {
|
1023 | from = from || {};
|
1024 | for (var p in from) {
|
1025 | to[p] = from[p];
|
1026 | }
|
1027 | return to;
|
1028 | };
|
1029 |
|
1030 |
|
1031 |
|
1032 |
|
1033 |
|
1034 |
|
1035 |
|
1036 |
|
1037 |
|
1038 |
|
1039 |
|
1040 |
|
1041 |
|
1042 | exports.shallowCopyFromList = function (to, from, list) {
|
1043 | for (var i = 0; i < list.length; i++) {
|
1044 | var p = list[i];
|
1045 | if (typeof from[p] != 'undefined') {
|
1046 | to[p] = from[p];
|
1047 | }
|
1048 | }
|
1049 | return to;
|
1050 | };
|
1051 |
|
1052 |
|
1053 |
|
1054 |
|
1055 |
|
1056 |
|
1057 |
|
1058 |
|
1059 |
|
1060 | exports.cache = {
|
1061 | _data: {},
|
1062 | set: function (key, val) {
|
1063 | this._data[key] = val;
|
1064 | },
|
1065 | get: function (key) {
|
1066 | return this._data[key];
|
1067 | },
|
1068 | remove: function (key) {
|
1069 | delete this._data[key];
|
1070 | },
|
1071 | reset: function () {
|
1072 | this._data = {};
|
1073 | }
|
1074 | };
|
1075 |
|
1076 | },{}],3:[function(require,module,exports){
|
1077 |
|
1078 | },{}],4:[function(require,module,exports){
|
1079 | (function (process){
|
1080 |
|
1081 |
|
1082 |
|
1083 |
|
1084 |
|
1085 |
|
1086 |
|
1087 |
|
1088 |
|
1089 |
|
1090 |
|
1091 |
|
1092 |
|
1093 |
|
1094 |
|
1095 |
|
1096 |
|
1097 |
|
1098 |
|
1099 |
|
1100 |
|
1101 |
|
1102 |
|
1103 |
|
1104 |
|
1105 | function normalizeArray(parts, allowAboveRoot) {
|
1106 |
|
1107 | var up = 0;
|
1108 | for (var i = parts.length - 1; i >= 0; i--) {
|
1109 | var last = parts[i];
|
1110 | if (last === '.') {
|
1111 | parts.splice(i, 1);
|
1112 | } else if (last === '..') {
|
1113 | parts.splice(i, 1);
|
1114 | up++;
|
1115 | } else if (up) {
|
1116 | parts.splice(i, 1);
|
1117 | up--;
|
1118 | }
|
1119 | }
|
1120 |
|
1121 |
|
1122 | if (allowAboveRoot) {
|
1123 | for (; up--; up) {
|
1124 | parts.unshift('..');
|
1125 | }
|
1126 | }
|
1127 |
|
1128 | return parts;
|
1129 | }
|
1130 |
|
1131 |
|
1132 |
|
1133 | var splitPathRe =
|
1134 | /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
|
1135 | var splitPath = function(filename) {
|
1136 | return splitPathRe.exec(filename).slice(1);
|
1137 | };
|
1138 |
|
1139 |
|
1140 |
|
1141 | exports.resolve = function() {
|
1142 | var resolvedPath = '',
|
1143 | resolvedAbsolute = false;
|
1144 |
|
1145 | for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
1146 | var path = (i >= 0) ? arguments[i] : process.cwd();
|
1147 |
|
1148 |
|
1149 | if (typeof path !== 'string') {
|
1150 | throw new TypeError('Arguments to path.resolve must be strings');
|
1151 | } else if (!path) {
|
1152 | continue;
|
1153 | }
|
1154 |
|
1155 | resolvedPath = path + '/' + resolvedPath;
|
1156 | resolvedAbsolute = path.charAt(0) === '/';
|
1157 | }
|
1158 |
|
1159 |
|
1160 |
|
1161 |
|
1162 |
|
1163 | resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
|
1164 | return !!p;
|
1165 | }), !resolvedAbsolute).join('/');
|
1166 |
|
1167 | return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
|
1168 | };
|
1169 |
|
1170 |
|
1171 |
|
1172 | exports.normalize = function(path) {
|
1173 | var isAbsolute = exports.isAbsolute(path),
|
1174 | trailingSlash = substr(path, -1) === '/';
|
1175 |
|
1176 |
|
1177 | path = normalizeArray(filter(path.split('/'), function(p) {
|
1178 | return !!p;
|
1179 | }), !isAbsolute).join('/');
|
1180 |
|
1181 | if (!path && !isAbsolute) {
|
1182 | path = '.';
|
1183 | }
|
1184 | if (path && trailingSlash) {
|
1185 | path += '/';
|
1186 | }
|
1187 |
|
1188 | return (isAbsolute ? '/' : '') + path;
|
1189 | };
|
1190 |
|
1191 |
|
1192 | exports.isAbsolute = function(path) {
|
1193 | return path.charAt(0) === '/';
|
1194 | };
|
1195 |
|
1196 |
|
1197 | exports.join = function() {
|
1198 | var paths = Array.prototype.slice.call(arguments, 0);
|
1199 | return exports.normalize(filter(paths, function(p, index) {
|
1200 | if (typeof p !== 'string') {
|
1201 | throw new TypeError('Arguments to path.join must be strings');
|
1202 | }
|
1203 | return p;
|
1204 | }).join('/'));
|
1205 | };
|
1206 |
|
1207 |
|
1208 |
|
1209 |
|
1210 | exports.relative = function(from, to) {
|
1211 | from = exports.resolve(from).substr(1);
|
1212 | to = exports.resolve(to).substr(1);
|
1213 |
|
1214 | function trim(arr) {
|
1215 | var start = 0;
|
1216 | for (; start < arr.length; start++) {
|
1217 | if (arr[start] !== '') break;
|
1218 | }
|
1219 |
|
1220 | var end = arr.length - 1;
|
1221 | for (; end >= 0; end--) {
|
1222 | if (arr[end] !== '') break;
|
1223 | }
|
1224 |
|
1225 | if (start > end) return [];
|
1226 | return arr.slice(start, end - start + 1);
|
1227 | }
|
1228 |
|
1229 | var fromParts = trim(from.split('/'));
|
1230 | var toParts = trim(to.split('/'));
|
1231 |
|
1232 | var length = Math.min(fromParts.length, toParts.length);
|
1233 | var samePartsLength = length;
|
1234 | for (var i = 0; i < length; i++) {
|
1235 | if (fromParts[i] !== toParts[i]) {
|
1236 | samePartsLength = i;
|
1237 | break;
|
1238 | }
|
1239 | }
|
1240 |
|
1241 | var outputParts = [];
|
1242 | for (var i = samePartsLength; i < fromParts.length; i++) {
|
1243 | outputParts.push('..');
|
1244 | }
|
1245 |
|
1246 | outputParts = outputParts.concat(toParts.slice(samePartsLength));
|
1247 |
|
1248 | return outputParts.join('/');
|
1249 | };
|
1250 |
|
1251 | exports.sep = '/';
|
1252 | exports.delimiter = ':';
|
1253 |
|
1254 | exports.dirname = function(path) {
|
1255 | var result = splitPath(path),
|
1256 | root = result[0],
|
1257 | dir = result[1];
|
1258 |
|
1259 | if (!root && !dir) {
|
1260 |
|
1261 | return '.';
|
1262 | }
|
1263 |
|
1264 | if (dir) {
|
1265 |
|
1266 | dir = dir.substr(0, dir.length - 1);
|
1267 | }
|
1268 |
|
1269 | return root + dir;
|
1270 | };
|
1271 |
|
1272 |
|
1273 | exports.basename = function(path, ext) {
|
1274 | var f = splitPath(path)[2];
|
1275 |
|
1276 | if (ext && f.substr(-1 * ext.length) === ext) {
|
1277 | f = f.substr(0, f.length - ext.length);
|
1278 | }
|
1279 | return f;
|
1280 | };
|
1281 |
|
1282 |
|
1283 | exports.extname = function(path) {
|
1284 | return splitPath(path)[3];
|
1285 | };
|
1286 |
|
1287 | function filter (xs, f) {
|
1288 | if (xs.filter) return xs.filter(f);
|
1289 | var res = [];
|
1290 | for (var i = 0; i < xs.length; i++) {
|
1291 | if (f(xs[i], i, xs)) res.push(xs[i]);
|
1292 | }
|
1293 | return res;
|
1294 | }
|
1295 |
|
1296 |
|
1297 | var substr = 'ab'.substr(-1) === 'b'
|
1298 | ? function (str, start, len) { return str.substr(start, len) }
|
1299 | : function (str, start, len) {
|
1300 | if (start < 0) start = str.length + start;
|
1301 | return str.substr(start, len);
|
1302 | }
|
1303 | ;
|
1304 |
|
1305 | }).call(this,require('_process'))
|
1306 | },{"_process":5}],5:[function(require,module,exports){
|
1307 |
|
1308 | var process = module.exports = {};
|
1309 |
|
1310 |
|
1311 |
|
1312 |
|
1313 |
|
1314 |
|
1315 | var cachedSetTimeout;
|
1316 | var cachedClearTimeout;
|
1317 |
|
1318 | function defaultSetTimout() {
|
1319 | throw new Error('setTimeout has not been defined');
|
1320 | }
|
1321 | function defaultClearTimeout () {
|
1322 | throw new Error('clearTimeout has not been defined');
|
1323 | }
|
1324 | (function () {
|
1325 | try {
|
1326 | if (typeof setTimeout === 'function') {
|
1327 | cachedSetTimeout = setTimeout;
|
1328 | } else {
|
1329 | cachedSetTimeout = defaultSetTimout;
|
1330 | }
|
1331 | } catch (e) {
|
1332 | cachedSetTimeout = defaultSetTimout;
|
1333 | }
|
1334 | try {
|
1335 | if (typeof clearTimeout === 'function') {
|
1336 | cachedClearTimeout = clearTimeout;
|
1337 | } else {
|
1338 | cachedClearTimeout = defaultClearTimeout;
|
1339 | }
|
1340 | } catch (e) {
|
1341 | cachedClearTimeout = defaultClearTimeout;
|
1342 | }
|
1343 | } ())
|
1344 | function runTimeout(fun) {
|
1345 | if (cachedSetTimeout === setTimeout) {
|
1346 |
|
1347 | return setTimeout(fun, 0);
|
1348 | }
|
1349 |
|
1350 | if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
1351 | cachedSetTimeout = setTimeout;
|
1352 | return setTimeout(fun, 0);
|
1353 | }
|
1354 | try {
|
1355 |
|
1356 | return cachedSetTimeout(fun, 0);
|
1357 | } catch(e){
|
1358 | try {
|
1359 |
|
1360 | return cachedSetTimeout.call(null, fun, 0);
|
1361 | } catch(e){
|
1362 |
|
1363 | return cachedSetTimeout.call(this, fun, 0);
|
1364 | }
|
1365 | }
|
1366 |
|
1367 |
|
1368 | }
|
1369 | function runClearTimeout(marker) {
|
1370 | if (cachedClearTimeout === clearTimeout) {
|
1371 |
|
1372 | return clearTimeout(marker);
|
1373 | }
|
1374 |
|
1375 | if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
1376 | cachedClearTimeout = clearTimeout;
|
1377 | return clearTimeout(marker);
|
1378 | }
|
1379 | try {
|
1380 |
|
1381 | return cachedClearTimeout(marker);
|
1382 | } catch (e){
|
1383 | try {
|
1384 |
|
1385 | return cachedClearTimeout.call(null, marker);
|
1386 | } catch (e){
|
1387 |
|
1388 |
|
1389 | return cachedClearTimeout.call(this, marker);
|
1390 | }
|
1391 | }
|
1392 |
|
1393 |
|
1394 |
|
1395 | }
|
1396 | var queue = [];
|
1397 | var draining = false;
|
1398 | var currentQueue;
|
1399 | var queueIndex = -1;
|
1400 |
|
1401 | function cleanUpNextTick() {
|
1402 | if (!draining || !currentQueue) {
|
1403 | return;
|
1404 | }
|
1405 | draining = false;
|
1406 | if (currentQueue.length) {
|
1407 | queue = currentQueue.concat(queue);
|
1408 | } else {
|
1409 | queueIndex = -1;
|
1410 | }
|
1411 | if (queue.length) {
|
1412 | drainQueue();
|
1413 | }
|
1414 | }
|
1415 |
|
1416 | function drainQueue() {
|
1417 | if (draining) {
|
1418 | return;
|
1419 | }
|
1420 | var timeout = runTimeout(cleanUpNextTick);
|
1421 | draining = true;
|
1422 |
|
1423 | var len = queue.length;
|
1424 | while(len) {
|
1425 | currentQueue = queue;
|
1426 | queue = [];
|
1427 | while (++queueIndex < len) {
|
1428 | if (currentQueue) {
|
1429 | currentQueue[queueIndex].run();
|
1430 | }
|
1431 | }
|
1432 | queueIndex = -1;
|
1433 | len = queue.length;
|
1434 | }
|
1435 | currentQueue = null;
|
1436 | draining = false;
|
1437 | runClearTimeout(timeout);
|
1438 | }
|
1439 |
|
1440 | process.nextTick = function (fun) {
|
1441 | var args = new Array(arguments.length - 1);
|
1442 | if (arguments.length > 1) {
|
1443 | for (var i = 1; i < arguments.length; i++) {
|
1444 | args[i - 1] = arguments[i];
|
1445 | }
|
1446 | }
|
1447 | queue.push(new Item(fun, args));
|
1448 | if (queue.length === 1 && !draining) {
|
1449 | runTimeout(drainQueue);
|
1450 | }
|
1451 | };
|
1452 |
|
1453 |
|
1454 | function Item(fun, array) {
|
1455 | this.fun = fun;
|
1456 | this.array = array;
|
1457 | }
|
1458 | Item.prototype.run = function () {
|
1459 | this.fun.apply(null, this.array);
|
1460 | };
|
1461 | process.title = 'browser';
|
1462 | process.browser = true;
|
1463 | process.env = {};
|
1464 | process.argv = [];
|
1465 | process.version = '';
|
1466 | process.versions = {};
|
1467 |
|
1468 | function noop() {}
|
1469 |
|
1470 | process.on = noop;
|
1471 | process.addListener = noop;
|
1472 | process.once = noop;
|
1473 | process.off = noop;
|
1474 | process.removeListener = noop;
|
1475 | process.removeAllListeners = noop;
|
1476 | process.emit = noop;
|
1477 | process.prependListener = noop;
|
1478 | process.prependOnceListener = noop;
|
1479 |
|
1480 | process.listeners = function (name) { return [] }
|
1481 |
|
1482 | process.binding = function (name) {
|
1483 | throw new Error('process.binding is not supported');
|
1484 | };
|
1485 |
|
1486 | process.cwd = function () { return '/' };
|
1487 | process.chdir = function (dir) {
|
1488 | throw new Error('process.chdir is not supported');
|
1489 | };
|
1490 | process.umask = function() { return 0; };
|
1491 |
|
1492 | },{}],6:[function(require,module,exports){
|
1493 | module.exports={
|
1494 | "name": "ejs",
|
1495 | "description": "Embedded JavaScript templates",
|
1496 | "keywords": [
|
1497 | "template",
|
1498 | "engine",
|
1499 | "ejs"
|
1500 | ],
|
1501 | "version": "3.0.1",
|
1502 | "author": "Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)",
|
1503 | "license": "Apache-2.0",
|
1504 | "main": "./lib/ejs.js",
|
1505 | "repository": {
|
1506 | "type": "git",
|
1507 | "url": "git://github.com/mde/ejs.git"
|
1508 | },
|
1509 | "bugs": "https://github.com/mde/ejs/issues",
|
1510 | "homepage": "https://github.com/mde/ejs",
|
1511 | "dependencies": {},
|
1512 | "devDependencies": {
|
1513 | "browserify": "^13.1.1",
|
1514 | "eslint": "^4.14.0",
|
1515 | "git-directory-deploy": "^1.5.1",
|
1516 | "jake": "^10.3.1",
|
1517 | "jsdoc": "^3.4.0",
|
1518 | "lru-cache": "^4.0.1",
|
1519 | "mocha": "^5.0.5",
|
1520 | "uglify-js": "^3.3.16"
|
1521 | },
|
1522 | "engines": {
|
1523 | "node": ">=0.10.0"
|
1524 | },
|
1525 | "scripts": {
|
1526 | "test": "mocha",
|
1527 | "postinstall": "node ./postinstall.js"
|
1528 | }
|
1529 | }
|
1530 |
|
1531 | },{}]},{},[1])(1)
|
1532 | });
|