diff options
| author | 2016-11-15 14:18:53 -0300 | |
|---|---|---|
| committer | 2016-11-15 14:18:53 -0300 | |
| commit | 1ad5102b7ddd181bb9c632b124d3ea4c7db28be6 (patch) | |
| tree | 73dda18465d0f4b8eb52d4482282a387c9f67c95 /scripts/jinjify.py | |
| parent | b67294f76809a681ff73f209ed691a3e3f00563d (diff) | |
| parent | ffb671c61a24a9086343b54bad080e145ff33fc5 (diff) | |
Merge tag 'upstream/7.8.1'
Upstream version 7.8.1
# gpg: Firmado el mar 15 nov 2016 14:18:48 ART
# gpg: usando RSA clave A6C7B88B9583046A11C5403E0B00FB6CEBE2D002
# gpg: Firma correcta de "Ulises Vitulli <dererk@debian.org>" [absoluta]
# gpg: alias "Dererk <dererk@torproject.org>" [absoluta]
# gpg: alias "Ulises Vitulli <uvitulli@fi.uba.ar>" [absoluta]
# gpg: alias "Ulises Vitulli <dererk@satellogic.com>" [absoluta]
Diffstat (limited to 'scripts/jinjify.py')
| -rwxr-xr-x | scripts/jinjify.py | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/scripts/jinjify.py b/scripts/jinjify.py index abd18e9..8f14323 100755 --- a/scripts/jinjify.py +++ b/scripts/jinjify.py @@ -6,6 +6,7 @@ import os import re import json import shutil +import tempfile import colorama import jinja2 @@ -14,6 +15,7 @@ dumb_replacements = [ ["{% if any(post.is_mathjax for post in posts) %}", '{% if posts|selectattr("is_mathjax")|list %}'], ["json.dumps(title)", "title|tojson"], ["{{ parent.extra_head() }}", "{{ super() }}"], + ["{{ parent.content() }}", "{{ super() }}"], ["prefix='\\", "prefix='"], ["og: http://ogp.me/ns# \\", "og: http://ogp.me/ns#"], ["article: http://ogp.me/ns/article# \\", "article: http://ogp.me/ns/article#"], @@ -215,6 +217,24 @@ def mako2jinja(input_file): return output + +def jinjify_shortcodes(in_dir, out_dir): + for fname in os.listdir(in_dir): + if not fname.endswith('.tmpl'): + continue + in_file = os.path.join(in_dir, fname) + out_file = os.path.join(out_dir, fname) + with open(in_file) as inf: + data = mako2jinja(inf) + with open(out_file, 'w') as outf: + outf.write(data) + + +def usage(): + print("Usage: python {} [in-dir] [out-dir]".format(sys.argv[0])) + print("OR") + print("Usage: python {} [in-file] [out-file]".format(sys.argv[0])) + if __name__ == "__main__": if len(sys.argv) == 1: print('Performing standard conversions:') @@ -224,7 +244,20 @@ if __name__ == "__main__": ): print(' {0} -> {1}'.format(m, j)) jinjify(m, j) + jinjify_shortcodes('nikola/data/shortcodes/mako', 'nikola/data/shortcodes/jinja') elif len(sys.argv) != 3: - print('ERROR: needs input and output directory, or no arguments for default conversions.') - else: + print('ERROR: needs input and output directory (file), or no arguments for default conversions.') + usage() + elif os.path.isdir(sys.argv[1]) and (os.path.isdir(sys.argv[2]) or not os.path.exists(sys.argv[2])): jinjify(sys.argv[1], sys.argv[2]) + elif os.path.isfile(sys.argv[1]) and (os.path.isfile(sys.argv[2]) or not os.path.exists(sys.argv[2])): + tmpdir = tempfile.mkdtemp() + indir = os.path.sep.join((tmpdir, 'in', 'templates')) + outdir = os.path.sep.join((tmpdir, 'out', 'templates')) + os.makedirs(indir) + shutil.copy(sys.argv[1], indir) + jinjify(os.path.dirname(indir), os.path.dirname(outdir)) + shutil.move(os.path.sep.join((outdir, os.path.basename(sys.argv[1]))), sys.argv[2]) + else: + print('ERROR: the two arguments must be both directories or files') + usage() |
