Skip to content
Snippets Groups Projects
Commit 49db3f99 authored by Mike Bayer's avatar Mike Bayer
Browse files

- ${} expressions embedded in tags,

  such as <%foo:bar x="${...}">, now
  allow multiline Python expressions.
parent ae592c70
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,10 @@
must be referenced explicitly.
[ticket:141]
- ${} expressions embedded in tags,
such as <%foo:bar x="${...}">, now
allow multiline Python expressions.
- Fixed previously non-covered regular
expression, such that using a ${} expression
inside of a tag element that doesn't allow
......
......@@ -5,5 +5,5 @@
# the MIT License: http://www.opensource.org/licenses/mit-license.php
__version__ = '0.3.4'
__version__ = '0.3.5'
......@@ -268,8 +268,8 @@ class Tag(Node):
for key in self.attributes:
if key in expressions:
expr = []
for x in re.split(r'(\${.+?})', self.attributes[key]):
m = re.match(r'^\${(.+?)}$', x)
for x in re.compile(r'(\${.+?})', re.S).split(self.attributes[key]):
m = re.compile(r'^\${(.+?)}$', re.S).match(x)
if m:
code = ast.PythonCode(m.group(1), **self.exception_kwargs)
undeclared_identifiers = undeclared_identifiers.union(
......
from mako.template import Template
from mako import util
import unittest
from util import result_lines, flatten_result
from test import TemplateTest, eq_
class CallTest(unittest.TestCase):
class CallTest(TemplateTest):
def test_call(self):
t = Template("""
<%def name="foo()">
......@@ -44,6 +44,34 @@ class CallTest(unittest.TestCase):
""")
assert result_lines(t.render()) == ['foo calling comp1:', 'this is comp1, 5', 'foo calling body:', 'this is the body,', 'this is comp1, 6', 'this is bar']
def test_new_syntax(self):
"""test foo:bar syntax, including multiline args and expression eval."""
t = Template("""
<%def name="foo(x, y, q, z)">
${x}
${y}
${q}
${",".join("%s->%s" % (a, b) for a, b in z)}
</%def>
<%self:foo x="this is x" y="${'some ' + 'y'}" q="
this
is
q"
z="${[
(1, 2),
(3, 4),
(5, 6)
]}"/>
""")
eq_(
result_lines(t.render()),
['this is x', 'some y', 'this', 'is', 'q', '1->2,3->4,5->6']
)
def test_ccall_caller(self):
t = Template("""
<%def name="outer_func()">
......@@ -380,7 +408,7 @@ class CallTest(unittest.TestCase):
""")
assert result_lines(t.render()) == ['this is a', 'this is b', 'this is c:', "this is the body in b's call", 'the embedded "d" is:', 'this is d']
class SelfCacheTest(unittest.TestCase):
class SelfCacheTest(TemplateTest):
"""this test uses a now non-public API."""
def test_basic(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment