Created
April 17, 2012 03:41
-
-
Save adambard/2403238 to your computer and use it in GitHub Desktop.
Create template.js
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 | |
""" | |
The filename is grandiose. All this does is find the files in the | |
web/templates/mustache directory, and dump them all into web/static/js/templates.js as | |
members of the window.templates object. | |
""" | |
import os | |
import re | |
import json | |
TEMPLATE_DIR = os.path.abspath("web/templates/mustache") | |
files = os.listdir(TEMPLATE_DIR) | |
first = True | |
templates = {} | |
for fn in files: | |
m = re.match(r"^(?P<varname>.*)\.mustache$", fn) | |
if m: | |
with open(os.path.join(TEMPLATE_DIR, fn), "rb") as f: | |
tmpl_str = f.read() | |
templates[m.group('varname')] = tmpl_str.replace("\n", " ") | |
with open("web/static/js/templates.js", "wb") as outfile: | |
outfile.write("window.templates = ") | |
outfile.write(json.dumps(templates)) | |
outfile.write(";") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment