Jakub Zalewski avatar Jakub Zalewski committed 532a9f8

Squashed commit of the following:

commit cd0b4320b695de4b99c6b0a5e7e6551ad5cd749f
Author: Jakub Zalewski <zalew7@gmail.com>;
Date: Sun Sep 23 16:52:41 2012 +0200

new functionality readme

commit 54c2cc979191188c3613770a408059cbe3fc2e5e
Author: Jakub Zalewski <zalew7@gmail.com>;
Date: Sun Sep 23 16:47:00 2012 +0200

autodiscover all templates except starting with _

commit 41db990763178a836531745c036541be56bc357a
Author: Jakub Zalewski <zalew7@gmail.com>;
Date: Sun Sep 23 16:38:18 2012 +0200

basic haml support

Comments (0)

Files changed (3)

 Requirements
 ------------
 
+pip install requirements.txt
+
 * jinja2 (`pip install jinja2`)
+* [hamlish-jinja](https://github.com/Pitmairen/hamlish-jinja) for [haml](http://haml.info/) support
 * (optional, for automatic compilation) watchdog (`pip install watchdog`)
 
 Setup
 -----
 
-To compile the templates run `python build.py`. This will look execute the `main` function in `build.py` (which is set by default to build the `index.html` file inside of `./templates`).
+To compile the templates run `python build.py`. This will look execute the `main` function in `build.py` (looks for every file inside `./templates` not starting with `_`).
 
-To compile additional pages, you will need to add more functions specifying how to compile each page. For pages which are loading any data, and therefore don't require a context, adding the line `build_template(env, 'mypage.html')` to `main` is sufficient. For pages which require a context of some sort, you will need to write a custom function that `main` calls, passing context data as extra arguments to `build_template`.
+For pages which require a context of some sort, you will need to write a custom function that `main` calls, passing context data as extra arguments to `build_template`.
 
 Automatic Compilation
 ---------------------
 Uses jinja2 to compile templates.
 Templates should live inside `./templates` and will be compiled in '.'.
 """
+from hamlish_jinja import HamlishExtension
+from jinja2 import Environment, FileSystemLoader
+from jinja2.exceptions import TemplateNotFound
 import csv
+import os
 import sys
 
-from jinja2 import Environment, FileSystemLoader
-
 
 def build_template(env, template_name, **kwargs):
     """Compile a template.
     *   kwargs should be a series of key-value pairs. These items will be
         passed to the template to be used as needed.
     """
+    name, ext = os.path.splitext(template_name)
     print "Building %s..." % template_name
     template = env.get_template(template_name)
-    with open(template_name, "w") as f:
+    output_name = '%s.html' % name
+    with open(output_name, "w") as f:
         f.write(template.render(**kwargs))
 
 
 
 def main():
     """Compile each of the templates."""
-    env = Environment(loader=FileSystemLoader(searchpath="./templates"))
+    path = "./templates"
+    env = Environment(loader=FileSystemLoader(searchpath=path), extensions=[HamlishExtension])
 
     # Add any instructions to build templates here
-    build_template(env, 'index.html')
-
+    files = os.listdir(path)
+    for file in files:
+        if not file.startswith('_'):
+            build_template(env, file)
     print "Templates built."
     return 0
 
 Jinja2==2.5.2
+Hamlish-Jinja==0.2.0
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.