[Use templates for static files. Bryan O'Sullivan **20070916040944] { move ./web/index.complete.html ./web/index.complete.html.in hunk ./en/Makefile 166 - cp $< $@ + ../web/texpand.py $< $@ hunk ./en/Makefile 182 - cp $< $@ + ../web/texpand.py $< $@ hunk ./en/Makefile 195 - cp $< $@ + ../web/texpand.py $< $@ hunk ./en/Makefile 272 +vpath %.html.in ../web hunk ./web/index.complete.html.in 1 - - - - Real World Haskell - - - - - - + +{% extends "boilerplate.html" %} hunk ./web/index.complete.html.in 4 - - +{% block bodycontent %} + hunk ./web/index.complete.html.in 9 -
-

Table of Contents

- -
- -

Want to stay - up to date? Subscribe to comment feeds for any chapter (see - above), or - the entire book.

Copyright - 2007 Bryan O'Sullivan, Don Stewart, and John Goerzen. This - work is licensed under a Creative - Commons Attribution-Noncommercial 3.0 License. Icons by - Paul Davey aka Mattahan.

-
- - - - - +
+

Table of Contents

+ +
+{% endblock %} addfile ./web/texpand.py hunk ./web/texpand.py 1 +#!/usr/bin/env python +# +# Use Django's template machinery to expand static web pages. First +# tries the default template path for a particular installation, then +# looks for templates in the filesystem. + +from django.template import Context, TemplateDoesNotExist +from django.template.loader import get_template, get_template_from_string +from django.core.management import setup_environ +import rwh.settings as settings +import sys + +setup_environ(settings) +c = Context() + +if len(sys.argv) == 2: + in_name = sys.argv[1] + out_name = 'stdout' + out_fp = sys.stdout +elif len(sys.argv) == 3: + in_name = sys.argv[1] + out_name = sys.argv[2] + out_fp = None +else: + print >> sys.stderr, 'Usage: %s template-file [output-file]' + sys.exit(1) + +try: + t = get_template(in_name) +except TemplateDoesNotExist: + t = get_template_from_string(open(in_name).read(), name=in_name) +if out_fp is None: + out_fp = open(out_name, 'w') +out_fp.write(t.render(c)) +out_fp.close() }