-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbase2-jst-p.js
9 lines (8 loc) · 2.23 KB
/
base2-jst-p.js
1
2
3
4
5
6
7
8
9
/*
base2 - copyright 2007-2009, Dean Edwards
http://code.google.com/p/base2/
http://www.opensource.org/licenses/mit-license.php
Contributors:
Doeke Zanstra
*/
new function(_3){var jst=new base2.Package(this,{name:"jst",version:base2.version,exports:"Command,Environment,Interpreter,Parser"});eval(this.imports);var STDOUT=1;var Command=Base.extend({constructor:function(a){this[STDOUT]=[];this.extend(a)},echo:function(a){this[STDOUT].push(a)},toString:function(){return this[STDOUT].join("")}});var Environment=Base.extend({set:function(a,c){this[a]=c},unset:function(a){delete this[a]}});var Interpreter=Base.extend({constructor:function(a,c){this.command=a||{};this.environment=new Environment(c);this.parser=new Parser},command:null,environment:null,parser:null,interpret:function(a){var c=new Command(this.command);var b=base2.namespace+js.namespace+lang.namespace+"\nwith(arguments[0])with(arguments[1]){\n"+this.parser.parse(a)+"}\nreturn arguments[0].toString()";return new Function(b)(c,this.environment)}});var Escape=Module.extend({escape:function(c,b){if(c.escapeChar){var d=new RegExp(rescape(c.escapeChar+"."),"g");b=b.replace(d,function(a){return String.fromCharCode(Escape.BASE+a.charCodeAt(1))})}return b},unescape:function(c,b){if(c.escapeChar){b=b.replace(Escape.RANGE,function(a){return c.escapeChar+String.fromCharCode(a.charCodeAt(0)-Escape.BASE)})}return b}},{BASE:65280,RANGE:/[\uff00-\uffff]/g});var Parser=Base.extend({escapeChar:"\\",parse:function(a){return this._1(this._2(String(a)))},_1:function(b){var d=this._0;while(Parser.EVALUATED.test(b)){b=b.replace(Parser.EVALUATED,function(a,c){return d[c]})}delete this._0;return this.unescape(b)},_2:function(b){var d=/^=|;+$/g,f=/<%[^%]*%([^>][^%]*%)*>/g,e=this._0=[];var g=function(a){a=a.replace(Parser.TRIM,"");if(!a)return"";if(a.indexOf("=")==0){a="\necho("+a.replace(d,"")+");"}var c="\x01"+e.length+"\x01";e.push(a);return c};return Parser.TEXT.exec(this.escape(b).replace(f,g))}},{ESCAPE:new RegGrp({'\\\\':'\\\\','"':'\\"','\\n':'\\n','\\r':'\\r'}),EVALUATED:/\x01(\d+)\x01/g,TEXT:new RegGrp({"\\x01\\d+\\x01":RegGrp.IGNORE,"[^\\x01]+":function(a){return'\necho("'+Parser.ESCAPE.exec(a)+'");'}}),TRIM:/^<%\-\-.*\-\-%>$|^<%\s*|\s*%>$/g});Parser.implement(Escape);eval(this.exports)};