2014-11-21 10:41:29 +01:00
|
|
|
|
2014-11-20 16:31:00 +01:00
|
|
|
def createPage(display, filename, title):
|
|
|
|
page = {}
|
|
|
|
page['title'] = title;
|
|
|
|
page['blocks'] = []
|
|
|
|
display[filename] = page
|
|
|
|
|
|
|
|
return page
|
|
|
|
|
|
|
|
def appendBlockToPage(page, block):
|
|
|
|
page['blocks'].append(block)
|
|
|
|
|
|
|
|
def createTable(title, cols):
|
|
|
|
table = {'type' : 'table', 'title' : title}
|
|
|
|
table['cols'] = cols
|
|
|
|
table['rows'] = []
|
|
|
|
|
2014-11-21 10:41:29 +01:00
|
|
|
return table
|
|
|
|
|
2014-11-20 16:31:00 +01:00
|
|
|
def appendRowToTable(table, row):
|
|
|
|
table['rows'].append(row)
|
|
|
|
|
2014-11-21 10:41:29 +01:00
|
|
|
def buildTable(block, f):
|
|
|
|
print 'Write table %s' % block['title']
|
|
|
|
f.write('<table>')
|
|
|
|
f.write('<tr>')
|
|
|
|
for title in block['cols']:
|
|
|
|
f.write('<th>%s</th>' % (title))
|
|
|
|
f.write('</tr>')
|
|
|
|
for row in block['rows']:
|
|
|
|
f.write('<tr>')
|
|
|
|
for v in row:
|
|
|
|
f.write('<td>%s</td>' % (v))
|
|
|
|
f.write('</tr>')
|
|
|
|
f.write('</table>')
|
|
|
|
|
|
|
|
def buildPages(display_root, display):
|
2014-11-20 16:31:00 +01:00
|
|
|
for filename in display.keys():
|
|
|
|
page = display[filename]
|
2014-11-21 10:41:29 +01:00
|
|
|
print "OPEN %s" % (display_root + filename)
|
|
|
|
with open(display_root + filename, 'w') as f:
|
2014-11-20 16:31:00 +01:00
|
|
|
f.write('<html><title>%s</title><body>' % (page['title']))
|
|
|
|
for block in page['blocks']:
|
2014-11-21 10:41:29 +01:00
|
|
|
print "Bluid block"
|
|
|
|
print block
|
|
|
|
print "End block"
|
2014-11-20 16:31:00 +01:00
|
|
|
if block['type'] == 'html':
|
|
|
|
f.write(block['value'])
|
|
|
|
elif block['type'] == 'table':
|
2014-11-21 10:41:29 +01:00
|
|
|
buildTable(block, f)
|
2014-11-20 16:31:00 +01:00
|
|
|
f.write('</body></html>')
|