diff options
| author | 2014-10-21 10:33:17 -0300 | |
|---|---|---|
| committer | 2014-10-21 10:33:17 -0300 | |
| commit | 2d14c4b384c7000e264674a92b16e010a510ac05 (patch) | |
| tree | 7676db09f338e46e053170b1c9f7594120b9d434 /scripts/jinjify.py | |
| parent | 2d2e97ac540c94e15ac5eccc7d32f3dfb3eea1bc (diff) | |
| parent | 5ec02211214350ee558fd9f6bb052264fd24f75e (diff) | |
Merge tag 'upstream/7.1.0'
Upstream version 7.1.0
Diffstat (limited to 'scripts/jinjify.py')
| -rwxr-xr-x | scripts/jinjify.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/scripts/jinjify.py b/scripts/jinjify.py index 5f07032..be69731 100755 --- a/scripts/jinjify.py +++ b/scripts/jinjify.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -import codecs +import io import glob import sys import os @@ -11,7 +11,6 @@ import colorama import jinja2 dumb_replacements = [ - ["{% if isinstance(url, tuple) %}", "{% if url is mapping %}"], ["{% if any(post.is_mathjax for post in posts) %}", '{% if posts|selectattr("is_mathjax")|list %}'], ["json.dumps(title)", "title|tojson"], ["{{ parent.extra_head() }}", "{{ super() }}"], @@ -43,7 +42,7 @@ def jinjify(in_theme, out_theme): lookup.loader = jinja2.FileSystemLoader([out_templates_path], encoding='utf-8') for template in glob.glob(os.path.join(in_templates_path, "*.tmpl")): out_template = os.path.join(out_templates_path, os.path.basename(template)) - with codecs.open(template, "r", "utf-8") as inf: + with io.open(template, "r", encoding="utf-8") as inf: data = mako2jinja(inf) lines = [] @@ -56,7 +55,7 @@ def jinjify(in_theme, out_theme): for repl in dumber_replacements: data = data.replace(*repl) - with codecs.open(out_template, "wb+", "utf-8") as outf: + with io.open(out_template, "w+", encoding="utf-8") as outf: outf.write(data + '\n') # Syntax check output @@ -213,7 +212,16 @@ def mako2jinja(input_file): return output if __name__ == "__main__": - if len(sys.argv) != 3: - print('ERROR: needs exactly two arguments, input and output directory.') + if len(sys.argv) == 1: + print('Performing standard conversions:') + for m, j in ( + ('nikola/data/themes/base', 'nikola/data/themes/base-jinja'), + ('nikola/data/themes/bootstrap', 'nikola/data/themes/bootstrap-jinja'), + ('nikola/data/themes/bootstrap3', 'nikola/data/themes/bootstrap3-jinja') + ): + print(' {0} -> {1}'.format(m, j)) + jinjify(m, j) + elif len(sys.argv) != 3: + print('ERROR: needs input and output directory, or no arguments for default conversions.') else: jinjify(sys.argv[1], sys.argv[2]) |
