Skip to content

Commit

Permalink
#13 Item in spine could have flag linear
Browse files Browse the repository at this point in the history
  • Loading branch information
aerkalov committed May 9, 2013
1 parent f0cb9a0 commit d70570f
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions ebooklib/epub.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ def parse_string(s):

return tree

def debug(obj):
import pprint

pp = pprint.PrettyPrinter(indent=4)
pp.pprint(obj)


## TOC elements

class Section(object):
Expand Down Expand Up @@ -118,6 +125,7 @@ def __init__(self, uid=None, file_name='', media_type='', content=''):
self.file_name = file_name
self.media_type = media_type
self.content = content
self.is_linear = True

self.book = None

Expand Down Expand Up @@ -240,6 +248,7 @@ def __init__(self, uid='cover', file_name='cover.xhtml', image_name=''):
super(EpubCoverHtml, self).__init__(uid=uid, file_name=file_name)

self.image_name = image_name
self.is_linear = False

def get_content(self):
tree = parse_string(self.book.get_template('cover'))
Expand Down Expand Up @@ -497,11 +506,25 @@ def _write_opf_file(self):
if len(item.properties) > 0:
opts['properties'] = ' '.join(item.properties)

etree.SubElement(spine, 'itemref', opts)
if not item.is_linear:
opts['linear'] = 'no'
elif isinstance(item, EpubItem):
etree.SubElement(spine, 'itemref', {'idref': item.get_id()})
opts = {'idref': item.get_id()}

if not item.is_linear:
opts['linear'] = 'no'
else:
etree.SubElement(spine, 'itemref', {'idref': item})
opts = {'idref': item}

try:
itm = self.book.get_item_with_id(item)

if not itm.is_linear:
opts['linear'] = 'no'
except:
pass

etree.SubElement(spine, 'itemref', opts)

# GUIDE
# guide = etree.SubElement(root, 'guide', {})
Expand Down Expand Up @@ -728,10 +751,7 @@ def add_item(ns, tag, value, extra):

self.book.metadata = nsdict

# import pprint
# pp = pprint.PrettyPrinter(indent=4)
# pp.pprint(self.book.metadata)

# debug(self.book.metadata)

def _load_manifest(self):
for r in self.container.find('{%s}%s' % (NAMESPACES['OPF'], 'manifest')):
Expand Down Expand Up @@ -803,10 +823,7 @@ def _get_children(elems, n, nid):


self.book.toc = _get_children(nav_map, 0, '')
# import pprint
# pp = pprint.PrettyPrinter(indent=4)
# pp.pprint(self.book.toc)

# debug(self.book.toc)

def _load_spine(self):
spine = self.container.find('{%s}%s' % (NAMESPACES['OPF'], 'spine'))
Expand Down

0 comments on commit d70570f

Please sign in to comment.