Created
September 14, 2012 18:55
-
-
Save borismus/3723927 to your computer and use it in GitHub Desktop.
Ember handlebars template precompilation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IMO, this is not exactly precompilation. The template will still need to be compiled in the browser without performance benefit.