From 7b9ee226ef30bb3d51b0dd57a16568de80aea321 Mon Sep 17 00:00:00 2001 From: Lakshmi Vyasarajan Date: Mon, 13 Dec 2010 18:21:16 +0530 Subject: [PATCH] Restructured templates --- .../basic/README.markdown | 0 data/{templates => layouts}/basic/info.yaml | 0 .../basic/layout/analytics.html | 0 .../basic/layout/base.html | 0 .../basic/layout/devmode.html | 0 .../basic/layout/root.html | 0 hyde/ext/templates/jinja2.py | 14 +++++++++ hyde/template.py | 20 +++++++++++++ hyde/tests/templates/jinja2/helpers.html | 12 ++++++++ hyde/tests/templates/jinja2/index.html | 29 +++++++++++++++++++ hyde/tests/templates/jinja2/layout.html | 29 +++++++++++++++++++ hyde/tests/test_jinja2template.py | 0 12 files changed, 104 insertions(+) rename data/{templates => layouts}/basic/README.markdown (100%) rename data/{templates => layouts}/basic/info.yaml (100%) rename data/{templates => layouts}/basic/layout/analytics.html (100%) rename data/{templates => layouts}/basic/layout/base.html (100%) rename data/{templates => layouts}/basic/layout/devmode.html (100%) rename data/{templates => layouts}/basic/layout/root.html (100%) create mode 100644 hyde/ext/templates/jinja2.py create mode 100644 hyde/template.py create mode 100644 hyde/tests/templates/jinja2/helpers.html create mode 100644 hyde/tests/templates/jinja2/index.html create mode 100644 hyde/tests/templates/jinja2/layout.html create mode 100644 hyde/tests/test_jinja2template.py diff --git a/data/templates/basic/README.markdown b/data/layouts/basic/README.markdown similarity index 100% rename from data/templates/basic/README.markdown rename to data/layouts/basic/README.markdown diff --git a/data/templates/basic/info.yaml b/data/layouts/basic/info.yaml similarity index 100% rename from data/templates/basic/info.yaml rename to data/layouts/basic/info.yaml diff --git a/data/templates/basic/layout/analytics.html b/data/layouts/basic/layout/analytics.html similarity index 100% rename from data/templates/basic/layout/analytics.html rename to data/layouts/basic/layout/analytics.html diff --git a/data/templates/basic/layout/base.html b/data/layouts/basic/layout/base.html similarity index 100% rename from data/templates/basic/layout/base.html rename to data/layouts/basic/layout/base.html diff --git a/data/templates/basic/layout/devmode.html b/data/layouts/basic/layout/devmode.html similarity index 100% rename from data/templates/basic/layout/devmode.html rename to data/layouts/basic/layout/devmode.html diff --git a/data/templates/basic/layout/root.html b/data/layouts/basic/layout/root.html similarity index 100% rename from data/templates/basic/layout/root.html rename to data/layouts/basic/layout/root.html diff --git a/hyde/ext/templates/jinja2.py b/hyde/ext/templates/jinja2.py new file mode 100644 index 0000000..e54229e --- /dev/null +++ b/hyde/ext/templates/jinja2.py @@ -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 \ No newline at end of file diff --git a/hyde/template.py b/hyde/template.py new file mode 100644 index 0000000..abbf9c6 --- /dev/null +++ b/hyde/template.py @@ -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 \ No newline at end of file diff --git a/hyde/tests/templates/jinja2/helpers.html b/hyde/tests/templates/jinja2/helpers.html new file mode 100644 index 0000000..89976aa --- /dev/null +++ b/hyde/tests/templates/jinja2/helpers.html @@ -0,0 +1,12 @@ +{% macro input_field(name, value='', type='text') -%} + +{%- endmacro %} + +{% macro textarea(name, value='', rows=10, cols=40) -%} + +{%- endmacro %} + +{% macro form(action='', method='post') -%} +
{{ caller() }}
+{%- endmacro %} diff --git a/hyde/tests/templates/jinja2/index.html b/hyde/tests/templates/jinja2/index.html new file mode 100644 index 0000000..b006d05 --- /dev/null +++ b/hyde/tests/templates/jinja2/index.html @@ -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 %} +
+

{{ article.title|e }}

+

written by {{ article.user.username|e }} on {{ article.pub_date|dateformat }}

+
{{ article.body }}
+
+ {%- endfor %} + {%- call form() %} +
+
Name
+
{{ input_field('name') }}
+
E-Mail
+
{{ input_field('email') }}
+
URL
+
{{ input_field('url') }}
+
Comment
+
{{ textarea('comment') }}
+
Captcha
+
{{ input_field('captcha') }}
+
+ {{ input_field(type='submit', value='Submit') }} + {{ input_field('cancel', type='submit', value='Cancel') }} + {%- endcall %} +{% endblock %} diff --git a/hyde/tests/templates/jinja2/layout.html b/hyde/tests/templates/jinja2/layout.html new file mode 100644 index 0000000..755789e --- /dev/null +++ b/hyde/tests/templates/jinja2/layout.html @@ -0,0 +1,29 @@ + + + + {% block page_title %}{% endblock %} | RealWorld Benchmark + + + +
+
+

RealWorld Benchmark

+

+ A less stupid benchmark for Mako and Jinja2 to get an impression how + code changes affect runtime performance. +

+
+ +
+ {% block body %}{% endblock %} +
+ +
+ + diff --git a/hyde/tests/test_jinja2template.py b/hyde/tests/test_jinja2template.py new file mode 100644 index 0000000..e69de29