diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-08-03 13:08:17 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-08-03 13:08:17 -0400 |
commit | 404275485f5263e60591edd254a614c73b039562 (patch) | |
tree | 50d264f49c0744506ebfd05285aed045578e2db5 | |
parent | eee34a5419a8190b98d0854ce75a09ab8219b2c5 (diff) | |
download | mako-404275485f5263e60591edd254a614c73b039562.tar.gz |
- inline the loop here again
- add more of a test
-rw-r--r-- | mako/ext/babelplugin.py | 16 | ||||
-rw-r--r-- | test/templates/gettext.mako | 6 | ||||
-rw-r--r-- | test/test_babelplugin.py | 5 |
3 files changed, 16 insertions, 11 deletions
diff --git a/mako/ext/babelplugin.py b/mako/ext/babelplugin.py index fc869bb..e4feceb 100644 --- a/mako/ext/babelplugin.py +++ b/mako/ext/babelplugin.py @@ -76,12 +76,15 @@ def extract_nodes(nodes, keywords, comment_tags, options): elif isinstance(node, parsetree.PageTag): code = node.body_decl.code elif isinstance(node, parsetree.CallNamespaceTag): - attribs = [] - for key, val in node.attributes.items(): - if not val.startswith('${'): - val = "'%s'" % val - attribs.append('%s=%s' % (key, val)) - code = '{%s}' % ', '.join(attribs) + attribs = ', '.join(['%s=%s' % ( + key, + "'%s'" % val + if not val.startswith('${') + else val + ) + for key, val in node.attributes.items()]) + + code = '{%s}' % attribs child_nodes = node.nodes elif isinstance(node, parsetree.ControlLine): if node.isend: @@ -112,6 +115,7 @@ def extract_nodes(nodes, keywords, comment_tags, options): if not compat.py3k and isinstance(code, compat.text_type): code = code.encode('ascii', 'backslashreplace') + code = StringIO(code) for lineno, funcname, messages, python_translator_comments \ in extract_python(code, keywords, comment_tags, options): diff --git a/test/templates/gettext.mako b/test/templates/gettext.mako index 108e471..85a7d8f 100644 --- a/test/templates/gettext.mako +++ b/test/templates/gettext.mako @@ -40,7 +40,7 @@ top = gettext('Begin') ## TRANSLATOR: Good bye ${_('Goodbye')} </div> - + <%def name="makerow(row=_('Babel'), count=1)"> <!-- ${ungettext('hella', 'hellas', count)} --> % for i in range(count): @@ -73,14 +73,14 @@ top = gettext('Begin') <div id="end"> <a href="#top"> ## TRANSLATOR: you won't see this either - + ${_('Top')} </a> </div> <%def name="panel()"> -${_(u'foo')} <%self:block_tpl title="#123", name="_(u'baz')"> +${_(u'foo')} <%self:block_tpl title="#123", name="_('baz')" value="${_('hoho')}"> ${_(u'bar')} diff --git a/test/test_babelplugin.py b/test/test_babelplugin.py index b216bdb..6b867ee 100644 --- a/test/test_babelplugin.py +++ b/test/test_babelplugin.py @@ -6,13 +6,13 @@ try: from mako.ext.babelplugin import extract except: babel = None - + import os class ExtractMakoTestCase(TemplateTest): @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, @@ -37,6 +37,7 @@ class ExtractMakoTestCase(TemplateTest): (71, '_', 'P.S. byebye', []), (77, '_', 'Top', []), (83, '_', 'foo', []), + (83, '_', 'hoho', []), (85, '_', 'bar', []) ] self.assertEqual(expected, messages) |