def renderer(template_path, build_path): template_path.join('.ignored1.html').write('Ignored 1') template_path.join('_partial1.html').write('Partial 1') template_path.join('template1.html').write('Test 1') template_path.join('template2.html').write('Test 2') template_path.mkdir('sub').join('template3.html').write('Test {{b}}') contexts = [('template2.html', lambda t: {'a': 1}), ('.*template3.html', lambda: {'b': 3}),] rules = [('template2.html', lambda env, t, a: None),] return make_renderer(searchpath=str(template_path), outpath=str(build_path), contexts=contexts, rules=rules)
def gen(start_server=False, debug=False): # Sass render_scss(debug) # Pages cachebuster_qs = cachebuster.gen_cachebuster_qs() for lang, context in data_contexts.iteritems(): context['printlog'] = _sp_printlog context['selectspeakers'] = _sp_selectspeakers context['cachebuster_qs'] = cachebuster_qs renderer = make_renderer(searchpath=SOURCE_DIR, staticpath=ASSET_DIR_REL, outpath=SITE_DIR, rules=[ ("[\w-]+\.html", render_page) ]) renderer.run(use_reloader=start_server)
def gen(start_server=False, debug=False): # Sass render_scss(debug) # Pages cachebuster_qs = cachebuster.gen_cachebuster_qs() for lang, context in data_contexts.iteritems(): context['printlog'] = _sp_printlog context['selectspeakers'] = _sp_selectspeakers context['cachebuster_qs'] = cachebuster_qs renderer = make_renderer(searchpath=SOURCE_DIR, staticpath=ASSET_DIR_REL, outpath=SITE_DIR, rules=[("[\w-]+\.html", render_page)]) renderer.run(use_reloader=start_server)
def main(): arguments = docopt(__doc__, version='staticjinja 0.3.0') if arguments['--srcpath'] is not None: srcpath = arguments['--srcpath'] else: srcpath = os.path.join(os.getcwd(), 'templates') if not os.path.isdir(srcpath): print("The templates directory '%s' is invalid." % srcpath) sys.exit(1) if arguments['--outpath'] is not None: outpath = arguments['--outpath'] else: outpath = os.getcwd() if not os.path.isdir(outpath): print("The output directory '%s' is invalid." % outpath) sys.exit(1) staticdir = arguments['--static'] staticpath = None if staticdir: staticpath = os.path.join(srcpath, staticdir) if staticpath and not os.path.isdir(staticpath): print("The static files directory '%s' is invalid." % staticpath) sys.exit(1) renderer = staticjinja.make_renderer( searchpath=srcpath, outpath=outpath, staticpath=staticdir ) use_reloader = arguments['watch'] renderer.run(use_reloader=use_reloader)
def renderer(template_path, build_path): template_path.join('.ignored1.html').write('Ignored 1') template_path.join('_partial1.html').write('Partial 1') template_path.join('template1.html').write('Test 1') template_path.join('template2.html').write('Test 2') template_path.mkdir('sub').join('template3.html').write('Test {{b}}') template_path.mkdir('fakestatic').join('hello.css').write( 'a { color: blue; }') contexts = [ ('template2.html', lambda t: { 'a': 1 }), ('.*template3.html', lambda: { 'b': 3 }), ] rules = [ ('template2.html', lambda env, t, a: None), ] return make_renderer(searchpath=str(template_path), outpath=str(build_path), contexts=contexts, rules=rules)
# Documents to append as an appendix to all manuals. #texinfo_appendices = [] # If false, no module index is generated. #texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. #texinfo_show_urls = 'footnote' ########NEW FILE######## __FILENAME__ = build import staticjinja if __name__ == "__main__": renderer = staticjinja.make_renderer() renderer.run() ########NEW FILE######## __FILENAME__ = staticjinja #-*- coding:utf-8 -*- """ Simple static page generator. Uses jinja2 to compile templates. """ from __future__ import absolute_import import inspect
import json from staticjinja import make_renderer def get_data(filename): with open(filename) as f: return json.loads(f.read()) def index_context(): return get_data("data/resume.json") if __name__ == "__main__": renderer = make_renderer( contexts=[ ('index.html', index_context), ], ) renderer.run()
import staticjinja if __name__ == "__main__": renderer = staticjinja.make_renderer() renderer.run()
# Documents to append as an appendix to all manuals. #texinfo_appendices = [] # If false, no module index is generated. #texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. #texinfo_show_urls = 'footnote' ########NEW FILE######## __FILENAME__ = build import staticjinja if __name__ == "__main__": renderer = staticjinja.make_renderer() renderer.run() ########NEW FILE######## __FILENAME__ = staticjinja #-*- coding:utf-8 -*- """ Simple static page generator. Uses jinja2 to compile templates. """ from __future__ import absolute_import import inspect import logging
def prune(d): if type(d) == list: rv = [] for x in d: y = prune(x) if y: rv.append(y) return rv elif type(d) == dict: rv = {} for k, v in d.iteritems(): y = prune(v) if y: rv[k] = y if len(rv) == 1 and "name" in rv: return {} else: return rv else: return d def get_catalogs(): with open('patterns.json') as f: return {'filenames': prune(json.loads(f.read()))} renderer = make_renderer(contexts=[ ("index.html", get_catalogs), ]) renderer.run()