
YAHOO.namespace("ea.sp");YAHOO.ea.sp.Template=function()
{this.templates=new Object();};YAHOO.ea.sp.Template.prototype={VARIABLE_PATTERN:new RegExp("(!?)\\{([^\\}]*)\\}","gm"),SECTION_PATTERN:new RegExp("^(\\S+):$","gm"),templates:null,render:function(name,variables)
{var template=this.templates[name];if(template!=null)
{for(var i=1;i<template.variables.length;i+=2)
{var rendered=template.variables[i](variables,this);template.content[i]=rendered==null?'':rendered;}
return template.content.join('');}
else
return"";},renderAll:function(name,objects,join)
{var result=new Array();for(var i=0;i<objects.length;i++)
result[i]=this.render(name,objects[i]);return result.join(join!=null?join:'');},parseSections:function(sections)
{this.SECTION_PATTERN.lastIndex=0;var lastIndex=0;var name=null;var result=null;while((result=this.SECTION_PATTERN.exec(sections))!=null)
{if(name!=null)
this.parseString(name,this.trim(sections.substring(lastIndex,result.index)));name=result[1];lastIndex=this.SECTION_PATTERN.lastIndex;}
if(name!=null)
this.parseString(name,this.trim(sections.substring(lastIndex)));},parseString:function(templateName,templateString)
{var content=new Array();var variables=new Array();this.VARIABLE_PATTERN.lastIndex=0;var lastIndex=0;while((match=this.VARIABLE_PATTERN.exec(templateString))!=null)
{content.push(templateString.substring(lastIndex,match.index));content.push(null);variables.push(null);if(match[1])
variables.push(eval('new Function("o","t","return '+match[2].replace('"','\\"')+'")'))
else
variables.push(eval('new Function("o","t","return o[\''+match[2].replace('"','\\"')+'\'];")'))
lastIndex=this.VARIABLE_PATTERN.lastIndex;}
content.push(templateString.substring(lastIndex));this.templates[templateName]={content:content,variables:variables};},trim:function(str)
{return str.replace(/^\s*(\S*(\s+\S+)*)\s*$/,"$1");}}