From db72cec869ec6a88736d1559aca25249e9df5107 Mon Sep 17 00:00:00 2001 From: Lakshmi Vyasarajan Date: Mon, 3 Jan 2011 16:13:44 +0530 Subject: [PATCH] Added typogrify support --- hyde/ext/templates/jinja.py | 9 +++++++++ hyde/tests/test_jinja2template.py | 14 +++++++++++++- hyde/tests/test_typogrify.py | 0 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 hyde/tests/test_typogrify.py diff --git a/hyde/ext/templates/jinja.py b/hyde/ext/templates/jinja.py index c0f5687..3fa41a3 100644 --- a/hyde/ext/templates/jinja.py +++ b/hyde/ext/templates/jinja.py @@ -52,6 +52,15 @@ class Jinja2Template(Template): self.env.globals['media_url'] = media_url self.env.globals['content_url'] = content_url + try: + from typogrify.templatetags import jinja2_filters + except ImportError: + jinja2_filters = False + + if jinja2_filters: + jinja2_filters.register(self.env) + + def render(self, text, context): """ Renders the given resource using the context diff --git a/hyde/tests/test_jinja2template.py b/hyde/tests/test_jinja2template.py index 1132d0a..94499f6 100644 --- a/hyde/tests/test_jinja2template.py +++ b/hyde/tests/test_jinja2template.py @@ -9,6 +9,7 @@ Code borrowed from rwbench.py from the jinja2 examples from datetime import datetime from hyde.ext.templates.jinja import Jinja2Template from hyde.fs import File, Folder +import jinja2 from jinja2.utils import generate_lorem_ipsum from random import choice, randrange from util import assert_html_equals @@ -68,4 +69,15 @@ def test_render(): assert actual("div.article h2").length == 20 assert actual("div.article h2 a").length == 20 assert actual("div.article p.meta").length == 20 - assert actual("div.article div.text").length == 20 \ No newline at end of file + assert actual("div.article div.text").length == 20 + +def test_typogrify(): + source = """ + {%filter typogrify%} + One & two + {%endfilter%} + """ + t = Jinja2Template(JINJA2.path) + t.configure(None) + html = t.render(source, {}).strip() + assert html == u'One & two' diff --git a/hyde/tests/test_typogrify.py b/hyde/tests/test_typogrify.py new file mode 100644 index 0000000..e69de29