gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-www] 03/03: make template compilation a LOT faster


From: gnunet
Subject: [GNUnet-SVN] [taler-www] 03/03: make template compilation a LOT faster
Date: Tue, 14 Feb 2017 21:09:45 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository www.

commit 197f0a626dc333a4956a541ce556abb87bda8b46
Author: Florian Dold <address@hidden>
AuthorDate: Tue Feb 14 21:07:41 2017 +0100

    make template compilation a LOT faster
    
    By not doing template parsing and starting the python interpreter every
    time, templating only takes about a second on my machine now.
---
 Makefile    |  2 +-
 template.py | 59 +++++++++++++++++++++++++++++++----------------------------
 template.sh | 17 -----------------
 3 files changed, 32 insertions(+), 46 deletions(-)

diff --git a/Makefile b/Makefile
index 24f3de5..2f39d06 100644
--- a/Makefile
+++ b/Makefile
@@ -33,4 +33,4 @@ locale: locale-update locale-compile
 # Run the jinga2 templating engine to expand templates to HTML
 # incorporating translations.
 template: locale-compile
-       ./template.sh
+       ./template.py
diff --git a/template.py b/template.py
index f872ad3..179e32a 100755
--- a/template.py
+++ b/template.py
@@ -8,45 +8,48 @@
 # Note that the gettext files need to be prepared first. This script
 # is thus to be invoked via the Makefile.
 import os
+import os.path
 import sys
 import re
 import gettext
 import jinja2
+import glob
+import codecs
 
-if len(sys.argv) < 3:
-    sys.exit("Usage: " + __file__ + " <template-file> <locale> <output-file>")
+env = 
jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
+                         extensions=["jinja2.ext.i18n"],
+                         autoescape=False)
 
-in_file = sys.argv[1]
-locale = sys.argv[2]
 
-name, ext = re.match(r"(.*)\.([^.]+)$", in_file.rstrip(".j2")).groups()
+for in_file in glob.glob("*.j2"):
+    name, ext = re.match(r"(.*)\.([^.]+)$", in_file.rstrip(".j2")).groups()
+    tmpl = env.get_template(in_file)
 
-tr = gettext.translation("messages",
-                         localedir="locale",
-                         languages=[locale])
+    def self_localized(other_locale):
+        """
+        Return URL for the current page in another locale.
+        """
+        return "../" + other_locale + "/" + in_file.rstrip(".j2")
 
-env = 
jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
-                         extensions=["jinja2.ext.i18n"],
-                         autoescape=False)
-env.install_gettext_translations(tr, newstyle=True)
+    def url_localized(filename):
+        return "../" + locale + "/" + filename
 
-tmpl = env.get_template(in_file)
+    def url(x):
+        # TODO: look at the app root environment variable
+        # TODO: check if file exists
+        return "../" + x
 
-def self_localized(other_locale):
-    """
-    Return URL for the current page in another locale.
-    """
-    return "../" + other_locale + "/" + in_file.rstrip(".j2")
+    for l in glob.glob("locale/*/"):
+        locale = os.path.basename(l[:-1])
 
-def url_localized(filename):
-    return "../" + locale + "/" + filename
+        tr = gettext.translation("messages",
+                                 localedir="locale",
+                                 languages=[locale])
 
-def url(x):
-    # TODO: look at the app root environment variable
-    # TODO: check if file exists
-    return "../" + x
+        env.install_gettext_translations(tr, newstyle=True)
 
-import codecs
-f = codecs.open("./" + locale + "/" + in_file.rstrip(".j2"), "w", "utf-8")
-f.write(tmpl.render(lang=locale, url=url, self_localized=self_localized, 
url_localized=url_localized))
-f.close()
+
+        content = tmpl.render(lang=locale, url=url, 
self_localized=self_localized, url_localized=url_localized)
+        out_name = "./" + locale + "/" + in_file.rstrip(".j2")
+        with codecs.open(out_name, "w", "utf-8") as f:
+            f.write(content)
diff --git a/template.sh b/template.sh
deleted file mode 100755
index 040f3a0..0000000
--- a/template.sh
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/bin/sh
-# This file is in the public domain.
-#
-# Wrapper around 'template.py', running it on all
-# of our jinja2 input files for all languages for which
-# we have translations.
-#
-# Note that the gettext files need to be prepared first. This script
-# is thus to be invoked via the Makefile.
-for f in $(git ls-files *.j2); do
-    for ld in locale/*/; do
-       l=$(basename $ld)
-        mkdir -p $(basename $l)
-       echo "$f: $l"
-       python template.py $f $l
-    done
-done

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]