(function($) { // Simple JavaScript Templating // John Resig - http://ejohn.org/ - MIT Licensed // adapted from: http://ejohn.org/blog/javascript-micro-templating/ // originally $.srender by Greg Borenstein http://ideasfordozens.com in Feb 2009 // modified for Sammy by Aaron Quint for caching templates by name var srender_cache = {}; var srender = function(name, template, data) { // target is an optional element; if provided, the result will be inserted into it // otherwise the result will simply be returned to the caller if (srender_cache[name]) { fn = srender_cache[name]; } else { if (typeof template == 'undefined') { // was a cache check, return false return false; } // Generate a reusable function that will serve as a template // generator (and which will be cached). fn = srender_cache[name] = new Function("obj", "var p=[],print=function(){p.push.apply(p,arguments);};" + // Introduce the data as local variables using with(){} "with(obj){p.push(\"" + // Convert the template into pure JavaScript template .replace(/[\r\t\n]/g, " ") .replace(/\"/g, '\\"') .split("<%").join("\t") .replace(/((^|%>)[^\t]*)/g, "$1\r") .replace(/\t=(.*?)%>/g, "\",$1,\"") .split("\t").join("\");") .split("%>").join("p.push(\"") .split("\r").join("") + "\");}return p.join('');"); } if (typeof data != 'undefined') { return fn(data); } else { return fn; } }; Sammy = Sammy || {}; // Sammy.Template is a simple plugin that provides a way to create // and render client side templates. The rendering code is based on John Resig's // quick templates and Greg Borenstien's srender plugin. // This is also a great template/boilerplate for Sammy plugins. // // Templates use <% %> tags to denote embedded javascript. // // ### Examples // // Here is an example template (user.template): // //