]> projects.mako.cc - yourule/commitdiff
merged in jinja template move
author<mako@atdot.cc> <>
Sun, 16 Sep 2007 20:55:02 +0000 (16:55 -0400)
committer<mako@atdot.cc> <>
Sun, 16 Sep 2007 20:55:02 +0000 (16:55 -0400)
1  2 
yourule.py

diff --combined yourule.py
index c5ffdb7eeed914f187daf138d4cb31eee49c6dc4,9e933d667a8959610c8883962b37fbce15d9e9d6..3de9e7b4f03cd56323f730adf4fa1d0bbd37e6ca
@@@ -6,17 -6,25 +6,27 @@@ import sys, os, r
  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',
 +urls = ( '/?', 'index',
           '/ruler_([0-9\.]+)px_([0-9\.]+)([A-Za-z]+).(svg|png|jpg)', 'ruler_img',
           '/show/(.*(svg|png|jpg))', 'show_ruler',
           '/gallery(.*)', 'gallery',
           '/delete/(\d+)', 'delete',
           '/undelete/(\d+)', 'undelete')
  
 -database = create_database("sqlite:yourule.db")
 +database = create_database("sqlite:%s/db/yourule.db" %
 +                           os.path.dirname(__file__))
 +
  store = Store(database)
  
  class Ruler(object):
@@@ -57,8 -65,7 +67,7 @@@
  
  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()
@@@ -69,7 -76,7 +78,7 @@@
              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'], 
@@@ -79,7 -86,6 +88,6 @@@
  
  class show_ruler:
      def GET(self, ruler_url, ext):
-         web.debug('test test')
          if web.input().has_key('fromgallery'):
              fromgallery = True
          else:
@@@ -87,9 -93,7 +95,7 @@@
  
          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):
@@@ -129,7 -133,7 +135,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()
  
          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):
@@@ -211,8 -215,6 +217,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__":

Benjamin Mako Hill || Want to submit a patch?