From 01997af8b0c04318c2c76afc29eb043052e3d793 Mon Sep 17 00:00:00 2001 From: jantwisted Date: Wed, 16 Dec 2015 01:39:41 +0530 Subject: HTMLRender added --- lps_gen.py | 13 ++++++++++++- tests/files/index.html | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 tests/files/index.html diff --git a/lps_gen.py b/lps_gen.py index 657b030..a7690b2 100644 --- a/lps_gen.py +++ b/lps_gen.py @@ -19,6 +19,7 @@ # . import json +import jinja2 from argparse import ArgumentParser from collections import OrderedDict @@ -132,6 +133,15 @@ class LPSMarkdown(Markdown): html = super(LPSMarkdown, self).parse(text) return lps_dict +def HTMLRender(_dict): + + templateLoader = jinja2.FileSystemLoader( searchpath="./" ) + templateEnv = jinja2.Environment( loader=templateLoader ) + TEMPLATE_FILE = "tests/files/index.html" + template = templateEnv.get_template( TEMPLATE_FILE ) + _data = {'res':_dict} + outputText = template.render( _data ) + return outputText def main(): parser = ArgumentParser() @@ -143,8 +153,9 @@ def main(): markdown = LPSMarkdown() lps_dict = markdown(lps_md_content) + print HTMLRender(lps_dict) - print json.dumps(lps_dict, indent=4) + #print json.dumps(lps_dict, indent=4) if __name__ == "__main__": diff --git a/tests/files/index.html b/tests/files/index.html new file mode 100644 index 0000000..8dac6e0 --- /dev/null +++ b/tests/files/index.html @@ -0,0 +1,52 @@ + {% for key, value in res.iteritems() %} +
+
+

{{ key }} + +

+
+
+ +
+ {% for key2, value2 in value.iteritems() %} +
+
+
+

{{ key2 }}

+
+
+ {# conditional content #} + {% if value2|count > 0 %} +
+ {% for key3, value3 in value2.iteritems() %} +
+
+

{{ key3 }}

+
+ {{ value3['speaker'] }} + + +
+

{{ value3['room'] }}

+ +

{{ value3['desc'][0].decode('utf-8') }}

+
+
+
+ {% endfor %} + {% endif %} +
+ {% endfor %} +{% endfor %} -- cgit v1.2.3