Skip to content
Permalink
Browse files

system-wide shortcode support

  • Loading branch information
ralsina committed Dec 24, 2015
1 parent 7a97475 commit ce07d6b81e93b0c110cee09e62a7ae0383dad4f4
Showing with 18 additions and 13 deletions.
  1. +18 −13 nikola/nikola.py
@@ -1294,19 +1294,24 @@ 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]
if os.path.isdir('shortcodes'):
sc_dirs.append('shortcodes')

for sc_dir in sc_dirs:
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"."""

0 comments on commit ce07d6b

Please sign in to comment.
You can’t perform that action at this time.