1234567891011121314151617181920212223242526272829 |
- function InstallDots(t){this.__path=t.path||"./","/"!==this.__path[this.__path.length-1]&&(this.__path+="/"),this.__destination=t.destination||this.__path,"/"!==this.__destination[this.__destination.length-1]&&(this.__destination+="/"),this.__global=t.global||"window.render",this.__rendermodule=t.rendermodule||{},this.__settings=Object.prototype.hasOwnProperty.call(t,"templateSettings")?copy(t.templateSettings,copy(doT.templateSettings)):void 0,this.__includes={}}function addexports(t){for(var e="",o=0;o<t.length;o++)e+="itself."+t[o]+"="+t[o]+";";return e}function copy(t,e){e=e||{};for(var o in t)e[o]=t[o];return e}function readdata(t){var e=fs.readFileSync(t);return e?e.toString():void console.log("problems with "+t)}var fs=require("fs"),doT=module.exports=require("./doT");doT.process=function(t){return new InstallDots(t).compileAll()},InstallDots.prototype.compileToFile=function(t,e,o){o=o||{};var i,n=t.substring(t.lastIndexOf("/")+1,t.lastIndexOf(".")),s=copy(this.__includes,copy(o)),l=this.__settings||doT.templateSettings,d=copy(l),r=doT.template(e,l,s),a=[],p="";for(var _ in s)s[_]!==o[_]&&s[_]!==this.__includes[_]&&(i=void 0,"string"==typeof s[_]?i=doT.template(s[_],l,s):"function"==typeof s[_]?i=s[_]:s[_].arg&&(d.varname=s[_].arg,i=doT.template(s[_].text,d,s)),i&&(p+=i.toString().replace("anonymous",_),a.push(_)));p+=r.toString().replace("anonymous",n),fs.writeFileSync(t,"(function(){"+p+"var itself="+n+", _encodeHTML=("+doT.encodeHTMLSource.toString()+"("+(l.doNotSkipEncoded||"")+"));"+addexports(a)+"if(typeof module!=='undefined' && module.exports) module.exports=itself;else if(typeof define==='function')define(function(){return itself;});else {"+this.__global+"="+this.__global+"||{};"+this.__global+"['"+n+"']=itself;}}());")},InstallDots.prototype.compilePath=function(t){var e=readdata(t);return e?doT.template(e,this.__settings||doT.templateSettings,copy(this.__includes)):void 0},InstallDots.prototype.compileAll=function(){doT.log&&console.log("Compiling all doT templates...");var t,e,o,i=this.__path,n=fs.readdirSync(i);for(t=0,e=n.length;e>t;t++)o=n[t],/\.def(\.dot|\.jst)?$/.test(o)&&(doT.log&&console.log("Loaded def "+o),this.__includes[o.substring(0,o.indexOf("."))]=readdata(i+o));for(t=0,e=n.length;e>t;t++)o=n[t],/\.dot(\.def|\.jst)?$/.test(o)&&(doT.log&&console.log("Compiling "+o+" to function"),this.__rendermodule[o.substring(0,o.indexOf("."))]=this.compilePath(i+o)),/\.jst(\.dot|\.def)?$/.test(o)&&(doT.log&&console.log("Compiling "+o+" to file"),this.compileToFile(this.__destination+o.substring(0,o.indexOf("."))+".js",readdata(i+o)));return this.__rendermodule};
|