Skip to content

Commit

Permalink
Merge branch 'master' into fix-2205
Browse files Browse the repository at this point in the history
  • Loading branch information
ralsina committed Jan 4, 2016
2 parents aaa8cb7 + 1b620db commit 3fdc49f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
1 change: 1 addition & 0 deletions nikola/data/shortcodes/mako/raw.tmpl
@@ -0,0 +1 @@
${data}
30 changes: 17 additions & 13 deletions nikola/nikola.py
Expand Up @@ -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"."""
Expand Down
14 changes: 14 additions & 0 deletions scripts/jinjify.py
Expand Up @@ -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:')
Expand All @@ -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:
Expand Down

0 comments on commit 3fdc49f

Please sign in to comment.