Browse Source

Added line statement support to jinja2

main
Lakshmi Vyasarajan 14 years ago
parent
commit
ed5d3c3a67
2 changed files with 40 additions and 1 deletions
  1. +1
    -0
      hyde/ext/templates/jinja.py
  2. +39
    -1
      hyde/tests/test_jinja2template.py

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

@@ -465,6 +465,7 @@ class Jinja2Template(Template):
self.loader = HydeLoader(self.sitepath, site, self.preprocessor) self.loader = HydeLoader(self.sitepath, site, self.preprocessor)
self.env = Environment(loader=self.loader, self.env = Environment(loader=self.loader,
undefined=SilentUndefined, undefined=SilentUndefined,
line_statement_prefix='---',
trim_blocks=True, trim_blocks=True,
bytecode_cache=FileSystemBytecodeCache(), bytecode_cache=FileSystemBytecodeCache(),
extensions=[IncludeText, extensions=[IncludeText,


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

@@ -150,6 +150,22 @@ def test_markdown_with_extensions():
assert html == u'<h3 id="heading_3">Heading 3</h3>' assert html == u'<h3 id="heading_3">Heading 3</h3>'




def test_line_statements():
source = """
---markdown
### Heading 3

--- endmarkdown
"""
t = Jinja2Template(JINJA2.path)
s = Site(JINJA2.path)
c = Config(JINJA2.path, config_dict=dict(markdown=dict(extensions=['headerid'])))
s.config = c
t.configure(s)
html = t.render(source, {}).strip()
assert html == u'<h3 id="heading_3">Heading 3</h3>'


TEST_SITE = File(__file__).parent.child_folder('_test') TEST_SITE = File(__file__).parent.child_folder('_test')


@nottest @nottest
@@ -163,7 +179,6 @@ def assert_markdown_typogrify_processed_well(include_text, includer_text):
gen.load_template_if_needed() gen.load_template_if_needed()
template = gen.template template = gen.template
html = template.render(includer_text, {}).strip() html = template.render(includer_text, {}).strip()
print html
assert html assert html
q = PyQuery(html) q = PyQuery(html)
assert "is_processable" not in html assert "is_processable" not in html
@@ -207,6 +222,29 @@ class TestJinjaTemplate(object):
assert 'layout.html' in deps assert 'layout.html' in deps
assert 'index.html' in deps assert 'index.html' in deps


def test_line_statements_with_blocks(self):
site = Site(TEST_SITE)
JINJA2.copy_contents_to(site.content.source)
inc = File(TEST_SITE.child('content/inc.md'))
text = """
{% extends 'index.html' %}
--- block body
<div id="article">Heya</div>
--- endblock
"""
site.load()
gen = Generator(site)
gen.load_template_if_needed()
template = gen.template
html = template.render(text, {}).strip()

assert html
q = PyQuery(html)
article = q("#article")
assert article.length == 1
assert article.text() == "Heya"


def test_depends_with_reference_tag(self): def test_depends_with_reference_tag(self):
site = Site(TEST_SITE) site = Site(TEST_SITE)
JINJA2.copy_contents_to(site.content.source) JINJA2.copy_contents_to(site.content.source)


Loading…
Cancel
Save