Skip to content

Instantly share code, notes, and snippets.

@borismus
Created September 14, 2012 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save borismus/3723927 to your computer and use it in GitHub Desktop.
Save borismus/3723927 to your computer and use it in GitHub Desktop.
Ember handlebars template precompilation
#!/usr/bin/env python
import os
JS_FORMAT = """
Ember.TEMPLATES.%(name)s = Ember.Handlebars.compile('%(template)s');
"""
output = ''
# Get all templates with the name *.handlebars
for filename in os.listdir('.'):
if filename.endswith('.handlebars'):
name, extension = filename.split('.')
template = file(filename, 'r')
templateValue = template.read().replace('\n', '')
# For each template, generate JavaScript code according to the format.
output += JS_FORMAT % {'name': name, 'template': templateValue}
print output
@snanda85
Copy link

IMO, this is not exactly precompilation. The template will still need to be compiled in the browser without performance benefit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment