| @@ -0,0 +1,14 @@ | |||||
| """ | |||||
| Hyde Template interface realization for Jinja2 | |||||
| """ | |||||
| from hyde.template import Template | |||||
| class Jinja2Template(Template): | |||||
| def setup_env(config): | |||||
| """ | |||||
| Uses the config object to initialize the jinja environment. | |||||
| """ | |||||
| pass | |||||
| def render(template_name, context): | |||||
| pass | |||||
| @@ -0,0 +1,20 @@ | |||||
| # -*- coding: utf-8 -*- | |||||
| """ | |||||
| Interface for hyde template engines. To use a different template engine, | |||||
| the following interface must be implemented. | |||||
| """ | |||||
| class Template(object): | |||||
| def setup_env(config): | |||||
| """ | |||||
| The config object is a simple YAML object with required settings. The template | |||||
| implementations are responsible for transforming this object to match the `settings` | |||||
| required for the template engines. | |||||
| """ | |||||
| abstract | |||||
| def render(template_name, context): | |||||
| """ | |||||
| Given the name of a template (partial path usually), and the context, this function | |||||
| must return the rendered string. | |||||
| """ | |||||
| abstract | |||||
| @@ -0,0 +1,12 @@ | |||||
| {% macro input_field(name, value='', type='text') -%} | |||||
| <input type="{{ type }}" value="{{ value|e }}" name="{{ name }}"> | |||||
| {%- endmacro %} | |||||
| {% macro textarea(name, value='', rows=10, cols=40) -%} | |||||
| <textarea name="{{ name }}" rows="{{ rows }}" cols="{{ cols }}">{{ | |||||
| value|e }}</textarea> | |||||
| {%- endmacro %} | |||||
| {% macro form(action='', method='post') -%} | |||||
| <form action="{{ action|e }}" method="{{ method }}">{{ caller() }}</form> | |||||
| {%- endmacro %} | |||||
| @@ -0,0 +1,29 @@ | |||||
| {% extends "layout.html" %} | |||||
| {% from "helpers.html" import input_field, textarea, form %} | |||||
| {% block page_title %}Index Page{% endblock %} | |||||
| {% block body %} | |||||
| {%- for article in articles if article.published %} | |||||
| <div class="article"> | |||||
| <h2><a href="{{ article.href|e }}">{{ article.title|e }}</a></h2> | |||||
| <p class="meta">written by <a href="{{ article.user.href|e | |||||
| }}">{{ article.user.username|e }}</a> on {{ article.pub_date|dateformat }}</p> | |||||
| <div class="text">{{ article.body }}</div> | |||||
| </div> | |||||
| {%- endfor %} | |||||
| {%- call form() %} | |||||
| <dl> | |||||
| <dt>Name</dt> | |||||
| <dd>{{ input_field('name') }}</dd> | |||||
| <dt>E-Mail</dt> | |||||
| <dd>{{ input_field('email') }}</dd> | |||||
| <dt>URL</dt> | |||||
| <dd>{{ input_field('url') }}</dd> | |||||
| <dt>Comment</dt> | |||||
| <dd>{{ textarea('comment') }}</dd> | |||||
| <dt>Captcha</dt> | |||||
| <dd>{{ input_field('captcha') }}</dd> | |||||
| </dl> | |||||
| {{ input_field(type='submit', value='Submit') }} | |||||
| {{ input_field('cancel', type='submit', value='Cancel') }} | |||||
| {%- endcall %} | |||||
| {% endblock %} | |||||
| @@ -0,0 +1,29 @@ | |||||
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> | |||||
| <html> | |||||
| <head> | |||||
| <title>{% block page_title %}{% endblock %} | RealWorld Benchmark</title> | |||||
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |||||
| </head> | |||||
| <body> | |||||
| <div class="contents"> | |||||
| <div class="header"> | |||||
| <h1>RealWorld Benchmark</h1> | |||||
| <blockquote><p> | |||||
| A less stupid benchmark for Mako and Jinja2 to get an impression how | |||||
| code changes affect runtime performance. | |||||
| </p></blockquote> | |||||
| </div> | |||||
| <ul class="navigation"> | |||||
| {%- for href, caption in page_navigation %} | |||||
| <li><a href="{{ href|e }}">{{ caption }}</a></li> | |||||
| {%- endfor %} | |||||
| </ul> | |||||
| <div class="body"> | |||||
| {% block body %}{% endblock %} | |||||
| </div> | |||||
| <div class="footer"> | |||||
| © Copyright 2008 by I don't know who. | |||||
| </div> | |||||
| </div> | |||||
| </body> | |||||
| </html> | |||||