Commits

Andriy Kornatskyy  committed a0a944e

Added widget benchmark for tornado.

  • Participants
  • Parent commits 4d1eca0

Comments (0)

Files changed (8)

File 06-widgets/benchmark.py

 
 path = os.getcwd()
 
-frameworks = ['django', 'jinja2', 'wheezy.template']
+frameworks = ['django', 'jinja2', 'tornado', 'wheezy.template']
 #frameworks += ['mako']
 frameworks = sorted(frameworks)
 

File 06-widgets/tornado/01-initial/welcome.html

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+    <head>
+        <title>My Site - Welcome</title>
+    </head>
+    <body>
+        <div id="greeting">
+            {% for name in names %}
+            <p>
+                Hello <i>{{ name }}</i>!
+            </p>
+            {% end %}
+        </div>
+    </body>
+</html>

File 06-widgets/tornado/02-single/uimodules/greetings.html

+<div id="greeting">
+    {% for name in names %}
+    <p>
+        Hello <i>{{ name }}</i>!
+    </p>
+    {% end %}
+</div>

File 06-widgets/tornado/02-single/welcome.html

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+    <head>
+        <title>My Site - Welcome</title>
+    </head>
+    <body>
+        {% module greetings(names=names) %}
+    </body>
+</html>

File 06-widgets/tornado/03-loop/uimodules/greeting.html

+    <p>
+        Hello <i>{{ name }}</i>!
+    </p>

File 06-widgets/tornado/03-loop/welcome.html

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+    <head>
+        <title>My Site - Welcome</title>
+    </head>
+    <body>
+        <div id="greeting">
+            {% for name in names %}
+                {% module greeting(name=name) %}
+            {% end %}
+        </div>
+    </body>
+</html>

File 06-widgets/tornado/app.py

+
+"""
+"""
+
+import uimodules
+
+from tornado.template import Loader
+from tornado.util import ObjectDict
+
+
+def main(name):
+    loader = Loader(root_directory=name)
+    template = loader.load('welcome.html')
+    modules = {'_modules': ObjectDict([
+        ('greeting', uimodules.Greeting(loader)),
+        ('greetings', uimodules.Greetings(loader))
+    ])}
+    return lambda ctx: template.generate(**dict(ctx, **modules))

File 06-widgets/tornado/uimodules.py

+import tornado.web
+
+
+class Greeting(tornado.web.UIModule):
+
+    def __init__(self, loader):
+        self.loader = loader
+
+    def __call__(self, **ctx):
+        template = self.loader.load('uimodules/greeting.html')
+        return template.generate(**ctx)
+
+
+class Greetings(tornado.web.UIModule):
+
+    def __init__(self, loader):
+        self.loader = loader
+
+    def __call__(self, **ctx):
+        template = self.loader.load('uimodules/greetings.html')
+        return template.generate(**ctx)