[Checkins] SVN: megrok.jinja/trunk/ * Update docs

Santiago Videla santiago.videla at gmail.com
Sat May 2 21:43:28 EDT 2009


Log message for revision 99676:
  * Update docs
  * The Environment it's created with auto_reload=True if Zope it's running in debug mode (not tested yet)
  
  

Changed:
  U   megrok.jinja/trunk/CHANGES.txt
  U   megrok.jinja/trunk/README.txt
  U   megrok.jinja/trunk/src/megrok/jinja/factory.py

-=-
Modified: megrok.jinja/trunk/CHANGES.txt
===================================================================
--- megrok.jinja/trunk/CHANGES.txt	2009-05-02 20:20:40 UTC (rev 99675)
+++ megrok.jinja/trunk/CHANGES.txt	2009-05-03 01:43:28 UTC (rev 99676)
@@ -1,7 +1,7 @@
 Changelog
 =========
 
-0.1 (unreleased)
+0.1 (2009-05-02)
 ----------------
 
-Initial import.
\ No newline at end of file
+Initial public release.
\ No newline at end of file

Modified: megrok.jinja/trunk/README.txt
===================================================================
--- megrok.jinja/trunk/README.txt	2009-05-02 20:20:40 UTC (rev 99675)
+++ megrok.jinja/trunk/README.txt	2009-05-03 01:43:28 UTC (rev 99676)
@@ -30,7 +30,7 @@
                       ],
 
 Then include megrok.jinja in your configure.zcml. It should look
-something like this:
+something like this::
 
     <configure xmlns="http://namespaces.zope.org/zope"
                xmlns:grok="http://namespaces.zope.org/grok">
@@ -47,36 +47,41 @@
 That's it. You can now place Jinja2 templates (with the `.jinja` extension)
 into any template directory used within your project.
 
-Extensions
-----------
+Jinja2 Environment
+------------------
 
-megrok.jinja defines two Jinja2 Extensions classes. For more information
-about Jinja2 Extensions visit:
+megrok.jinja create an Environment using `jinja2.ext.i18n` extension and overrides
+the globals variables `_` and `gettext` in order to use custom functions to resolve
+translations. It also set the global variable `provider` as a function to resolve
+the call to a content provider (viewlet manager).
 
-- http://jinja.pocoo.org/2/documentation/extensions
+For more information about Jinja2 Environment and Global variables visit:
 
+- http://jinja.pocoo.org/2/documentation/api#high-level-api
+- http://jinja.pocoo.org/2/documentation/api#the-global-namespace
+
 With the extensions added you are able to use
  - zope.i18n messages factory
  - content providers like viewlets
 
 To translate your templates, just register your translations domain and then
-you can write:
+you can write::
 
-{% set i18n_domain='test_domain' %}
+    {% set i18n_domain='test_domain' %}
 
-{{ _('some-msgid')}}
+    {{ _('some-msgid')}}
 
-Also it's possible to use the {%trans%} tag:
+Also it's possible to use the {%trans%} tag::
 
-{% set i18n_domain='test_domain' %}
+    {% set i18n_domain='test_domain' %}
 
-{% trans %}
-Whatever you may want to translate.
-{% endtrans %}
+    {% trans %}
+    Whatever you may want to translate.
+    {% endtrans %}
 
-If you want to call some content provider named 'manager', just write:
+If you want to call some content provider named 'manager', just write::
 
-{{ provider('manager') }}
+    {{ provider('manager') }}
 
 About `.json` extension and PyYAML
 ----------------------------------
@@ -93,7 +98,8 @@
 
 If you write this in a template with `.json` extension
 
-dicts :
+dicts ::
+
    - key1 : some_text
    - key2 : {{ 'Some Jinja2 expression' }}
      {% set l = ['3','4'] %}
@@ -101,7 +107,7 @@
    - {{ 'key-' + v }} : whatever {{ v }}
      {% endfor %}
 
-You will get the next JSON:
+You will get the next JSON::
 
      {"dicts": [{"key1": "some_text"},
                 {"key2": "Some Jinja2 expression"},
@@ -116,7 +122,7 @@
 
 If you write:
 
-view.py
+view.py::
 
     from zope import i18nmessageid
     _ = i18nmessageid.MessageFactory('some.domain')
@@ -124,21 +130,21 @@
     class Something(grok.View):
         def update(self):
             self.msg = _('Some msg id')
-view.jinja
 
+view.jinja::
+
     {{ view.msg }}
 
 You will always get 'Some msg id'.
+What you do could write is
 
-What you do could write is:
+view.py::
 
-view.py
-
     class Something(grok.View):
         def update(self):
             self.msg = 'Some msg id'
 
-view.jinja
+view.jinja::
 
     {% set i18n_domain='some.domain' %}
 

Modified: megrok.jinja/trunk/src/megrok/jinja/factory.py
===================================================================
--- megrok.jinja/trunk/src/megrok/jinja/factory.py	2009-05-02 20:20:40 UTC (rev 99675)
+++ megrok.jinja/trunk/src/megrok/jinja/factory.py	2009-05-03 01:43:28 UTC (rev 99676)
@@ -22,13 +22,15 @@
 from grokcore.view.components import GrokTemplate
 from grokcore.view.interfaces import ITemplate, ITemplateFileFactory
 
+from zope.app.applicationcontrol.runtimeinfo import RuntimeInfo
 # Create an Environment instance with the i18n extension
 # and the FileSystemLoader class loader that will look for
 # absolute path templates.
-# By default, auto_reload = True, for production system
-# should be set to False for higher performance
+
+#XXX passing in a None value here is a hack.
+in_dev_mode = RuntimeInfo(None).getDeveloperMode() == 'On'
 env = Environment(extensions=['jinja2.ext.i18n'],
-                  loader=FileSystemLoader('/'))
+                  loader=FileSystemLoader('/'), auto_reload=in_dev_mode)
 
 #Just set the functions used to resolve translations and
 #contents providers instead of full Extension classes



More information about the Checkins mailing list