Commits

Anonymous committed 395338f

Use same constants across templates rendering functions:
``TITLE``, ``USER`` and ``(U_)ITEMS``.

Comments (0)

Files changed (1)

examples/bench/basic.py

 __all__ = ['mako', 'mako_inheritance', 'jinja2', 'jinja2_inheritance',
             'cheetah', 'django', 'myghty', 'genshi', 'kid']
 
+# Templates content and constants
+TITLE = 'Just a test'
+USER = 'joe'
+ITEMS = ['Number %d' % num for num in range(1, 15)]
+U_ITEMS = [u(item) for item in ITEMS]
+
 def genshi(dirname, verbose=False):
     from genshi.template import TemplateLoader
     loader = TemplateLoader([dirname], auto_reload=False)
     template = loader.load('template.html')
     def render():
-        data = dict(title='Just a test', user='joe',
-                    items=['Number %d' % num for num in range(1, 15)])
+        data = dict(title=TITLE, user=USER, items=ITEMS)
         return template.generate(**data).render('xhtml')
 
     if verbose:
     from myghty import interp
     interpreter = interp.Interpreter(component_root=dirname)
     def render():
-        data = dict(title='Just a test', user='joe',
-                    items=['Number %d' % num for num in range(1, 15)])
+        data = dict(title=TITLE, user=USER, items=ITEMS)
         buffer = StringIO()
         interpreter.execute("template.myt", request_args=data, out_buffer=buffer)
         return buffer.getvalue()
     lookup = TemplateLookup(directories=[dirname], filesystem_checks=False, disable_unicode=disable_unicode)
     template = lookup.get_template('template.html')
     def render():
-        return template.render(title="Just a test", user="joe", list_items=[u('Number %d') % num for num in range(1,15)])
+        return template.render(title=TITLE, user=USER, list_items=U_ITEMS)
     if verbose:
         print(template.code + " " + render())
     return render
     env = Environment(loader=FileSystemLoader(dirname))
     template = env.get_template('template.html')
     def render():
-        return template.render(title="Just a test", user="joe", list_items=[u('Number %d') % num for num in range(1,15)])
+        return template.render(title=TITLE, user=USER, list_items=U_ITEMS)
     if verbose:
         print(render())
     return render
     filename = os.path.join(dirname, 'template.tmpl')
     template = Template(file=filename)
     def render():
-        template.__dict__.update({'title': 'Just a test', 'user': 'joe',
-                                  'list_items': [u('Number %d') % num for num in range(1, 15)]})
+        template.__dict__.update({'title': TITLE, 'user': USER,
+                                  'list_items': U_ITEMS})
         return template.respond()
 
     if verbose:
     tmpl = loader.get_template('template.html')
 
     def render():
-        data = {'title': 'Just a test', 'user': 'joe',
-                'items': ['Number %d' % num for num in range(1, 15)]}
+        data = {'title': TITLE, 'user': USER, 'items': ITEMS}
         return tmpl.render(template.Context(data))
 
     if verbose:
     template = kid.Template(file='template.kid')
     def render():
         template = kid.Template(file='template.kid',
-                                title='Just a test', user='joe',
-                                items=['Number %d' % num for num in range(1, 15)])
+                                title=TITLE, user=USER, items=ITEMS)
         return template.serialize(output='xhtml')
 
     if verbose: