diff options
| author | Kenneth Reitz <me@kennethreitz.com> | 2011-01-31 01:35:52 -0500 |
|---|---|---|
| committer | Kenneth Reitz <me@kennethreitz.com> | 2011-01-31 01:35:52 -0500 |
| commit | 26b6faa88d0c272f7f8153cbd2de6ce451e22caf (patch) | |
| tree | ef25c2f5969cfa88d4802243a588e753a2118834 /tablib/formats/_html.py | |
| parent | 7727171379683dcf859a344d6c8a43dc6d5cfa2b (diff) | |
| parent | 140736ff332ff164f18821ec150488b1a2092898 (diff) | |
| download | tablib-0.9.3.tar.gz | |
Merge branch 'release/0.9.3'v0.9.3
Diffstat (limited to 'tablib/formats/_html.py')
| -rw-r--r-- | tablib/formats/_html.py | 53 |
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() |
