Browse Source

Added typogrify support

main
Lakshmi Vyasarajan 14 years ago
parent
commit
db72cec869
3 changed files with 22 additions and 1 deletions
  1. +9
    -0
      hyde/ext/templates/jinja.py
  2. +13
    -1
      hyde/tests/test_jinja2template.py
  3. +0
    -0
      hyde/tests/test_typogrify.py

+ 9
- 0
hyde/ext/templates/jinja.py View File

@@ -52,6 +52,15 @@ class Jinja2Template(Template):
self.env.globals['media_url'] = media_url self.env.globals['media_url'] = media_url
self.env.globals['content_url'] = content_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): def render(self, text, context):
""" """
Renders the given resource using the context Renders the given resource using the context


+ 13
- 1
hyde/tests/test_jinja2template.py View File

@@ -9,6 +9,7 @@ Code borrowed from rwbench.py from the jinja2 examples
from datetime import datetime from datetime import datetime
from hyde.ext.templates.jinja import Jinja2Template from hyde.ext.templates.jinja import Jinja2Template
from hyde.fs import File, Folder from hyde.fs import File, Folder
import jinja2
from jinja2.utils import generate_lorem_ipsum from jinja2.utils import generate_lorem_ipsum
from random import choice, randrange from random import choice, randrange
from util import assert_html_equals 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").length == 20
assert actual("div.article h2 a").length == 20 assert actual("div.article h2 a").length == 20
assert actual("div.article p.meta").length == 20 assert actual("div.article p.meta").length == 20
assert actual("div.article div.text").length == 20
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 <span class="amp">&amp;</span>&nbsp;two'

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


Loading…
Cancel
Save