Commit 5f35d312 by Kevin Morgan

Only returning functions when they are unbounded methods otherwise they get…

Only returning functions when they are unbounded methods otherwise they get called in the return and fail.
parent 49c34b0c
...@@ -19,6 +19,9 @@ def replace(subject, this='foo', with_this='bar'): ...@@ -19,6 +19,9 @@ def replace(subject, this='foo', with_this='bar'):
class Lambdas(pystache.View): class Lambdas(pystache.View):
template_path = 'examples' template_path = 'examples'
def test(self):
return 'laaa'
def replace_foo_with_bar(self, text=None): def replace_foo_with_bar(self, text=None):
return replace return replace
......
{{#rot13}}abcdefghijklm{{/rot13}}
\ No newline at end of file
import pystache
from examples.lambdas import rot
class PartialsWithLambdas(pystache.View):
template_path = 'examples'
def rot(self):
return rot
\ No newline at end of file
from pystache import Template from pystache import Template
import os.path import os.path
import re import re
from types import *
class View(object): class View(object):
# Path where this view's template(s) live # Path where this view's template(s) live
...@@ -103,7 +104,7 @@ class View(object): ...@@ -103,7 +104,7 @@ class View(object):
def get(self, attr, default): def get(self, attr, default):
attr = self.context.get(attr, getattr(self, attr, default)) attr = self.context.get(attr, getattr(self, attr, default))
if hasattr(attr, '__call__'): if hasattr(attr, '__call__') and type(attr) is UnboundMethodType:
return attr() return attr()
else: else:
return attr return attr
......
...@@ -75,6 +75,11 @@ class TestView(unittest.TestCase): ...@@ -75,6 +75,11 @@ class TestView(unittest.TestCase):
view = Lambdas() view = Lambdas()
view.template = '{{#sort}}zyxwvutsrqponmlkjihgfedcba{{/sort}}' view.template = '{{#sort}}zyxwvutsrqponmlkjihgfedcba{{/sort}}'
self.assertEquals(view.render(), 'abcdefghijklmnopqrstuvwxyz') self.assertEquals(view.render(), 'abcdefghijklmnopqrstuvwxyz')
def test_partials_with_lambdas(self):
view = Lambdas()
view.template = '{{>partial_with_lambda}}'
self.assertEquals(view.render(), 'nopqrstuvwxyz')
def test_inverted(self): def test_inverted(self):
view = Inverted() view = Inverted()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment