From: Date: Sun, 16 Sep 2007 21:33:59 +0000 (-0400) Subject: moved templating system to jinja X-Git-Url: https://projects.mako.cc/source/yourule/commitdiff_plain/ba471ef56c488ae95dac054033c81a3541cda71c moved templating system to jinja --- diff --git a/templates/_form_elements.tmpl b/templates/_form_elements.tmpl index b365ce0..001617b 100644 --- a/templates/_form_elements.tmpl +++ b/templates/_form_elements.tmpl @@ -1,15 +1,15 @@

-

+

-

+

+ You Rule
@@ -13,10 +14,8 @@
- -#filter Filter -$body -#end filter + <% block body %> + <% endblock %>
diff --git a/yourule.py b/yourule.py index 108cce3..9e933d6 100755 --- a/yourule.py +++ b/yourule.py @@ -6,6 +6,16 @@ import sys, os, re from storm.locals import * from svgruler import SVGRuler +from jinja import Environment, FileSystemLoader +jinja_env = Environment('<%', '%>', '<%=', '%>', '<%#', '%>', + loader=FileSystemLoader('templates/')) + +def render(filename, vars): + web.header("Content-Type","text/html; charset=utf-8") + tmpl = jinja_env.get_template(filename + '.tmpl') + print tmpl.render(vars) + web.debug(web.ctx) + # the url map for the application urls = ( '/', 'index', '/ruler_([0-9\.]+)px_([0-9\.]+)([A-Za-z]+).(svg|png|jpg)', 'ruler_img', @@ -55,8 +65,7 @@ class Ruler(object): class index: def GET(self): - web.header("Content-Type","text/html; charset=utf-8") - web.render('index.tmpl') + render('index', locals()) def POST(self): input = web.input() @@ -67,7 +76,7 @@ class index: pixel_width = input['pixel_width'] unit_width = input['unit_width'] units = input['units'] - web.render('index.tmpl') + render('index', locals()) else: ruler = Ruler(pixel_width = input['pixel_width'], unit_width = input['unit_width'], @@ -77,7 +86,6 @@ class index: class show_ruler: def GET(self, ruler_url, ext): - web.debug('test test') if web.input().has_key('fromgallery'): fromgallery = True else: @@ -85,9 +93,7 @@ class show_ruler: other_unit, other_unit_url = get_other_unit(ruler_url) - web.header("Content-Type","text/html; charset=utf-8") - web.render('show_ruler.tmpl') - + render('show_ruler', locals()) class ruler_img: def GET(self, pixel_width=None, unit_width=None, units=None, ext=None): @@ -127,7 +133,7 @@ class gallery: rulers = store.find(Ruler, Ruler.show == 1) rulers.order_by(Ruler.model) - web.render('gallery.tmpl') + render('gallery', locals()) def POST(self, ruler_url): input = web.input() @@ -152,7 +158,7 @@ class gallery: rulers = store.find(Ruler, Ruler.show == 1) rulers.order_by(Ruler.model) - web.render('gallery.tmpl') + render('gallery', locals()) class delete: def GET(self, id): @@ -209,8 +215,6 @@ def validate_input(input): return(errormsg) -# render the site template here so that i can use it later -web.render('site.tmpl', None, True, 'site') web.webapi.internalerror = web.debugerror if __name__ == "__main__":