// -- Sammy -- /plugins/sammy.haml.js
// http://code.quirkey.com/sammy
// Version: 0.5.4
// Built: Thu Apr 29 19:30:54 -0400 2010
(function(c){var b,e,i;function d(l){return(l+"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;")}function j(p){var m,n,l=[];for(m in p){if(m!=="content"&&p.hasOwnProperty(m)){switch(p[m]){case"undefined":case"false":case"null":case'""':break;default:try{n=JSON.parse("["+p[m]+"]")[0];if(n===true){n=m}else{if(typeof n==="string"&&i.test(n)){n='" +\n'+a(d(n))+' +\n"'}else{n=d(n)}}l.push(" "+m+'=\\"'+n+'\\"')}catch(o){l.push(" "+m+'=\\"" + html_escape('+p[m]+') + "\\"')}}}}return l.join("")}function f(z){var r={},p=z.length,s,w,u=1,m=false,x=false,t,y,o,v,q={start:1,middle:null,end:null};if(!(p>0&&(z.charAt(0)==="{"||z.charAt(0)==="("))){return{content:z[0]===" "?z.substr(1,p):z}}t=z.charAt(0);y=(t==="{")?"}":")";o=(t==="{")?":":"=";v=(t==="{")?",":" ";function n(){if(typeof q.start==="number"&&typeof q.middle==="number"&&typeof q.end==="number"){var l=z.substr(q.start,q.middle-q.start).trim(),A=z.substr(q.middle+1,q.end-q.middle-1).trim();r[l]=A}q={start:null,middle:null,end:null}}for(s=1;u>0;s+=1){if(s>p){throw"Malformed attribute block"}w=z.charAt(s);if(x){x=false}else{if(m){if(w==="\\"){x=true}if(w===m){m=false}}else{if(w==='"'||w==="'"){m=w}if(u===1){if(w===o){q.middle=s}if(w===v||w===y){q.end=s;n();if(w===v){q.start=s+1}}}if(w===t){u+=1}if(w===y){u-=1}}}}r.content=z.substr(s,z.length);return r}function a(o){var l=[],p=0,n=0,m;while(true){n=o.substr(p).search(i);if(n<0){if(p<o.length){l.push(JSON.stringify(o.substr(p)))}break}l.push(JSON.stringify(o.substr(p,n)));p+=n;m=o.substr(p).match(i);n=m[0].length;if(n<0){break}l.push(m[1]||m[2]);p+=n}return l.filter(function(q){return q&&q.length>0}).join(" +\n")}i=/\#\{([^}]*)\}/;e=["meta","img","link","br","hr","input","area","base"];b=[{regexp:/^(\s*)((?:[.#%][a-z_\-][a-z0-9_\-]*)+)(.*)$/i,process:function(){var l,m,n,q,o;l=this.matches[2];m=l.match(/\.([a-z_\-][a-z0-9_\-]*)/gi);n=l.match(/\#([a-z_\-][a-z0-9_\-]*)/gi);l=l.match(/\%([a-z_\-][a-z0-9_\-]*)/gi);l=l?l[0].substr(1,l[0].length):"div";q=this.matches[3];if(q){q=f(q);if(q.content){this.contents.unshift(q.content.trim());delete (q.content)}}else{q={}}if(m){m=m.map(function(r){return r.substr(1,r.length)}).join(" ");if(q["class"]){try{q["class"]=JSON.stringify(m+" "+JSON.parse(q["class"]))}catch(p){q["class"]=JSON.stringify(m+" ")+" + "+q["class"]}}else{q["class"]=JSON.stringify(m)}}if(n){n=n.map(function(r){return r.substr(1,r.length)}).join(" ");if(q.id){q.id=JSON.stringify(n+" ")+q.id}else{q.id=JSON.stringify(n)}}q=j(q);o=this.render_contents();if(o==='""'){o=""}if(e.indexOf(l)==-1){return'"<'+l+q+'>"'+(o.length>0?" + \n"+o:"")+' + \n"</'+l+'>"'}else{return'"<'+l+q+' />"'}}},{regexp:/^(\s*)(?::for|:each)\s+(?:([a-z_][a-z_\-]*),\s*)?([a-z_][a-z_\-]*)\s+in\s+(.*)(\s*)$/i,process:function(){var n=this.matches[2]||"__key__",l=this.matches[3],o=this.matches[4],m="__result__";if(this.matches[5]){this.contents.unshift(this.matches[5])}return"(function () { var "+m+" = [], "+n+", "+l+"; for ("+n+" in "+o+") { if ("+o+".hasOwnProperty("+n+")) { "+l+" = "+o+"["+n+"]; "+m+".push(\n"+(this.render_contents()||"''")+"\n); } } return "+m+'.join(""); }).call(this)'}},{regexp:/^(\s*):if\s+(.*)\s*$/i,process:function(){var l=this.matches[2];return"(function () { if ("+l+") { return (\n"+(this.render_contents()||"")+'\n);} else { return ""; } }).call(this)'}},{regexp:/^()!!!(?:\s*(.*))\s*$/,process:function(){var l="";switch((this.matches[2]||"").toLowerCase()){case"":l='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';break;case"strict":case"1.0":l='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';break;case"frameset":l='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">';break;case"5":l="<!DOCTYPE html>";break;case"1.1":l='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';break;case"basic":l='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">';break;case"mobile":l='<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">';break;case"xml":l="<?xml version='1.0' encoding='utf-8' ?>";break;case"xml iso-8859-1":l="<?xml version='1.0' encoding='iso-8859-1' ?>";break}return JSON.stringify(l+"\n")}},{regexp:/^(\s*):markdown\s*$/i,process:function(){return a(exports.Markdown.encode(this.contents.join("\n")))}},{regexp:/^(\s*):(?:java)?script\s*$/,process:function(){return a('\n<script type="text/javascript">\n//<![CDATA[\n'+this.contents.join("\n")+"\n//]]>\n<\/script>\n")}},{regexp:/^(\s*):css\s*$/,process:function(){return JSON.stringify('\n<style type="text/css">\n'+this.contents.join("\n")+"\n</style>\n")}},];function k(l){var n=false,m=[];if(typeof l==="string"){l=l.trim().split("\n")}l.forEach(function(o){var p,q=false;if(n){p=n.check_indent(o);if(p){n.contents.push(p[1]||"");return}else{m.push(n.process());n=false}}b.forEach(function(r){if(!q){p=r.regexp(o);if(p){n={contents:[],matches:p,check_indent:new RegExp("^(?:\\s*|"+p[1]+"  (.*))$"),process:r.process,render_contents:function(){return k(this.contents)}};q=true}}});if(!q){m.push(function(){if(o[0]==="\\"){return a(o.substr(1,o.length))}if(o[0]==="="){o=o.substr(1,o.length).trim();try{return a(JSON.parse(o))}catch(s){return o}}if(o.substr(0,2)==="&="){o=o.substr(2,o.length).trim();try{return JSON.stringify(d(JSON.parse(o)))}catch(r){return"html_escape("+o+")"}}return a(o)}())}});if(n){m.push(n.process())}return m.filter(function(o){return o&&o.length>0}).join(" +\n")}function h(q){var m=[],o=[],p,n;function l(){if(o.length>0){m.push(JSON.stringify(o.join(""))+n);o=[]}}q.split("\n").forEach(function(r){p=r.match(/^(\".*\")(\s*\+\s*)?$/);if(!p){l();m.push(r);return}n=p[2]||"";p=p[1];try{o.push(JSON.parse(p))}catch(s){l();m.push(r)}});l();return m.join("\n")}function g(l){var m=h(k(l));return new Function("locals",d+"\nwith(locals || {}) {\n  try {\n    return ("+m+');\n  } catch (e) {\n    return "\\n<pre class=\'error\'>" + html_escape(e.stack) + "</pre>\\n";\n  }\n}')}Sammy=Sammy||{};Sammy.Haml=function(o,m){o.use(Sammy.JSON);var n={};var l=function(r,s,p){if(typeof p=="undefined"){p=r}var q=n[p];if(!q){q=n[p]=g(r)}return q(c.extend({},this,s))};if(!m){m="haml"}o.helper(m,l)}})(jQuery);
