Skip to content

Commit

Permalink
simple mustache template tool
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Feb 26, 2015
1 parent 75b6459 commit d98e19f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
5 changes: 3 additions & 2 deletions build/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .collect import collectjson
from .setversion import setversion
from .appcache import appcache
from .compilers import optimize, scss
from .compilers import optimize, scss, mustache
from .init import init


Expand All @@ -19,6 +19,7 @@ class Builder(object):
'init': init,
'collectjson': collectjson,
'scss': scss,
'mustache': mustache,
}

def __init__(self, version=None, config="wq.yml"):
Expand Down Expand Up @@ -52,7 +53,7 @@ def build(self):
if 'setversion' in self.conf or self.version != "":
self.setversion()

for command in ('init', 'collectjson', 'scss'):
for command in ('init', 'collectjson', 'scss', 'mustache'):
if command in self.conf:
self.run(command)

Expand Down
27 changes: 27 additions & 0 deletions build/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,30 @@ def compile(path, source):
path = "%s/%s.css" % (conf['outdir'], name)
compile(path, source)
print("%s compiled from %s/%s.scss" % (path, conf['indir'], name))


def mustache(conf, indir=None):
import pystache
template = conf.get("template", None)
if template is None:
return
if os.sep in template or template.endswith(".html"):
template = open(template).read()

context = conf.get("context", {})
if not isinstance(context, dict):
path = context
context = readfiles(path, "yaml", "yml")
context.update(**readfiles(path, "json"))

partials = conf.get("partials", {})
if not isinstance(partials, dict):
partials = readfiles(partials, "html")

output = conf.get("output", "output.html")
print("Generating %s from %s" % (output, conf['template']))
renderer = pystache.Renderer(partials=partials)
html = renderer.render(template, context)
f = open(output, 'w')
f.write(html)
f.close()
1 change: 1 addition & 0 deletions build/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def usage():
build
collectjson
init
mustache
optimize
scss
setversion
Expand Down

0 comments on commit d98e19f

Please sign in to comment.