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