-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.py
More file actions
58 lines (44 loc) · 2.09 KB
/
render.py
File metadata and controls
58 lines (44 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import template
class HTMLRender(object):
def _get_default_html_template(self):
#TODO have this in a separate file?
html = "<html>"
html += "{{ entries }}"
html += "</html>"
return html
def _render_content(self, content_dict):
html = ""
for content_type, content in content_dict.iteritems():
if template.Template.is_resource(content_type):
# TODO should this be done elsewhere? also, not readable at all
if "resource_dir" in content_dict:
content[0] = content_dict["resource_dir"][0] + "/" + content[0]
#TODO better content parsing
if content_type == "show":
html += "<img src=%s/>\n" % " ".join(content)
if content_type == "message":
html += "<p>%s</p>" % " ".join(content)
if content_type == "author":
html += "<p><b>%s</b></p>\n" % " ".join(content)
if content_type == "date":
html += "<p><i>%s</i></p>\n" % " ".join([str(d) for d in content])
if content_type == "command":
html += "<p><h2>%s</h2></p>\n" % " ".join([str(d) for d in content])
if content_type == "command_args":
html += "<p><h3>%s</h3></p>\n" % " ".join([str(d) for d in content])
return html
def render(self, log_entries, configs):
out = self._get_default_html_template()
entries_html = ""
for log_entry in log_entries:
if "command" not in log_entry.content_dict:
continue
#TODO better parsing of command name, remove ./ elsewhere
command = log_entry.content_dict["command"][0].strip("./")
template = configs.templates[command]
filtered_content = template.filter(log_entry.content_dict)
entries_html += self._render_content(filtered_content)
return out.replace("{{ entries }}", entries_html)
def get_renderer(renderer_type):
renderers = {"html":HTMLRender}
return renderers[renderer_type]()