Browse Source

Restructured templates

main
Lakshmi Vyasarajan 14 years ago
parent
commit
7b9ee226ef
12 changed files with 104 additions and 0 deletions
  1. +0
    -0
      data/layouts/basic/README.markdown
  2. +0
    -0
      data/layouts/basic/info.yaml
  3. +0
    -0
      data/layouts/basic/layout/analytics.html
  4. +0
    -0
      data/layouts/basic/layout/base.html
  5. +0
    -0
      data/layouts/basic/layout/devmode.html
  6. +0
    -0
      data/layouts/basic/layout/root.html
  7. +14
    -0
      hyde/ext/templates/jinja2.py
  8. +20
    -0
      hyde/template.py
  9. +12
    -0
      hyde/tests/templates/jinja2/helpers.html
  10. +29
    -0
      hyde/tests/templates/jinja2/index.html
  11. +29
    -0
      hyde/tests/templates/jinja2/layout.html
  12. +0
    -0
      hyde/tests/test_jinja2template.py

data/templates/basic/README.markdown → data/layouts/basic/README.markdown View File


data/templates/basic/info.yaml → data/layouts/basic/info.yaml View File


data/templates/basic/layout/analytics.html → data/layouts/basic/layout/analytics.html View File


data/templates/basic/layout/base.html → data/layouts/basic/layout/base.html View File


data/templates/basic/layout/devmode.html → data/layouts/basic/layout/devmode.html View File


data/templates/basic/layout/root.html → data/layouts/basic/layout/root.html View File


+ 14
- 0
hyde/ext/templates/jinja2.py View File

@@ -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

+ 20
- 0
hyde/template.py View File

@@ -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

+ 12
- 0
hyde/tests/templates/jinja2/helpers.html View File

@@ -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 %}

+ 29
- 0
hyde/tests/templates/jinja2/index.html View File

@@ -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 %}

+ 29
- 0
hyde/tests/templates/jinja2/layout.html View File

@@ -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">
&copy; Copyright 2008 by I don't know who.
</div>
</div>
</body>
</html>

+ 0
- 0
hyde/tests/test_jinja2template.py View File


Loading…
Cancel
Save