Merge lp:~lifeless/pybars/bug-1040096 into lp:pybars

Proposed by Robert Collins
Status: Merged
Merged at revision: 7
Proposed branch: lp:~lifeless/pybars/bug-1040096
Merge into: lp:pybars
Diff against target: 73 lines (+23/-2)
3 files modified
NEWS (+4/-0)
pybars/_compiler.py (+11/-2)
pybars/tests/test_acceptance.py (+8/-0)
To merge this branch: bzr merge lp:~lifeless/pybars/bug-1040096
Reviewer Review Type Date Requested Status
James Westby (community) Approve
Review via email: mp+125874@code.launchpad.net

Description of the change

handlebars.js comes with a default helperMissing, pybars doesn't, but should for compatability.

To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

Hi,

Looks good.

Maybe a test for the helpers ordering change would be good?

Thanks,

James

review: Approve
Revision history for this message
Robert Collins (lifeless) wrote :

On Mon, Sep 24, 2012 at 12:45 PM, James Westby
<email address hidden> wrote:
> Review: Approve
>
> Hi,
>
> Looks good.
>
> Maybe a test for the helpers ordering change would be good?

Its covered already - I had to change it to keep tests passing :)

-Rob

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2012-09-20 23:42:40 +0000
+++ NEWS 2012-09-23 08:15:25 +0000
@@ -6,6 +6,10 @@
6NEXT6NEXT
7----7----
88
9* A default `helperMissing` helper is now present in the global set of helpers.
10 This gives default behaviour the same as handlebars.js, though it can still
11 be overridden. (Robert Collins, lp:1040096)
12
90.0.3130.0.3
10-----14-----
1115
1216
=== modified file 'pybars/_compiler.py'
--- pybars/_compiler.py 2012-09-20 23:42:40 +0000
+++ pybars/_compiler.py 2012-09-23 08:15:25 +0000
@@ -233,15 +233,23 @@
233 return options['fn'](callwith)233 return options['fn'](callwith)
234234
235235
236def _helperMissing(scope, name, *args):
237 if not args:
238 return None
239 raise Exception(u"Could not find property %s" % (name,))
240
241
236def _with(this, options, context):242def _with(this, options, context):
237 return options['fn'](context)243 return options['fn'](context)
238244
245
239# scope for the compiled code to reuse globals246# scope for the compiled code to reuse globals
240_pybars_ = {247_pybars_ = {
241 'helpers': {248 'helpers': {
242 'blockHelperMissing': _blockHelperMissing,249 'blockHelperMissing': _blockHelperMissing,
243 'each': _each,250 'each': _each,
244 'if': _if,251 'if': _if,
252 'helperMissing': _helperMissing,
245 'log': _log,253 'log': _log,
246 'unless': _unless,254 'unless': _unless,
247 'with': _with,255 'with': _with,
@@ -265,8 +273,9 @@
265 # when profiling.273 # when profiling.
266 self._result.grow(u"def render(context, helpers=None, partials=None):\n")274 self._result.grow(u"def render(context, helpers=None, partials=None):\n")
267 self._result.grow(u" result = strlist()\n")275 self._result.grow(u" result = strlist()\n")
268 self._result.grow(u" if helpers is None: helpers = {}\n")276 self._result.grow(u" _helpers = dict(pybars['helpers'])\n")
269 self._result.grow(u" helpers.update(pybars['helpers'])\n")277 self._result.grow(u" if helpers is not None: _helpers.update(helpers)\n")
278 self._result.grow(u" helpers = _helpers\n")
270 self._result.grow(u" if partials is None: partials = {}\n")279 self._result.grow(u" if partials is None: partials = {}\n")
271 # Expose used functions and helpers to the template.280 # Expose used functions and helpers to the template.
272 self._locals['strlist'] = strlist281 self._locals['strlist'] = strlist
273282
=== modified file 'pybars/tests/test_acceptance.py'
--- pybars/tests/test_acceptance.py 2012-09-20 23:42:40 +0000
+++ pybars/tests/test_acceptance.py 2012-09-23 08:15:25 +0000
@@ -547,6 +547,14 @@
547 source = u"{{#truthy}}yep{{/truthy}}"547 source = u"{{#truthy}}yep{{/truthy}}"
548 self.assertEqual("yep", render(source, {'truthy': lambda this: True}))548 self.assertEqual("yep", render(source, {'truthy': lambda this: True}))
549549
550 def test_default_helperMissing_no_params(self):
551 source = u"a{{missing}}b"
552 self.assertEqual("ab", render(source, {}))
553
554 def test_default_helperMissing_with_param(self):
555 source = u"a{{missing something}}b"
556 self.assertRaises(Exception, render, source, {})
557
550 def test_with(self):558 def test_with(self):
551 source = u"{{#with person}}{{first}} {{last}}{{/with}}"559 source = u"{{#with person}}{{first}} {{last}}{{/with}}"
552 self.assertEqual("Alan Johnson",560 self.assertEqual("Alan Johnson",

Subscribers

People subscribed via source and target branches

to all changes: