Skip to content

Commit

Permalink
Switch the order of precompiling and registering partials in handleba…
Browse files Browse the repository at this point in the history
…rs tag, so that partials can used compiled template
  • Loading branch information
mjumbewu committed Sep 23, 2013
1 parent 91a25da commit 65a8d0a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
14 changes: 8 additions & 6 deletions jstemplate/templatetags/handlebarsjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ def generate_node_text(self, resolved_name, file_content):
output += (
'<script>'
'(function(H) {{'
'var source = document.getElementById("{name}").innerHtml;'
'var source = document.getElementById("{name}").innerHtml,'
'template = source;'
)

if 'register_partials' in self.args:
output += 'H.registerPartial("{name}", source);'

if 'precompile' in self.args:
output += ('H.templates = H.templates || {{}};'
'H.templates["{name}"] = H.compile(source);')
output += ('template = H.compile(source);'
'H.templates = H.templates || {{}};'
'H.templates["{name}"] = template;')

if 'register_partials' in self.args:
output += 'H.registerPartial("{name}", template);'

output += (
'}})(Handlebars);'
Expand Down
11 changes: 7 additions & 4 deletions jstemplate/tests/test_ttag.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,11 @@ def test_with_precompile(self):
res,
'<script type="text/x-handlebars-template" id="testtemplate">'
'<p>Mustache\'s template full of {{ foo }} and \\.</p>\n'
'</script><script>(function(H) {var source = document.getElementById("testtemplate").innerHtml;'
'</script><script>(function(H) {var source = document.getElementById("testtemplate").innerHtml,'
'template = source;'
'template = H.compile(source);'
'H.templates = H.templates || {};'
'H.templates["testtemplate"] = H.compile(source);})(Handlebars);</script>')
'H.templates["testtemplate"] = template;})(Handlebars);</script>')


@override_settings(JSTEMPLATE_DIRS=[DIR])
Expand All @@ -271,8 +273,9 @@ def test_with_partials(self):
res,
'<script type="text/x-handlebars-template" id="testtemplate">'
'<p>Mustache\'s template full of {{ foo }} and \\.</p>\n'
'</script><script>(function(H) {var source = document.getElementById("testtemplate").innerHtml;'
'H.registerPartial("testtemplate", source);})(Handlebars);</script>')
'</script><script>(function(H) {var source = document.getElementById("testtemplate").innerHtml,'
'template = source;'
'H.registerPartial("testtemplate", template);})(Handlebars);</script>')


class DustTemplateTagTest(TestCase, BaseJSTemplateTagTestMixin):
Expand Down

0 comments on commit 65a8d0a

Please sign in to comment.