summaryrefslogtreecommitdiff
path: root/tablib/formats/_html.py
diff options
context:
space:
mode:
Diffstat (limited to 'tablib/formats/_html.py')
-rw-r--r--tablib/formats/_html.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/tablib/formats/_html.py b/tablib/formats/_html.py
new file mode 100644
index 0000000..13dc055
--- /dev/null
+++ b/tablib/formats/_html.py
@@ -0,0 +1,53 @@
+# -*- coding: utf-8 -*-
+
+""" Tablib - HTML export support.
+"""
+
+from StringIO import StringIO
+
+from tablib.packages import markup
+import tablib
+
+BOOK_ENDINGS = 'h3'
+
+title = 'html'
+extentions = ('html', )
+
+
+def export_set(dataset):
+ """HTML representation of a Dataset."""
+
+ stream = StringIO()
+
+ page = markup.page()
+ page.table.open()
+
+ if dataset.headers is not None:
+ page.thead.open()
+ headers = markup.oneliner.th(dataset.headers)
+ page.tr(headers)
+ page.thead.close()
+
+ for row in dataset:
+ html_row = markup.oneliner.td(row)
+ page.tr(html_row)
+
+ page.table.close()
+
+ stream.writelines(str(page))
+
+ return stream.getvalue()
+
+
+def export_book(databook):
+ """HTML representation of a Databook."""
+
+ stream = StringIO()
+
+ for i, dset in enumerate(databook._datasets):
+ title = (dset.title if dset.title else 'Set %s' % (i))
+ stream.write('<%s>%s</%s>\n' % (BOOK_ENDINGS, title, BOOK_ENDINGS))
+ stream.write(dset.html)
+ stream.write('\n')
+
+ return stream.getvalue()