new "easy" meta data handling for html output

This commit is contained in:
Fabian Graßl 2010-10-14 18:18:18 +02:00
parent 66602a84d7
commit 85ec5acd70
3 changed files with 47 additions and 8 deletions

View File

@ -7,17 +7,18 @@
<link rel="schema.DCTERMS" href="http://purl.org/dc/terms/" />
<title></title>
${for item_name in meta.items:}$
${for item in meta[item_name]:}$
${if namespace(item.term) == DC11_NS:}$
<meta ${print 'name="DC.'+barename(item.term)+'"',}$ ${print 'content="'+item.value+'"',}$ />
${:endif}$
${:endfor}$
${for item in meta:}$
<meta ${print 'name="DC.'+item['name']+'"',}$ ${print 'content="'+item['value']+'"',}$ />
${:endfor}$
</head>
<body>
${for title in meta.titles():}$
<h1>${print title}$</h1>
${:endfor}$
${print ', '.join(meta.creators())}$
<h1>Table of contents</h1>
${toc}$

View File

@ -0,0 +1,36 @@
from __future__ import with_statement
__license__ = 'GPL 3'
__copyright__ = '2010, Fabian Grassl <fg@jusmeum.de>'
__docformat__ = 'restructuredtext en'
import os, re
from os.path import dirname, abspath, relpath, exists, basename
from calibre.ebooks.oeb.base import element, namespace, barename, DC11_NS
class EasyMeta(object):
def __init__(self, meta):
self.meta = meta
def __iter__(self):
meta = self.meta
for item_name in meta.items:
for item in meta[item_name]:
if namespace(item.term) == DC11_NS:
yield { 'name': barename(item.term), 'value': item.value }
def __len__(self):
count = 0
for item in self:
count = count+1
return count
def titles(self):
for item in self.meta['title']:
yield item.value
def creators(self):
for item in self.meta['creator']:
yield item.value

View File

@ -1,6 +1,6 @@
from __future__ import with_statement
__license__ = 'GPL 3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__copyright__ = '2010, Fabian Grassl <fg@jusmeum.de>'
__docformat__ = 'restructuredtext en'
import os, re
@ -16,6 +16,8 @@ from calibre import CurrentDir
from urllib import unquote
from calibre.ebooks.html.meta import EasyMeta
class HTMLOutput(OutputFormatPlugin):
name = 'HTML Output'
@ -66,7 +68,7 @@ class HTMLOutput(OutputFormatPlugin):
html_toc = self.generate_html_toc(oeb_book, output_file, output_dir)
templite = Templite(P('templates/html_export_default_index.tmpl', data=True))
print oeb_book.metadata.items
t = templite.render(toc=html_toc, meta=oeb_book.metadata, namespace=lambda x:namespace(x), barename=lambda x:barename(x), DC11_NS=DC11_NS)
t = templite.render(toc=html_toc, meta=EasyMeta(oeb_book.metadata))
f.write(t)
with CurrentDir(output_dir):