Przeglądaj źródła

Merge pull request #818 from avaris/jinja_environment_fixes

Update plugins that use JINJA_ENTENSIONS to the Pelican 3.7 setting
Justin Mayer 7 lat temu
rodzic
commit
bddcce1e40

+ 4 - 1
assets/assets.py

@@ -32,7 +32,10 @@ except ImportError:
 def add_jinja2_ext(pelican):
     """Add Webassets to Jinja2 extensions in Pelican settings."""
 
-    pelican.settings['JINJA_ENVIRONMENT']['extensions'].append(AssetsExtension)
+    if 'JINJA_ENVIRONMENT' in pelican.settings: # pelican 3.7+
+        pelican.settings['JINJA_ENVIRONMENT']['extensions'].append(AssetsExtension)
+    else:
+        pelican.settings['JINJA_EXTENSIONS'].append(AssetsExtension)
 
 
 def create_assets_env(generator):

+ 1 - 1
assets/test_assets.py

@@ -68,7 +68,7 @@ class TestWebAssetsRelativeURLS(TestWebAssets):
         # Test that the Jinja2 extension was correctly added.
 
         from webassets.ext.jinja2 import AssetsExtension
-        self.assertIn(AssetsExtension, self.settings['JINJA_EXTENSIONS'])
+        self.assertIn(AssetsExtension, self.settings['JINJA_ENVIRONMENT']['extensions'])
 
     def test_compilation(self):
         # Compare the compiled css with the reference.

+ 7 - 1
i18n_subsites/i18n_subsites.py

@@ -270,7 +270,13 @@ def install_templates_translations(generator):
     Only if the 'jinja2.ext.i18n' jinja2 extension is enabled
     the translations for the current DEFAULT_LANG are installed.
     '''
-    if 'jinja2.ext.i18n' in generator.settings['JINJA_EXTENSIONS']:
+    if 'JINJA_ENVIRONMENT' in generator.settings: # pelican 3.7+
+        jinja_extensions = generator.settings['JINJA_ENVIRONMENT'].get(
+            'extensions', [])
+    else:
+        jinja_extensions = generator.settings['JINJA_EXTENSIONS']
+
+    if 'jinja2.ext.i18n' in jinja_extensions:
         domain = generator.settings.get('I18N_GETTEXT_DOMAIN', 'messages')
         localedir = generator.settings.get('I18N_GETTEXT_LOCALEDIR')
         if localedir is None:

+ 2 - 3
i18n_subsites/test_data/output/an-untranslated-article.html

@@ -9,7 +9,6 @@
 
 
 
-
 </head>
 
 <body id="index" class="home">
@@ -27,9 +26,9 @@
  
   </header>
   <footer class="post-info">
-    <abbr class="published" title="2014-07-14T00:00:00+00:00">
+    <time class="published" datetime="2014-07-14T00:00:00+00:00">
       Mon 14 July 2014
-    </abbr>
+    </time>
     <address class="vcard author">
       By           <a class="url fn" href="http://example.com/test/author/the-tester.html">The Tester</a>
     </address>

+ 2 - 3
i18n_subsites/test_data/output/cz/an-untranslated-article-en.html

@@ -9,7 +9,6 @@
 
 
 
-
 </head>
 
 <body id="index" class="home">
@@ -26,9 +25,9 @@
  
   </header>
   <footer class="post-info">
-    <abbr class="published" title="2014-07-14T00:00:00+00:00">
+    <time class="published" datetime="2014-07-14T00:00:00+00:00">
       Mon 14 July 2014
-    </abbr>
+    </time>
     <address class="vcard author">
       By           <a class="url fn" href="http://example.com/test/cz/author/test-testovic.html">Test Testovič</a>
     </address>

Plik diff jest za duży
+ 13 - 5
i18n_subsites/test_data/output/cz/feeds_all.atom.xml


+ 2 - 2
i18n_subsites/test_data/output/cz/index.html

@@ -21,7 +21,7 @@
         <li><article class="hentry">
                 <header> <h2 class="entry-title"><a href="http://example.com/test/cz/translated-article.html" rel="bookmark" title="Permalink to Přeložený článek">Přeložený článek</a></h2> </header>
                 <footer class="post-info">
-                    <abbr class="published" title="2014-09-15T00:00:00+00:00"> Mon 15 September 2014 </abbr>
+                    <time class="published" datetime="2014-09-15T00:00:00+00:00"> Mon 15 September 2014 </time>
                     <address class="vcard author">By
                         <a class="url fn" href="http://example.com/test/cz/author/test-testovic.html">Test Testovič</a>
                     </address>
@@ -33,7 +33,7 @@ Zde je odkaz na <a class="reference external" href="http://example.com/test/cz/.
         <li><article class="hentry">
                 <header> <h2 class="entry-title"><a href="http://example.com/test/cz/an-untranslated-article-en.html" rel="bookmark" title="Permalink to An untranslated article">An untranslated article</a></h2> </header>
                 <footer class="post-info">
-                    <abbr class="published" title="2014-07-14T00:00:00+00:00"> Mon 14 July 2014 </abbr>
+                    <time class="published" datetime="2014-07-14T00:00:00+00:00"> Mon 14 July 2014 </time>
                     <address class="vcard author">By
                         <a class="url fn" href="http://example.com/test/cz/author/test-testovic.html">Test Testovič</a>
                     </address>

+ 2 - 3
i18n_subsites/test_data/output/cz/translated-article.html

@@ -9,7 +9,6 @@
 
 
 
-
 </head>
 
 <body id="index" class="home">
@@ -29,9 +28,9 @@
 
   </header>
   <footer class="post-info">
-    <abbr class="published" title="2014-09-15T00:00:00+00:00">
+    <time class="published" datetime="2014-09-15T00:00:00+00:00">
       Mon 15 September 2014
-    </abbr>
+    </time>
     <address class="vcard author">
       By           <a class="url fn" href="http://example.com/test/cz/author/test-testovic.html">Test Testovič</a>
     </address>

+ 3 - 4
i18n_subsites/test_data/output/de/drafts/an-untranslated-article-en.html

@@ -9,7 +9,6 @@
 
 
 
-
 </head>
 
 <body id="index" class="home">
@@ -26,9 +25,9 @@
  
   </header>
   <footer class="post-info">
-    <abbr class="published" title="2014-07-14T00:00:00+00:00">
-      Mo 14 Juli 2014
-    </abbr>
+    <time class="published" datetime="2014-07-14T00:00:00+00:00">
+      Mon 14 July 2014
+    </time>
     <address class="vcard author">
       By           <a class="url fn" href="http://example.com/test/de/author/der-tester.html">Der Tester</a>
     </address>

Plik diff jest za duży
+ 10 - 4
i18n_subsites/test_data/output/de/feeds_all.atom.xml


+ 1 - 1
i18n_subsites/test_data/output/de/index.html

@@ -21,7 +21,7 @@
         <li><article class="hentry">
                 <header> <h2 class="entry-title"><a href="http://example.com/test/de/translated-article.html" rel="bookmark" title="Permalink to Ein übersetzter Artikel">Ein übersetzter Artikel</a></h2> </header>
                 <footer class="post-info">
-                    <abbr class="published" title="2014-09-14T00:00:00+00:00"> So 14 September 2014 </abbr>
+                    <time class="published" datetime="2014-09-14T00:00:00+00:00"> Sun 14 September 2014 </time>
                     <address class="vcard author">By
                         <a class="url fn" href="http://example.com/test/de/author/der-tester.html">Der Tester</a>
                     </address>

+ 3 - 4
i18n_subsites/test_data/output/de/translated-article.html

@@ -9,7 +9,6 @@
 
 
 
-
 </head>
 
 <body id="index" class="home">
@@ -29,9 +28,9 @@
 
   </header>
   <footer class="post-info">
-    <abbr class="published" title="2014-09-14T00:00:00+00:00">
-      So 14 September 2014
-    </abbr>
+    <time class="published" datetime="2014-09-14T00:00:00+00:00">
+      Sun 14 September 2014
+    </time>
     <address class="vcard author">
       By           <a class="url fn" href="http://example.com/test/de/author/der-tester.html">Der Tester</a>
     </address>

Plik diff jest za duży
+ 13 - 5
i18n_subsites/test_data/output/feeds_all.atom.xml


+ 2 - 2
i18n_subsites/test_data/output/index.html

@@ -22,7 +22,7 @@
         <li><article class="hentry">
                 <header> <h2 class="entry-title"><a href="http://example.com/test/translated-article.html" rel="bookmark" title="Permalink to A translated article">A translated article</a></h2> </header>
                 <footer class="post-info">
-                    <abbr class="published" title="2014-09-13T00:00:00+00:00"> Sat 13 September 2014 </abbr>
+                    <time class="published" datetime="2014-09-13T00:00:00+00:00"> Sat 13 September 2014 </time>
                     <address class="vcard author">By
                         <a class="url fn" href="http://example.com/test/author/the-tester.html">The Tester</a>
                     </address>
@@ -34,7 +34,7 @@ Here is a link to <a class="reference external" href="http://example.com/test/im
         <li><article class="hentry">
                 <header> <h2 class="entry-title"><a href="http://example.com/test/an-untranslated-article.html" rel="bookmark" title="Permalink to An untranslated article">An untranslated article</a></h2> </header>
                 <footer class="post-info">
-                    <abbr class="published" title="2014-07-14T00:00:00+00:00"> Mon 14 July 2014 </abbr>
+                    <time class="published" datetime="2014-07-14T00:00:00+00:00"> Mon 14 July 2014 </time>
                     <address class="vcard author">By
                         <a class="url fn" href="http://example.com/test/author/the-tester.html">The Tester</a>
                     </address>

+ 2 - 3
i18n_subsites/test_data/output/translated-article.html

@@ -9,7 +9,6 @@
 
 
 
-
 </head>
 
 <body id="index" class="home">
@@ -30,9 +29,9 @@
 
   </header>
   <footer class="post-info">
-    <abbr class="published" title="2014-09-13T00:00:00+00:00">
+    <time class="published" datetime="2014-09-13T00:00:00+00:00">
       Sat 13 September 2014
-    </abbr>
+    </time>
     <address class="vcard author">
       By           <a class="url fn" href="http://example.com/test/author/the-tester.html">The Tester</a>
     </address>

+ 1 - 1
i18n_subsites/test_data/pelicanconf.py

@@ -32,7 +32,7 @@ PLUGIN_PATHS = ['../../']
 PLUGINS = ['i18n_subsites']
 
 THEME = 'localized_theme'
-JINJA_EXTENSIONS = ['jinja2.ext.i18n']
+JINJA_ENVIRONMENT = {'extensions': ['jinja2.ext.i18n']}
 
 from blinker import signal
 tmpsig = signal('tmpsig')

+ 11 - 3
jinja2content/jinja2content.py

@@ -29,9 +29,17 @@ class JinjaMarkdownReader(MarkdownReader):
 
         loaders = [FileSystemLoader(_dir) for _dir
                    in local_dirs + [theme_dir]]
-        self.env = Environment(trim_blocks=True, lstrip_blocks=True,
-                               extensions=self.settings['JINJA_EXTENSIONS'],
-                               loader=ChoiceLoader(loaders))
+        if 'JINJA_ENVIRONMENT' in self.settings: # pelican 3.7
+            jinja_environment = self.setting['JINJA_ENVIRONMENT']
+        else:
+            jinja_environment = {
+                'trim_blocks': True,
+                'lstrip_blocks': True,
+                'extensions': self.settings['JINJA_EXTENSIONS']
+            }
+        self.env = Environment(
+            loader=ChoiceLoader(loaders),
+            **jinja_environment)
 
     def read(self, source_path):
         """Parse content and metadata of markdown files.