Skip to content

Commit

Permalink
0.0.2
Browse files Browse the repository at this point in the history
-----

* Add support for '{{else}}'. (Mjumbe Wawatu Ukweli, lp:997180)

* Bump dependency on PyMeta to 0.5.0. (Robert Collins)
  • Loading branch information
rbtcollins committed Jul 30, 2012
1 parent 8b909b3 commit 1e25e12
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
10 changes: 10 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ Changes and improvements to pybars, grouped by release.
NEXT
----

0.0.2
-----

* Add support for '{{else}}'. (Mjumbe Wawatu Ukweli, lp:997180)

* Bump dependency on PyMeta to 0.5.0. (Robert Collins)

0.0.1
-----

* Initial release, passes acceptance tests from handlebars.js, except for
deliberately skipped features (.data hashes and stringParams).
(Robert Collins)
Expand Down
5 changes: 3 additions & 2 deletions pybars/_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
escapedexpression ::= <start> <expression_inner>:e => ('escapedexpand', ) + e
block_inner ::= <spaces> <symbol>:s <arguments>:args <spaces> <finish>
=> (u''.join(s), args)
alt_inner ::= <spaces> ('^' | 'e' 'l' 's' 'e') <spaces> <finish>
partial ::= <start> '>' <block_inner>:i => ('partial',) + i
path ::= ~('/') <pathseg>+:segments => ('path', segments)
kwliteral ::= <symbol>:s '=' (<literal>|<path>):v => ('kwparam', s, v)
Expand All @@ -71,7 +72,7 @@
true ::= 't' 'r' 'u' 'e' => True
notquote ::= <escapedquote> | (~('"') <anything>)
escapedquote ::= '\\' '"' => '\\"'
symbol ::= '['? (<letterOrDigit>|'-'|'@')+:symbol ']'? => u''.join(symbol)
symbol ::= ~<alt_inner> '['? (<letterOrDigit>|'-'|'@')+:symbol ']'? => u''.join(symbol)
pathseg ::= <symbol>
| '/' => u''
| ('.' '.' '/') => u'__parent'
Expand All @@ -82,7 +83,7 @@
<template>:t <alttemplate>:alt_t <symbolfinish i[0]> => ('block',) + i + (t, alt_t)
| <start> '^' <block_inner>:i
<template>:t <symbolfinish i[0]> => ('invertedblock',) + i + (t,)
alttemplate ::= (<start>'^'<finish> <template>)?:alt_t => alt_t or []
alttemplate ::= (<start> <alt_inner> <template>)?:alt_t => alt_t or []
"""

# this grammar compiles the template to python
Expand Down
6 changes: 6 additions & 0 deletions pybars/tests/test_acceptance.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ def list(this, options, context):
rootMessage = {'people': [], 'message': "Nobody's here"}
src1 = u"{{#list people}}{{name}}{{^}}<em>Nobody's here</em>{{/list}}"
src2 = u"{{#list people}}Hello{{^}}{{message}}{{/list}}"
src3 = u"{{#list people}}{{name}}{{else}}<em>Nobody's here</em>{{/list}}"
helpers = {'list': list}
# inverse not executed by helper:
self.assertEqual("<ul><li>Alan</li><li>Yehuda</li></ul>",
Expand All @@ -354,6 +355,11 @@ def list(this, options, context):
# helpers.
self.assertEqual("<p>Nobody&#x27;s here</p>",
render(src2, rootMessage, helpers=helpers))
# inverse can also be denoted by 'else':
self.assertEqual("<ul><li>Alan</li><li>Yehuda</li></ul>",
render(src3, context, helpers))
self.assertEqual("<p><em>Nobody's here</em></p>",
render(src3, empty, helpers))

def test_providing_a_helpers_hash(self):
self.assertEqual("Goodbye cruel world!",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
os.path.join(os.path.dirname(__file__), 'README'), 'rb').read()

setup(name="pybars",
version="0.0.1",
version="0.0.2",
description=\
"handlebars.js templating for Python.",
long_description=description,
Expand Down
2 changes: 1 addition & 1 deletion versions.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ versions = versions
[versions]
fixtures = 0.3.6
iso8601 = 0.1.4
PyMeta = 0.4.0
PyMeta = 0.5.0
pytz = 2010o
setuptools = 0.6c11
testtools = 0.9.11
Expand Down

0 comments on commit 1e25e12

Please sign in to comment.