diff --git a/build/builder.py b/build/builder.py index 64c4133a..e07b8b03 100644 --- a/build/builder.py +++ b/build/builder.py @@ -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 @@ -19,6 +19,7 @@ class Builder(object): 'init': init, 'collectjson': collectjson, 'scss': scss, + 'mustache': mustache, } def __init__(self, version=None, config="wq.yml"): @@ -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) diff --git a/build/compilers.py b/build/compilers.py index 8dc88446..2120baf9 100644 --- a/build/compilers.py +++ b/build/compilers.py @@ -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() diff --git a/build/tool.py b/build/tool.py index ada1ef73..f592a22b 100644 --- a/build/tool.py +++ b/build/tool.py @@ -12,6 +12,7 @@ def usage(): build collectjson init + mustache optimize scss setversion