Commits

Andriy Kornatskyy  committed 287b0f7

Added template benchmark for tenjin.

  • Participants
  • Parent commits cd8e870

Comments (0)

Files changed (15)

File 05-template/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" \

File 05-template/benchmark.py

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

File 05-template/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>
+        <link href="css/site.css" type="text/css" rel="stylesheet" />
+    </head>
+    <body>
+        <div id="content">
+            <div id="user">
+                <?py if user: ?>
+                    Hello, ${user.name}!
+                    | <a href="/signout">Sign out</a>
+                <?py else: ?>
+                    <a href="/signin">Sign in</a>
+                <?py #endif ?>
+            </div>
+            <?py if items: ?>
+                <?py for i in items: ?>
+                <p>
+                    ${i.name}: #{i.price}
+                </p>
+                <?py #endfor ?>
+            <?py else: ?>
+                <p>No items found.</p>
+            <?py #endif ?>
+        </div>
+        <div id="footer">
+            Some Rights Reserved!
+        </div>
+        <script src="js/jquery.js" type="text/javascript"></script>
+    </body>
+</html>

File 05-template/tenjin/02-include/shared/snippet/footer.html

+<div id="footer">
+    Some Rights Reserved!
+</div>

File 05-template/tenjin/02-include/shared/snippet/menu-signin.html

+<?py if user: ?>
+    Hello, ${user.name}!
+    | <a href="/signout">Sign out</a>
+<?py else: ?>
+    <a href="/signin">Sign in</a>
+<?py #end ?>

File 05-template/tenjin/02-include/shared/snippet/scripts.html

+<script src="js/jquery.js" type="text/javascript"></script>

File 05-template/tenjin/02-include/shared/snippet/styles.html

+<link href="css/site.css" type="text/css" rel="stylesheet" />

File 05-template/tenjin/02-include/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>
+        <?py include('shared/snippet/styles.html') ?>
+    </head>
+    <body>
+        <div id="content">
+            <div id="user">
+                <?py include('shared/snippet/menu-signin.html') ?>
+            </div>
+            <?py if items: ?>
+                <?py for i in items: ?>
+                <p>
+                    ${i.name}: #{i.price}
+                </p>
+                <?py #endfor ?>
+            <?py else: ?>
+                <p>No items found.</p>
+            <?py #endif ?>
+        </div>
+        <?py include('shared/snippet/footer.html') ?>
+        <?py include('shared/snippet/scripts.html') ?>
+    </body>
+</html>

File 05-template/tenjin/03-extends/shared/master.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 -
+        <?py if not captured_as("title"): ?>
+        <?py pass ?>
+        <?py #endif ?></title>
+        <?py include('shared/snippet/styles.html') ?>
+    </head>
+    <body>
+        <div id="content">
+            <div id="user">
+                <?py include('shared/snippet/menu-signin.html') ?>
+            </div>
+            #{_content}
+        </div>
+        <?py include('shared/snippet/footer.html') ?>
+        <?py include('shared/snippet/scripts.html') ?>
+        <?py if not captured_as("script"): ?>
+        <?py pass ?>
+        <?py #endif ?>
+    </body>
+</html>
+

File 05-template/tenjin/03-extends/shared/snippet/footer.html

+<div id="footer">
+    Some Rights Reserved!
+</div>

File 05-template/tenjin/03-extends/shared/snippet/menu-signin.html

+<?py if user: ?>
+    Hello, ${user.name}!
+    | <a href="/signout">Sign out</a>
+<?py else: ?>
+    <a href="/signin">Sign in</a>
+<?py #end ?>

File 05-template/tenjin/03-extends/shared/snippet/scripts.html

+<script src="js/jquery.js" type="text/javascript"></script>

File 05-template/tenjin/03-extends/shared/snippet/styles.html

+<link href="css/site.css" type="text/css" rel="stylesheet" />

File 05-template/tenjin/03-extends/welcome.html

+<?py _context["_layout"] = "shared/master.html" ?>
+
+<?py for t in capture_as("title"): ?>
+Welcome
+<?py #endfor ?>
+
+<?py if items: ?>
+    <?py for i in items: ?>
+    <p>
+        ${i.name}: #{i.price}
+    </p>
+    <?py #endfor ?>
+<?py else: ?>
+    <p>No items found.</p>
+<?py #endif ?>

File 05-template/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, helpers)