Andriy Kornatskyy avatar Andriy Kornatskyy committed cef07bb

Added widget benchmark for tenjin.

Comments (0)

Files changed (8)

06-widgets/Makefile

 	if [ "$$(echo $(VERSION) | sed 's/\.//')" -lt 30 ]; then \
 		cd $(ENV)/bin && ./easy_install-$(VERSION) -i $(PYPI) -O2 \
 			"wheezy.html>=0.1.122" "wheezy.template>=0.1.125" "mako>=0.7.2" \
-			"jinja2>=2.6" "django>=1.4.2" "tornado>=2.4"; \
+			"jinja2>=2.6" "django>=1.4.2" "tornado>=2.4" \
+			"tenjin>=1.1.1" "webext>=0.0.1" ; \
 	else \
 		cd $(ENV)/bin && ./easy_install-$(VERSION) -i $(PYPI) \
 				"distribute>=0.6.28" \

06-widgets/benchmark.py

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

06-widgets/tenjin/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">
+            <?py for name in names: ?>
+            <p>
+                Hello <i>${name}</i>!
+            </p>
+            <?py #endfor ?>
+        </div>
+    </body>
+</html>

06-widgets/tenjin/02-single/welcome.html

+<?py #@ARGS names ?>
+<!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>
+        <?py include('widget/greetings.html', names=names) ?>
+    </body>
+</html>

06-widgets/tenjin/02-single/widget/greetings.html

+<?py #@ARGS names ?>
+<div id="greeting">
+    <?py for name in names: ?>
+    <p>
+        Hello <i>${name}</i>!
+    </p>
+    <?py #endfor ?>
+</div>

06-widgets/tenjin/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">
+            <?py for name in names: ?>
+                <?py include('widget/greetings.html', name=name) ?>
+            <?py #endfor ?>
+        </div>
+    </body>
+</html>

06-widgets/tenjin/03-loop/widget/greetings.html

+<?py #@ARGS name ?>
+<p>
+    Hello <i>${name}</i>!
+</p>

06-widgets/tenjin/app.py

+
+"""
+"""
+
+import sys
+
+if sys.version_info[0] >= 3:
+    str_type = str
+else:
+    str_type = unicode
+
+import tenjin
+from tenjin.helpers import capture_as, captured_as, cache_as
+tenjin.set_template_encoding('UTF-8')
+try:
+    from webext import escape_html as escape
+except ImportError:
+    from tenjin.helpers import escape
+
+
+def main(name):
+    engine = tenjin.Engine(
+        path=[name],
+        postfix='.html',
+        cache=tenjin.MemoryCacheStorage(),
+        pp=None)
+    helpers = {
+        'to_str': str_type,
+        'escape': escape,
+        'capture_as': capture_as,
+        'captured_as': captured_as,
+        'cache_as': cache_as
+    }
+    return lambda ctx: engine.render('welcome.html', ctx.copy(), helpers)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.