/**
 * @class Jaml
 * @author Ed Spencer (http://edspencer.net)
 * Jaml is a simple JavaScript library which makes HTML generation easy and pleasurable.
 * Examples: http://edspencer.github.com/jaml
 * Introduction: http://edspencer.net/2009/11/jaml-beautiful-html-generation-for-javascript.html
 */
Jaml=function(){return{automaticScope:!0,templates:{},helpers:{},register:function(a,b){this.templates[a]=b},render:function(a,b){var c=this.templates[a],d=new Jaml.Template(c);return d.render(b)},registerHelper:function(a,b){this.helpers[a]=b,Jaml.Template.prototype[a]=b}}}(),Jaml.Node=function(a){this.tagName=a,this.attributes={},this.children=[]},Jaml.Node.prototype={setAttributes:function(a){for(var b in a){var c=b=="cls"?"class":b;this.attributes[c]=a[b]}},addChild:function(a){this.children.push(a)},render:function(a){a=a||0;var b=[],c=this instanceof Jaml.TextNode,d=this.multiLineTag();c||b.push(this.getPadding(a)),b.push("<"+this.tagName);for(var e in this.attributes)b.push(" "+e+'="'+this.attributes[e]+'"');if(this.isSelfClosing())b.push(" />\n");else{b.push(">"),d&&b.push("\n");for(var f=0;f<this.children.length;f++)b.push(this.children[f].render(a+2));d&&b.push(this.getPadding(a)),b.push("</",this.tagName,">\n")}return b.join("")},multiLineTag:function(){var a=this.children.length,b=a>0;return a==1&&this.children[0]instanceof Jaml.TextNode&&(b=!1),b},getPadding:function(a){return(new Array(a+1)).join(" ")},isSelfClosing:function(){var a=!1;for(var b=this.selfClosingTags.length-1;b>=0;b--)this.tagName==this.selfClosingTags[b]&&(a=!0);return a},selfClosingTags:["area","base","basefont","br","col","frame","hr","img","input","isindex","link","meta","param"]},Jaml.TextNode=function(a){this.text=a},Jaml.TextNode.prototype={render:function(){return this.text}},Jaml.Template=function(a){this.tpl=a,this.nodes=[]},Jaml.Template.prototype={render:function(data){data=data||{},data.constructor.toString().indexOf("Array")==-1&&(data=[data]);if(Jaml.automaticScope)with(this)for(var i=0;i<data.length;i++)eval("("+this.tpl.toString()+")(data[i], i)");else for(var i=0;i<data.length;i++)this.tpl.call(this,data[i],i);var roots=this.getRoots(),output="";for(var i=0;i<roots.length;i++)output+=roots[i].render();return output},getRoots:function(){var a=[];for(var b=0;b<this.nodes.length;b++){var c=this.nodes[b];c.parent==undefined&&a.push(c)}return a},tags:["html","head","body","script","meta","title","link","script","div","p","span","a","img","br","hr","table","tr","th","td","thead","tbody","ul","ol","li","dl","dt","dd","h1","h2","h3","h4","h5","h6","h7","form","input","label"]},function(){function b(a){return function(b){var c=new Jaml.Node(a),d=typeof b=="object"&&!(b instanceof Jaml.Node)&&!(b instanceof Jaml.TextNode);d&&c.setAttributes(b);var e=d?1:0;for(var f=e;f<arguments.length;f++){var g=arguments[f];if(typeof g=="string"||g==undefined)g=new Jaml.TextNode(g||"");if(g instanceof Jaml.Node||g instanceof Jaml.TextNode)g.parent=c;c.addChild(g)}return this.nodes.push(c),c}}var a=Jaml.Template.prototype.tags;for(var c=a.length-1;c>=0;c--){var d=a[c];Jaml.Template.prototype[d]=b(d)}}()
