Skip to content

Instantly share code, notes, and snippets.

@exallium
Created August 11, 2012 02:28
Show Gist options
  • Save exallium/3320060 to your computer and use it in GitHub Desktop.
Save exallium/3320060 to your computer and use it in GitHub Desktop.
CoffeeScript/Backbone Template Renderer with Caching, originally written in JS on github
class TemplateRenderer
constructor: (@directory='/static/templates', @cache={}) ->
render: (name, tmpl_data) ->
unless @cache[name]
url = @directory + '/' + name + '.html'
tmpl_string = null
$.ajax {
url: url,
method: 'GET',
async: false,
success: (data) ->
tmpl_string = data;
}
@cache[name] = _.template(tmpl_string)
@cache[name](tmpl_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment