<p><label for="units">Units:</label>
<select id="unitselector" name="units">
-<option values="centimeters"#if $getVar('units', '') == 'centimeters'# selected="selected"'#end if#>centimeters</option>
-<option value="inches"#if $getVar('units', '') == 'inches'# selected="selected"'#end if#>inches</option>
+<option values="centimeters"<% if units == 'centimeters' %>selected="selected"<% endif %>>centimeters</option>
+<option value="inches"<% if units == 'inches' %>selected="selected"<% endif %>>inches</option>
</select>
</p>
<p><label for="pixel_width">Screen width (in pixels):</label>
-<input type="text" name="pixel_width" value="$getVar('pixel_width', None)" /></p>
+<input type="text" name="pixel_width" value="<%= pixel_width %>" /></p>
<p><label for="unit_width"><em>Horizontal</em> screen width (in <span class="unittext">units</span>):</label>
-<input type="text" name="unit_width" value="$getVar('unit_width', None)" /></p>
+<input type="text" name="unit_width" value="<%= unit_width %>" /></p>
<script>
// simple chunk of javascript to handle changes
-#extends site
+<% extends 'site.tmpl' %>
-#block body
+<% block body %>
<h2>Gallery of Existing Rulers</h2>
<th>Rulers</th>
<th></th>
</tr>
-#for $ruler in $rulers
+<% for ruler in rulers %>
<tr>
- <td>$ruler.model</td>
- <td>$ruler.pixel_width</td>
- <td>$ruler.cm_width()/$ruler.in_width</td>
+ <td><%= ruler.model%></td>
+ <td><%= ruler.pixel_width %></td>
+ <td><%= ruler.cm_width() %>/<%= ruler.in_width() %></td>
<td>
- <a href="/show/ruler_${ruler.pixel_width}px_${ruler.cm_width}centimeters.png?fromgallery=true">cm</a>/<a href="/show/ruler_${ruler.pixel_width}px_${ruler.in_width}inches.png?fromgallery=true">in</a>
+ <a href="/show/ruler_<%= ruler.pixel_width %>px_<%= ruler.cm_width() %>centimeters.png?fromgallery=true">cm</a>/<a href="/show/ruler_<%= ruler.pixel_width %>px_<%= ruler.in_width() %>inches.png?fromgallery=true">in</a>
</td>
- <td><form method="GET" action="delete/$ruler.id" style="display:inline;">
+ <td><form method="GET" action="delete/<%= ruler.id %>" style="display:inline;">
<input type="submit" value="delete" /></form></td>
</tr>
-#end for
+<% endfor %>
</table>
<h2>Add Your Ruler</h2>
<p>If your ruler is not on the list you should add it with the box
form.</p>
-#if $getVar('errormsg', False)
+<% if errormsg %>
<div class="errormsg">
<strong>Error</strong><br />
-$getVar('errormsg', False)
+<%= errormsg %>
</div>
-#end if
+<% endif %>
<form method="POST" action="/gallery">
-#include 'templates/_form_elements.tmpl'
+<% include '_form_elements.tmpl' %>
<p><label for="model">Laptop or monitor model:</label>
<input type="text" name="model" size="50" maxlength="100"
-value="$getVar("model", None)" /></p>
+value="<%= model %>" /></p>
<input type="Submit" name="submit" value="Save" />
</form>
-#end block body
+<% endblock %>
-#extends site
+<% extends 'site.tmpl' %>
-#block body
+<% block body %>
<h2>Ruler Gallery </h2>
<h2>Create Custom Ruler</h2>
-#if $getVar('errormsg', False)
+<% if errormsg %>
<div class="errormsg">
<strong>Error</strong><br />
-$getVar('errormsg', False)
+<%= errormsg %>
</div>
+<% endif %>
-#end if
<form method="POST" action="/">
-#include 'templates/_form_elements.tmpl'
+<% include '_form_elements.tmpl' %>
<input type="Submit" name="submit" value="Generate" />
<form>
-
-#end block body
+<% endblock %>
<link rel="stylesheet" type="text/css" href="/static/style.css" />
</head>
<p id="menu">
-<a href="/show/$other_unit_url">show in $other_unit</a>
+<a href="/show/<%= other_unit_url %>">show in <%= other_unit %></a>
/
-#if $fromgallery
+<% if fromgallery %>
<a href="/gallery">back to gallery</a>
-#else
-<a href="/gallery/$ruler_url">save for others</a>
-#end if
+<% else %>
+<a href="/gallery/<%= ruler_url %>">save for others</a>
+<% endif %>
</p>
<div id="rulerimg">
-<img src="/$ruler_url" alt="$ruler_url" />
+<img src="/<%= ruler_url %>" alt="<%= ruler_url %>" />
</div>
<head>
<link rel="stylesheet" type="text/css" href="/static/style.css" />
<script src="/static/prototype.js" type="text/javascript"></script>
+ <title>You Rule</title>
</head>
<body>
<div id="wrapper">
<div class="mainbox">
<div class="mainbox_top"><div></div></div>
<div class="mainbox_content">
-
-#filter Filter
-$body
-#end filter
+ <% block body %>
+ <% endblock %>
</div>
<div class="mainbox_bottom"><div></div></div>
</div>
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',
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()
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'],
class show_ruler:
def GET(self, ruler_url, ext):
- web.debug('test test')
if web.input().has_key('fromgallery'):
fromgallery = True
else:
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):
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):
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__":