summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES4
-rw-r--r--doc/build/templates/base.mako2
-rw-r--r--mako/ext/babelplugin.py18
-rw-r--r--setup.cfg5
-rw-r--r--test/templates/gettext.mako9
-rw-r--r--test/test_babelplugin.py7
-rw-r--r--test/test_template.py20
7 files changed, 45 insertions, 20 deletions
diff --git a/CHANGES b/CHANGES
index eb30e38..4d54804 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,8 @@
0.9.1
+- [bug] Fixed bug in Babel plugin where translator comments
+ would be lost if intervening text nodes were encountered.
+ Fix courtesy Ned Batchelder. [ticket:225]
+
- [bug] Fixed TGPlugin.render method to support unicode template
names in Py2K - courtesy Vladimir Magamedov.
diff --git a/doc/build/templates/base.mako b/doc/build/templates/base.mako
index b075023..32c49d8 100644
--- a/doc/build/templates/base.mako
+++ b/doc/build/templates/base.mako
@@ -35,8 +35,6 @@
<div class="toolbar">
<a href="${site_base}/">Home</a>
&nbsp; | &nbsp;
- <a href="${site_base}/trac">Trac</a>
- &nbsp; | &nbsp;
<a href="${site_base}/community.html">Community</a>
&nbsp; | &nbsp;
<a href="${pathto('index')}">Documentation</a>
diff --git a/mako/ext/babelplugin.py b/mako/ext/babelplugin.py
index ba244bd..538c048 100644
--- a/mako/ext/babelplugin.py
+++ b/mako/ext/babelplugin.py
@@ -80,41 +80,37 @@ def extract_nodes(nodes, keywords, comment_tags, options):
child_nodes = node.nodes
elif isinstance(node, parsetree.ControlLine):
if node.isend:
- translator_comments = []
in_translator_comments = False
continue
code = node.text
elif isinstance(node, parsetree.Code):
- # <% and <%! blocks would provide their own translator comments
- translator_comments = []
in_translator_comments = False
-
code = node.code.code
elif isinstance(node, parsetree.Expression):
code = node.code.code
else:
- translator_comments = []
- in_translator_comments = False
continue
# Comments don't apply unless they immediately preceed the message
if translator_comments and \
translator_comments[-1][0] < node.lineno - 1:
translator_comments = []
- else:
- translator_comments = \
- [comment[1] for comment in translator_comments]
+
+ translator_strings = [comment[1] for comment in translator_comments]
if isinstance(code, compat.text_type):
code = code.encode('ascii', 'backslashreplace')
+ used_translator_comments = False
code = compat.byte_buffer(code)
for lineno, funcname, messages, python_translator_comments \
in extract_python(code, keywords, comment_tags, options):
yield (node.lineno + (lineno - 1), funcname, messages,
- translator_comments + python_translator_comments)
+ translator_strings + python_translator_comments)
+ used_translator_comments = True
- translator_comments = []
+ if used_translator_comments:
+ translator_comments = []
in_translator_comments = False
if child_nodes:
diff --git a/setup.cfg b/setup.cfg
index 3343ba9..c933a4d 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -2,6 +2,9 @@
tag_build = dev
+[wheel]
+universal = 1
+
[upload]
sign = 1
-identity = C4DAFEE1 \ No newline at end of file
+identity = C4DAFEE1
diff --git a/test/templates/gettext.mako b/test/templates/gettext.mako
index 367af55..ad07c5d 100644
--- a/test/templates/gettext.mako
+++ b/test/templates/gettext.mako
@@ -88,3 +88,12 @@ ${_(u'bar')}
</%def>
+## TRANSLATOR: <p> tag is ok?
+<p>${_("Inside a p tag")}</p>
+
+## TRANSLATOR: also this
+<p>${even_with_other_code_first()} - ${_("Later in a p tag")}</p>
+
+## TRANSLATOR: we still ignore comments too far from the string
+
+<p>${_("No action at a distance.")}</p>
diff --git a/test/test_babelplugin.py b/test/test_babelplugin.py
index 4118f4a..023433d 100644
--- a/test/test_babelplugin.py
+++ b/test/test_babelplugin.py
@@ -13,8 +13,8 @@ import os
class ExtractMakoTestCase(TemplateTest):
- @skip_if(lambda: not babel, 'babel not installed: skipping babelplugin test')
+ @skip_if(lambda: not babel, 'babel not installed: skipping babelplugin test')
def test_extract(self):
mako_tmpl = open(os.path.join(template_base, 'gettext.mako'))
messages = list(extract(mako_tmpl, {'_': None, 'gettext': None,
@@ -40,7 +40,10 @@ class ExtractMakoTestCase(TemplateTest):
(77, '_', 'Top', []),
(83, '_', 'foo', []),
(83, '_', 'hoho', []),
- (85, '_', 'bar', [])
+ (85, '_', 'bar', []),
+ (92, '_', 'Inside a p tag', ['TRANSLATOR: <p> tag is ok?']),
+ (95, '_', 'Later in a p tag', ['TRANSLATOR: also this']),
+ (99, '_', 'No action at a distance.', []),
]
self.assertEqual(expected, messages)
diff --git a/test/test_template.py b/test/test_template.py
index 28db06d..6c30c8a 100644
--- a/test/test_template.py
+++ b/test/test_template.py
@@ -13,6 +13,16 @@ from test import TemplateTest, eq_, template_base, module_base, \
requires_python_26_or_greater, assert_raises, assert_raises_message, \
requires_python_2
+class ctx(object):
+ def __init__(self, a, b):
+ pass
+
+ def __enter__(self):
+ return self
+
+ def __exit__(self, *arg):
+ pass
+
class EncodingTest(TemplateTest):
def test_escapes_html_tags(self):
from mako.exceptions import html_error_template
@@ -875,11 +885,12 @@ class ControlTest(TemplateTest):
def test_blank_control_8(self):
self._do_memory_test(
"""
- % with open('x', 'w') as fp:
+ % with ctx('x', 'w') as fp:
% endwith
""",
"",
- filters=lambda s:s.strip()
+ filters=lambda s: s.strip(),
+ template_args={"ctx": ctx}
)
def test_commented_blank_control_1(self):
@@ -973,12 +984,13 @@ class ControlTest(TemplateTest):
def test_commented_blank_control_8(self):
self._do_memory_test(
"""
- % with open('x', 'w') as fp:
+ % with ctx('x', 'w') as fp:
## comment
% endwith
""",
"",
- filters=lambda s:s.strip()
+ filters=lambda s: s.strip(),
+ template_args={"ctx": ctx}
)
def test_multiline_control(self):