Eclectic Media Git archived_em.space_site / d13c3a9
Adds jinja and markdown renderers to renderer Ariana Giroux 7 months ago
1 changed file(s) with 28 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
00 import os
11
22 from pystache import Renderer
3 from jinja2 import Environment, FileSystemLoader
4 from markdown import markdown
35
46 renderer = Renderer(search_dirs='templates', file_extension='stache')
57
6 def render(path, context={}):
7 if os.access(path, os.F_OK):
8 return renderer.render_path(path, context)
8
9 def render_index(**kwargs):
10 """ For jinja """
11 file_loader = FileSystemLoader('templates')
12 env = Environment(loader=file_loader)
13 template = env.get_template('index.jinja')
14
15 # Define data dictionaries
16 output = template.render(**kwargs)
17
18 return output
19
20
21 def render(path, context={}, **kwargs):
22 file_loader = FileSystemLoader('templates')
23 env = Environment(loader=file_loader)
24 template = env.get_template(path)
25 output = template.render(context, **kwargs)
26 return output
27
28
29 def render_markdown(path):
30 with open(path) as f:
31 content = f.read()
32
33 return markdown(content)