UNPKG

14.1 kBJavaScriptView Raw
1(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){"use strict";var utils=require("./utils"),ejs,templateCache={},jsCache={},includeFile,includeSource,resolveInclude,compile,rethrow,_DEFAULT_DELIMITER="%",_REGEX_STRING="(<%%)|(<%=)|(<%-)|(<%#)|(<%)|(%>)|(-%>)",_OPTS_MAP={cache:"cache",filename:"filename",delimiter:"delimiter",scope:"context",context:"context",debug:"debug",compileDebug:"compileDebug",client:"client"};resolveInclude=function(name,filename){var path=require("path"),dirname=path.dirname,extname=path.extname,resolve=path.resolve,includePath=resolve(dirname(filename),name),ext=extname(name);if(!ext){includePath+=".ejs"}return includePath};includeFile=function(path,options){var fn,opts=utils.shallowCopy({},options||{}),fs=require("fs"),includePath,template;if(!opts.filename){throw new Error("`include` requires the 'filename' option.")}includePath=resolveInclude(path,opts.filename);if(opts.cache){template=templateCache[includePath];if(!template){template=fs.readFileSync(includePath).toString().trim();templateCache[includePath]=template}}else{template=fs.readFileSync(includePath).toString().trim()}opts.filename=includePath;fn=exports.compile(template,opts);return fn};includeSource=function(path,options){var fn,opts=utils.shallowCopy({},options||{}),fs=require("fs"),includePath,template;if(!opts.filename){throw new Error("`include` requires the 'filename' option.")}includePath=resolveInclude(path,opts.filename);if(opts.cache){template=templateCache[includePath];if(!template){template=fs.readFileSync(includePath).toString().trim();templateCache[includePath]=template}}else{template=fs.readFileSync(includePath).toString().trim()}opts.filename=includePath;var templ=new Template(template,opts);templ.generateSource();return templ.source};rethrow=function(err,str,filename,lineno){var lines=str.split("\n"),start=Math.max(lineno-3,0),end=Math.min(lines.length,lineno+3);var context=lines.slice(start,end).map(function(line,i){var curr=i+start+1;return(curr==lineno?" >> ":" ")+curr+"| "+line}).join("\n");err.path=filename;err.message=(filename||"ejs")+":"+lineno+"\n"+context+"\n\n"+err.message;throw err};compile=exports.compile=function(template,opts){var templ=new Template(template,opts);return templ.compile()};exports.render=function(){var args=Array.prototype.slice.call(arguments),template=args.shift(),data=args.shift()||{},opts=args.shift()||{},fn,filename;if(arguments.length==2){for(var p in _OPTS_MAP){if(typeof data[p]!="undefined"){opts[_OPTS_MAP[p]]=data[p]}}}if(opts.scope){if(!opts.context){opts.context=opts.scope}delete opts.scope}if(opts.cache){filename=opts.filename;if(!filename){throw new Error("cache option requires a filename")}fn=jsCache[filename];if(!fn){fn=exports.compile(template,opts);jsCache[filename]=fn}}else{fn=exports.compile(template,opts)}return fn.call(opts.context,data)};exports.renderFile=function(){var read=require("fs").readFile,args=Array.prototype.slice.call(arguments),path=args.shift(),cb=args.pop(),data=args.shift()||{},opts=args.pop()||{},template,handleTemplate;opts.filename=path;handleTemplate=function(template){var result,failed=false;try{result=exports.render(template,data,opts)}catch(err){cb(err);failed=true}if(!failed)cb(null,result)};template=templateCache[path];if(opts.cache&&template){handleTemplate(template)}else{read(path,function(err,data){var tmpl;if(err){return cb(err)}tmpl=data.toString().trim();if(opts.cache){templateCache[path]=tmpl}handleTemplate(tmpl)})}};exports.clearCache=function(){templateCache={};jsCache={}};var Template=function(text,opts){opts=opts||{};var options={};this.templateText=text;this.mode=null;this.truncate=false;this.currentLine=1;this.source="";options.client=opts.client||false;options.escapeFunction=opts.escape||utils.escapeXML;options.compileDebug=opts.compileDebug!==false;options.debug=!!opts.debug;options.filename=opts.filename;options.delimiter=opts.delimiter||exports.delimiter||_DEFAULT_DELIMITER;options._with=opts._with!=null?opts._with:true;this.opts=options;this.regex=this.createRegex()};Template.prototype=new function(){this.modes={EVAL:"eval",ESCAPED:"escaped",RAW:"raw",APPEND:"append",COMMENT:"comment",LITERAL:"literal"};this.createRegex=function(){var str=_REGEX_STRING,delim=utils.escapeRegExpChars(this.opts.delimiter);str=str.replace(/%/g,delim);return new RegExp(str)};this.compile=function(){var self=this,src,fn,opts=this.opts,escape=opts.escapeFunction;if(!this.source){this.generateSource();var appended='var __output = "";';if(opts._with!==false)appended+=" with (locals || {}) { ";this.source=appended+this.source;if(opts._with!==false)this.source+="}";this.source+="return __output.trim();"}if(opts.compileDebug){src="var __line = 1"+", __lines = "+JSON.stringify(this.templateText)+", __filename = "+(opts.filename?JSON.stringify(opts.filename):"undefined")+"; try {"+this.source+"} catch (e) { rethrow(e, __lines, __filename, __line); }"}else{src=this.source}if(opts.debug){console.log(src)}if(opts.client){src="escape = escape || "+escape.toString()+";\n"+src;src="rethrow = rethrow || "+rethrow.toString()+";\n"+src}try{fn=new Function("locals, escape, include, rethrow",src)}catch(e){if(e instanceof SyntaxError){if(opts.filename){e.message+=" in "+opts.filename}e.message+=" while compiling ejs";throw e}}if(opts.client){return fn}return function(data){var include=function(path,includeData){var d=utils.shallowCopy({},data);if(includeData){d=utils.shallowCopy(d,includeData)}return includeFile(path,opts).apply(this,[d])};return fn.apply(this,[data||{},escape,include,rethrow])}};this.generateSource=function(){var self=this,matches=this.parseTemplateText(),d=this.opts.delimiter;if(matches&&matches.length){matches.forEach(function(line,index){var closing,include,includeOpts,includeSrc;if(line.indexOf("<"+d)===0){closing=matches[index+2];if(!(closing==d+">"||closing=="-"+d+">")){throw new Error('Could not find matching close tag for "'+line+'".')}}if(include=line.match(/^\s*include\s+(\S+)/)){includeOpts=utils.shallowCopy({},self.opts);includeSrc=includeSource(include[1],includeOpts);includeSrc=";(function(){"+includeSrc+"})();";self.source+=includeSrc}else{self.scanLine(line)}})}};this.parseTemplateText=function(){var str=this.templateText,pat=this.regex,result=pat.exec(str),arr=[],firstPos,lastPos;while(result){firstPos=result.index;lastPos=pat.lastIndex;if(firstPos!==0){arr.push(str.substring(0,firstPos));str=str.slice(firstPos)}arr.push(result[0]);str=str.slice(result[0].length);result=pat.exec(str)}if(str!==""){arr.push(str)}return arr};this.scanLine=function(line){var self=this,d=this.opts.delimiter,newLineCount=0,_addOutput;_addOutput=function(){if(self.truncate){line=line.replace("\n","")}line=line.replace(/\\/g,"\\\\");line=line.replace(/\n/g,"\\n");line=line.replace(/\r/g,"\\r");line=line.replace(/"/g,'\\"');self.source+=';__output += "'+line+'";'};newLineCount=line.split("\n").length-1;switch(line){case"<"+d:this.mode=this.modes.EVAL;break;case"<"+d+"=":this.mode=this.modes.ESCAPED;break;case"<"+d+"-":this.mode=this.modes.RAW;break;case"<"+d+"#":this.mode=this.modes.COMMENT;break;case"<"+d+d:this.mode=this.modes.LITERAL;this.source+=';__output += "'+line.replace("<"+d+d,"<"+d)+'";';break;case d+">":case"-"+d+">":if(this.mode==this.modes.LITERAL){_addOutput()}this.mode=null;this.truncate=line.indexOf("-")===0;break;default:if(this.mode){switch(this.mode){case this.modes.EVAL:case this.modes.ESCAPED:case this.modes.RAW:line=line.replace(/\/\/.*$/,"")}switch(this.mode){case this.modes.EVAL:this.source+=";"+line;break;case this.modes.ESCAPED:this.source+=";__output += escape("+line.replace(/;\S*/,"").trim()+");";break;case this.modes.RAW:this.source+=";__output += "+line.trim()+";";break;case this.modes.COMMENT:break;case this.modes.LITERAL:_addOutput();break}}else{_addOutput()}}if(newLineCount){this.currentLine+=newLineCount;this.source+=";__line = "+this.currentLine+";"}}};exports.__express=exports.renderFile;if(require.extensions){require.extensions[".ejs"]=function(module,filename){filename=filename||module.filename;var fs=require("fs"),options={filename:filename,client:true},template=fs.readFileSync(filename).toString().trim(),fn=compile(template,options);module._compile("module.exports = "+fn.toString()+";",filename)}}if(typeof window!="undefined"){window.ejs=exports}},{"./utils":2,fs:3,path:4}],2:[function(require,module,exports){"use strict";exports.escapeRegExpChars=function(){var specials=["^","$","/",".","*","+","?","|","(",")","[","]","{","}","\\"];var sRE=new RegExp("(\\"+specials.join("|\\")+")","g");return function(string){var str=string||"";str=String(str);return str.replace(sRE,"\\$1")}}();exports.escapeXML=function(markup){var chars={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},str=String(markup);Object.keys(chars).forEach(function(k){str=str.replace(new RegExp(k,"g"),chars[k])});return str};exports.shallowCopy=function(to,from){for(var p in from){to[p]=from[p]}return to}},{}],3:[function(require,module,exports){},{}],4:[function(require,module,exports){(function(process){function normalizeArray(parts,allowAboveRoot){var up=0;for(var i=parts.length-1;i>=0;i--){var last=parts[i];if(last==="."){parts.splice(i,1)}else if(last===".."){parts.splice(i,1);up++}else if(up){parts.splice(i,1);up--}}if(allowAboveRoot){for(;up--;up){parts.unshift("..")}}return parts}var splitPathRe=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;var splitPath=function(filename){return splitPathRe.exec(filename).slice(1)};exports.resolve=function(){var resolvedPath="",resolvedAbsolute=false;for(var i=arguments.length-1;i>=-1&&!resolvedAbsolute;i--){var path=i>=0?arguments[i]:process.cwd();if(typeof path!=="string"){throw new TypeError("Arguments to path.resolve must be strings")}else if(!path){continue}resolvedPath=path+"/"+resolvedPath;resolvedAbsolute=path.charAt(0)==="/"}resolvedPath=normalizeArray(filter(resolvedPath.split("/"),function(p){return!!p}),!resolvedAbsolute).join("/");return(resolvedAbsolute?"/":"")+resolvedPath||"."};exports.normalize=function(path){var isAbsolute=exports.isAbsolute(path),trailingSlash=substr(path,-1)==="/";path=normalizeArray(filter(path.split("/"),function(p){return!!p}),!isAbsolute).join("/");if(!path&&!isAbsolute){path="."}if(path&&trailingSlash){path+="/"}return(isAbsolute?"/":"")+path};exports.isAbsolute=function(path){return path.charAt(0)==="/"};exports.join=function(){var paths=Array.prototype.slice.call(arguments,0);return exports.normalize(filter(paths,function(p,index){if(typeof p!=="string"){throw new TypeError("Arguments to path.join must be strings")}return p}).join("/"))};exports.relative=function(from,to){from=exports.resolve(from).substr(1);to=exports.resolve(to).substr(1);function trim(arr){var start=0;for(;start<arr.length;start++){if(arr[start]!=="")break}var end=arr.length-1;for(;end>=0;end--){if(arr[end]!=="")break}if(start>end)return[];return arr.slice(start,end-start+1)}var fromParts=trim(from.split("/"));var toParts=trim(to.split("/"));var length=Math.min(fromParts.length,toParts.length);var samePartsLength=length;for(var i=0;i<length;i++){if(fromParts[i]!==toParts[i]){samePartsLength=i;break}}var outputParts=[];for(var i=samePartsLength;i<fromParts.length;i++){outputParts.push("..")}outputParts=outputParts.concat(toParts.slice(samePartsLength));return outputParts.join("/")};exports.sep="/";exports.delimiter=":";exports.dirname=function(path){var result=splitPath(path),root=result[0],dir=result[1];if(!root&&!dir){return"."}if(dir){dir=dir.substr(0,dir.length-1)}return root+dir};exports.basename=function(path,ext){var f=splitPath(path)[2];if(ext&&f.substr(-1*ext.length)===ext){f=f.substr(0,f.length-ext.length)}return f};exports.extname=function(path){return splitPath(path)[3]};function filter(xs,f){if(xs.filter)return xs.filter(f);var res=[];for(var i=0;i<xs.length;i++){if(f(xs[i],i,xs))res.push(xs[i])}return res}var substr="ab".substr(-1)==="b"?function(str,start,len){return str.substr(start,len)}:function(str,start,len){if(start<0)start=str.length+start;return str.substr(start,len)}}).call(this,require("_process"))},{_process:5}],5:[function(require,module,exports){var process=module.exports={};process.nextTick=function(){var canSetImmediate=typeof window!=="undefined"&&window.setImmediate;var canMutationObserver=typeof window!=="undefined"&&window.MutationObserver;var canPost=typeof window!=="undefined"&&window.postMessage&&window.addEventListener;if(canSetImmediate){return function(f){return window.setImmediate(f)}}var queue=[];if(canMutationObserver){var hiddenDiv=document.createElement("div");var observer=new MutationObserver(function(){var queueList=queue.slice();queue.length=0;queueList.forEach(function(fn){fn()})});observer.observe(hiddenDiv,{attributes:true});return function nextTick(fn){if(!queue.length){hiddenDiv.setAttribute("yes","no")}queue.push(fn)}}if(canPost){window.addEventListener("message",function(ev){var source=ev.source;if((source===window||source===null)&&ev.data==="process-tick"){ev.stopPropagation();if(queue.length>0){var fn=queue.shift();fn()}}},true);return function nextTick(fn){queue.push(fn);window.postMessage("process-tick","*")}}return function nextTick(fn){setTimeout(fn,0)}}();process.title="browser";process.browser=true;process.env={};process.argv=[];function noop(){}process.on=noop;process.addListener=noop;process.once=noop;process.off=noop;process.removeListener=noop;process.removeAllListeners=noop;process.emit=noop;process.binding=function(name){throw new Error("process.binding is not supported")};process.cwd=function(){return"/"};process.chdir=function(dir){throw new Error("process.chdir is not supported")}},{}]},{},[1]);
\No newline at end of file