Skip to content
Permalink
Browse files
Merge branch 'master' into fix-2205
  • Loading branch information
ralsina committed Jan 4, 2016
2 parents aaa8cb7 + 1b620db commit 3fdc49f8478b19eb9469cfc407a494377584cca3
Showing with 32 additions and 13 deletions.
  1. +1 −0 nikola/data/shortcodes/mako/raw.tmpl
  2. +17 −13 nikola/nikola.py
  3. +14 −0 scripts/jinjify.py
@@ -0,0 +1 @@
${data}
@@ -1297,19 +1297,23 @@ def url_replacer(self, src, dst, lang=None, url_type=None):
return result

def _register_templated_shortcodes(self):
"""Register shortcodes provided by templates in shortcodes/ folder."""
if not os.path.isdir('shortcodes'):
return
for fname in os.listdir('shortcodes'):
name, ext = os.path.splitext(fname)
if ext == '.tmpl':
with open(os.path.join('shortcodes', fname)) as fd:
template_data = fd.read()

def render_shortcode(t_data=template_data, **kw):
return self.template_system.render_template_to_string(t_data, kw)

self.register_shortcode(name, render_shortcode)
"""Register shortcodes provided by templates in shortcodes/ folders."""
builtin_sc_dir = resource_filename('nikola', os.path.join('data', 'shortcodes', utils.get_template_engine(self.THEMES)))
sc_dirs = [builtin_sc_dir, 'shortcodes']

for sc_dir in sc_dirs:
if not os.path.isdir(sc_dir):
continue
for fname in os.listdir(sc_dir):
name, ext = os.path.splitext(fname)
if ext == '.tmpl':
with open(os.path.join(sc_dir, fname)) as fd:
template_data = fd.read()

def render_shortcode(t_data=template_data, **kw):
return self.template_system.render_template_to_string(t_data, kw)

self.register_shortcode(name, render_shortcode)

def register_shortcode(self, name, f):
"""Register function f to handle shortcode "name"."""
@@ -216,6 +216,19 @@ 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)


if __name__ == "__main__":
if len(sys.argv) == 1:
print('Performing standard conversions:')
@@ -225,6 +238,7 @@ def mako2jinja(input_file):
):
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:

0 comments on commit 3fdc49f

Please sign in to comment.