Permalink
Browse files

Added documentation and test for the newstyle gettext option

  • Loading branch information...
1 parent 7ba0319 commit 938e34123d7b971c021f312b15f428bdc2fd5e54 tulpe committed Dec 7, 2012
Showing with 36 additions and 2 deletions.
  1. +1 −1 CHANGES.txt
  2. +10 −0 docs/index.rst
  3. +1 −1 pyramid_jinja2/__init__.py
  4. +24 −0 pyramid_jinja2/tests/test_it.py
View
@@ -1,7 +1,7 @@
1.6 (unreleased)
================
-- Nothing changed yet.
+- Add `jinja2.newstyle` setting to enable newstyle gettext calls
1.5 (2012-11-24)
View
@@ -407,6 +407,16 @@ temporary directory. See :py:class:`jinja2.FileSystemBytecodeCache`.
strategy (such as cron) to check and remove such files.
+.. _setting_jinja2_newstyle:
+
+jinja2.newstyle
+-----------------------
+
+``true`` or ``false`` to enable the use of newstyle gettext calls. Defaults to
+``false``.
+
+See `Newstyle Gettext <http://jinja.pocoo.org/docs/extensions/#newstyle-gettext>`
+
.. _jinja2_filters:
Jinja2 Filters
@@ -295,7 +295,7 @@ def _get_or_build_default_environment(registry):
# clear cache on exit
atexit.register(kw['bytecode_cache'].clear)
- # use newstyle gettext calls (http://jinja.pocoo.org/docs/extensions/#newstyle-gettext)
+ # should newstyle gettext calls be enabled?
newstyle = asbool(settings.get('jinja2.newstyle', False))
environment = Environment(loader=loader,
@@ -517,6 +517,30 @@ def stack(self):
self.assertEqual(pf.caller_package(), xml)
+class TestNewstyle(unittest.TestCase):
+ def test_it(self):
+ from pyramid.config import Configurator
+ from pyramid_jinja2 import includeme
+ from webtest import TestApp
+ import os
+
+ here = os.path.abspath(os.path.dirname(__file__))
+ templates_dir = os.path.join(here, 'templates')
+
+ def myview(request):
+ return {'what': 'eels'}
+
+ config = Configurator(settings={
+ 'jinja2.directories': templates_dir,
+ 'jinja2.newstyle': True})
+ includeme(config)
+ config.add_view(view=myview, renderer='newstyle.jinja2')
+
+ app = config.make_wsgi_app()
+ testapp = TestApp(app)
+ self.assertEqual(testapp.get('/').body, text_('my hovercraft is full of eels!', 'utf-8'))
+
+
class MiscTests(Base, unittest.TestCase):
def test_add_jinja2_extension(self):

0 comments on commit 938e341

Please sign in to comment.