function JTMLTemplate(template){this.template=((typeof(template)==="string")?template:template.html());this.compiledTemplate=this.compile(this.template)};JTMLTemplate.prototype={compile:function(markup){var self=this;var jsConstructs=[];var functionParts=["var __output = [];","var __o = 0;"];markup=markup.replace(new RegExp("[\\r\\n]+","g")," ");markup=markup.replace(new RegExp("<(/)?jtml:(\\w+)((?:[^>\"/]|\"[^\"]*\")*)/?>","g"),function($0,$1,$2,$3){if($1){jsConstructs.push(self.convertCloseTag($2))}else{jsConstructs.push(self.convertOpenTag($2,$3))}return("__t"+(jsConstructs.length-1)+"__")});markup.replace(new RegExp("^(.+)$","gm"),function($0,$1){var line=$1.replace(new RegExp("(\")","g"),"\\$1");line=line.replace(new RegExp("\\$\\{([^}]+)\\}","g"),function($0,$1){return("\" + ( "+$1+" ) + \"")});line=line.replace(new RegExp("__t(\\d+)__","g"),function($0,$1){return("\"; "+jsConstructs[parseInt($1)]+"; __output[ __o++ ] = \"")});functionParts.push("__output[ __o++ ] = \""+line+"\";")});functionParts.push("return( __output.join( \"\\n\" ) );");return(functionParts.join("\n"))},convertCloseTag:function(tag){switch(tag){case"if":return(" } ");break;case"loop":return(" } ");break;default:return("/* Unknown CLOSE */");break}},convertOpenTag:function(tag,metaData){var attributes=this.parseMetaData(metaData);switch(tag){case"else":if("test"in attributes){return(" } else if ( "+attributes.test+" ){ ")}else{return(" } else { ")}break;case"if":return(" if ( "+attributes.test+" ){ ");break;case"include":return("__output[ __o++ ] = (function(){ "+this.compile($(attributes.template).html())+" })();");break;case"loop":if(attributes.collection){if(this.isArray(attributes.collection)){return(" for ( var __"+attributes.index+" = 0 ; __"+attributes.index+" < "+attributes.collection+".length ; __"+attributes.index+"++ ) { "+(("key"in attributes)?("var "+attributes.key+" = __"+attributes.index+";"):"")+"var "+attributes.index+" = "+attributes.collection+"[ __"+attributes.index+" ];")}else{return(" for ( var __"+attributes.index+" in "+attributes.collection+" ) { "+(("key"in attributes)?("var "+attributes.key+" = __"+attributes.index+";"):"")+"var "+attributes.index+" = "+attributes.collection+"[ __"+attributes.index+" ];")}}else{return(" for ( var __"+attributes.index+" = "+(attributes.from||0)+" ; __"+attributes.index+" <= "+attributes.to+" ; __"+attributes.index+"+="+(attributes.step||1)+" ) { "+"var "+attributes.index+" = __"+attributes.index+";")}break;default:return("/* Unknown OPEN */");break}},isArray:function(object){return($.isArray(object))},parseMetaData:function(metaData){var attributes={};metaData.replace(new RegExp("(\\w+)\\s*=\\s*\"([^\"]*)\"","g"),function($0,$1,$2){attributes[$1]=$2});return(attributes)},render:function(map){var functionParts=[];var f=0;for(var key in map){functionParts[f++]=("var "+key+" = _map[ \""+key+"\" ];")}functionParts[f++]=("return( (function(){ "+this.compiledTemplate+" })() );");var renderFunction=new Function("_map",functionParts.join("\n"));return(renderFunction(map))}};