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