generate msg-only html
This commit is contained in:
+32
-6
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: UTF-8 -*-
|
||||
# File: Render.py
|
||||
# Date: Sat Nov 22 22:29:56 2014 +0800
|
||||
# File: render.py
|
||||
# Date: Sat Nov 22 23:24:10 2014 +0800
|
||||
# Author: Yuxin Wu <[email protected]>
|
||||
|
||||
import os
|
||||
@@ -9,16 +9,42 @@ LIB_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||
CSS_FILE = os.path.join(LIB_PATH, 'static/wx.css')
|
||||
HTML_FILE = os.path.join(LIB_PATH, 'static/template.html')
|
||||
|
||||
try:
|
||||
from csscompressor import compress as css_compress
|
||||
except:
|
||||
css_compress = lambda x: x
|
||||
|
||||
from .msg import *
|
||||
from .utils import ensure_unicode
|
||||
|
||||
TEMPLATES_FILES = {TYPE_MSG: "TP_MSG"}
|
||||
TEMPLATES = dict([(k, open(os.path.join(
|
||||
LIB_PATH, 'static/{}.html'.format(v))).read())
|
||||
for k, v in TEMPLATES_FILES.iteritems()])
|
||||
|
||||
|
||||
|
||||
class HTMLRender(object):
|
||||
def __init__(self, res=None):
|
||||
self.css = open(CSS_FILE).read().replace('\n', '')
|
||||
self.html = open(HTML_FILE).read()
|
||||
self.css = ensure_unicode(css_compress(open(CSS_FILE).read()))
|
||||
self.html = ensure_unicode(open(HTML_FILE).read())
|
||||
self.res = res
|
||||
|
||||
def render_msg(self, msg):
|
||||
""" render a message"""
|
||||
""" render a message, return the block"""
|
||||
# TODO
|
||||
pass
|
||||
#template = ensure_unicode(TEMPLATES[msg.type])
|
||||
template = ensure_unicode(TEMPLATES[1])
|
||||
if False:
|
||||
return ""
|
||||
else:
|
||||
return template.format(sender_label='you' if not msg.isSend else 'me',
|
||||
content=msg.msg_str())
|
||||
|
||||
def render_msgs(self, msgs):
|
||||
blocks = [self.render_msg(m) for m in msgs]
|
||||
return self.html.format(style=self.css, talker=msgs[0].talker_name,
|
||||
messages=u''.join(blocks))
|
||||
|
||||
if __name__ == '__main__':
|
||||
r = HTMLRender()
|
||||
|
||||
Reference in New Issue
Block a user