Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ship v0.7.9

  • Loading branch information...
commit 8b1b1e5c141f2c39a78d5f8678e9d2dfcf6c52bd 2 parents dc6e40c + ecdb84a
@avanov authored
View
3  CHANGES
@@ -5,6 +5,9 @@ Changelog
Version 0.7
------------
+- 0.7.9
+ Added babel message extraction plugin.
+
- 0.7.8
Expanded range of possible numeric values that don't require double-quoting.
View
2  docs/conf.py
@@ -50,7 +50,7 @@
# The short X.Y version.
version = '0.7'
# The full version, including alpha/beta/rc tags.
-release = '0.7.8'
+release = '0.7.9'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
View
23 plim/adapters/babelplugin.py
@@ -0,0 +1,23 @@
+"""gettext message extraction via Babel: http://babel.edgewall.org/"""
+from mako.ext.babelplugin import extract as _extract_mako
+
+from .. import lexer
+from ..util import StringIO
+
+
+
+def extract(fileobj, keywords, comment_tags, options):
+ """Extract messages from Plim templates.
+
+ :param fileobj: the file-like object the messages should be extracted from
+ :param keywords: a list of keywords (i.e. function names) that should be
+ recognized as translation functions
+ :param comment_tags: a list of translator tags to search for and include
+ in the results
+ :param options: a dictionary of additional options (optional)
+ :return: an iterator over ``(lineno, funcname, message, comments)`` tuples
+ :rtype: ``iterator``
+ """
+ fileobj = StringIO(lexer.compile_plim_source(fileobj))
+ for extracted in _extract_mako(fileobj, keywords, comment_tags, options):
+ yield extracted
View
4 plim/lexer.py
@@ -133,7 +133,7 @@
BOOLEAN_ATTRIBUTE_MARKER
)
-ATTRIBUTE_VALUE_WITH_PARENTHESES_TERMINATORS = (
+ATTRIBUTE_VALUE_TERMINATORS_WITH_PARENTHESES = (
ATTRIBUTES_DELIMITER,
INLINE_TAG_SEPARATOR,
LITERAL_CONTENT_PREFIX,
@@ -389,7 +389,7 @@ def extract_tag_attribute(line, source, parentheses=False):
# 3. Try to parse dynamic value
# -------------------------------------
if parentheses:
- result = extract_dynamic_attr_value(tail, source, ATTRIBUTE_VALUE_WITH_PARENTHESES_TERMINATORS)
+ result = extract_dynamic_attr_value(tail, source, ATTRIBUTE_VALUE_TERMINATORS_WITH_PARENTHESES)
else:
result = extract_dynamic_attr_value(tail, source, ATTRIBUTE_VALUE_TERMINATORS)
View
3  setup.py
@@ -11,11 +11,12 @@
setup(
name='Plim',
- version='0.7.8',
+ version='0.7.9',
packages=find_packages(exclude=['tests']),
# Plim is a preprocessor for Mako template language.
# But it doesn't depend on the Mako package itself.
install_requires=[
+ 'Mako>=0.7.0',
# We use reStructuredText (docutils' component) for both supporting
# the "-rest" extension and project documenting. So, ensure that the docutils
# get installed or upgraded on the target machine
View
0  tests/adapters/__init__.py
No changes.
View
27 tests/adapters/test_babelplugin.py
@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+from plim.adapters.babelplugin import extract
+from .. import TestCaseBase
+
+
+
+class TestBabelPlugin(TestCaseBase):
+
+ def test_babel_extractor(self):
+ fileobj = self.get_file_contents('babelplugin_test.html')
+ keywords = ['_', 'gettext', 'ungettext', 'pluralize']
+ extracted = [(data[1], data[2]) for data in extract(fileobj, keywords, None, {})]
+
+ assert ('_', 'Test') in extracted
+ assert ('_', 'View more') in extracted
+
+ assert ('pluralize', ('${num} conversation has been marked as read.',
+ '${num} conversations have been marked as read.',
+ None, None)) in extracted
+ assert ('ungettext', ('{num} conversation has been marked as read.',
+ '{num} conversations have been marked as read.',
+ None)) in extracted
+
+ assert ('gettext', 'N') not in extracted
+
+
View
34 tests/fixtures/babelplugin_test.html
@@ -0,0 +1,34 @@
+-inherit ../_layouts/960.html
+-def test_def(test=_('Test'))
+ = pluralize(
+ '${num} conversation has been marked as read.',
+ '${num} conversations have been marked as read.',
+ msgs_num, mapping=dict(num=msgs_num))
+ = ungettext(
+ '{num} conversation has been marked as read.',
+ '{num} conversations have been marked as read.',
+ msgs_num).format(num=msgs_num)
+
+#mosaic
+ div style="float:none;clear:both"
+
+ #latest-tabs
+ div style="width:650px;background:#EFEFEF;padding:10px 0 10px 0"
+ a.active href="#" = _('News')
+ a href="#" = _('Articles')
+ a href="#" = _('Videos')
+
+ .more: a href="#" ${_('View more')} ▸
+
+
+ h2.block-title = _('Recent comments')
+ #comments.block-ct
+ .block-tabs
+ a.active href="#" = _('News')
+ a href="#" = _('Previews')
+ a href="#" = _('Reviews')
+ a href="#" = _('Videos')
+ a href="#" = _('Blogs')
+
+ .more: a href="#" ${_('View more')} ▸
+
View
2  tests/test_lexer.py
@@ -185,7 +185,7 @@ def test_scan_line(self):
def test_extract_dynamic_attr_value(self):
- for terminators in (l.ATTRIBUTE_VALUE_WITH_PARENTHESES_TERMINATORS, l.ATTRIBUTE_VALUE_TERMINATORS):
+ for terminators in (l.ATTRIBUTE_VALUE_TERMINATORS_WITH_PARENTHESES, l.ATTRIBUTE_VALUE_TERMINATORS):
source = l.enumerate_source('')
value, tail, _ = l.extract_dynamic_attr_value("(value in func('test') and 'yes' or 'no')", source, terminators)
assert value == "value in func('test') and 'yes' or 'no'"
Please sign in to comment.
Something went wrong with that request. Please try again.