Class: Bookbinder::Transform::EPUB_CoverPage

Inherits:
Bookbinder::Transform show all
Defined in:
lib/bookbinder/transform/epub/cover_page.rb

Instance Method Summary collapse

Instance Method Details

#dependenciesObject



3
4
5
# File 'lib/bookbinder/transform/epub/cover_page.rb', line 3

def dependencies
  [Bookbinder::Transform::EPUB_Spine]
end

#from_map(package) ⇒ Object

Do nothing unless we have a map[‘landmark’] type=‘cover’.

In the Nav (if it exists), create a landmark with an epub:type of ‘cover’. Actually, don’t – let the landmarks feature handle this.

In the OPF, create a <guide> element if it doesn’t exist, and create a <reference type=“cover” title=“Cover” href=“…”> tag within it.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/bookbinder/transform/epub/cover_page.rb', line 51

def from_map(package)
  return  unless package.map['nav'] && package.map['nav']['landmarks']
  cover_page_item = package.map['nav']['landmarks'].detect { |item|
    item['type'] == 'cover'
  }
  return  unless cover_page_item

  opf_doc = package.file(:opf).document
  unless guide_tag = opf_doc.find('opf|guide')
    guide_tag = opf_doc.new_node('guide', :append => opf_doc.root)
  end

  opf_doc.new_node('reference', :append => guide_tag) { |ref_tag|
    ref_tag['type'] = 'cover'
    ref_tag['href'] = package.make_href(cover_page_item['path'])
    ref_tag['title'] = cover_page_item['title']
  }
end

#to_map(package) ⇒ Object

A: look in the Nav (if it exists) for a landmark li with an epub:type of ‘cover’, and find the spine item with that href.

B: look for an OPF <guide><reference type=“cover”> and find the spine item with the same href.

C: look at the first spine item:

- is it have /cover/ in the filename?
- no? does it have an image and no body text?
- no? does it have an svg and no body text?

-> If found, add to map[‘landmarks’] with a ‘type’ of ‘cover’.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bookbinder/transform/epub/cover_page.rb', line 22

def to_map(package)
  cover_page_item =
    cover_page_item_from_nav(package) ||
    cover_page_item_from_opf_guide(package) ||
    cover_page_item_from_first_spine_item(package)

  if cover_page_item
    package.map['nav'] ||= {}
    package.map['nav']['landmarks'] ||= []
    package.map['nav']['landmarks'].unshift(cover_page_item)
    package.map['spine'].each { |item|
      if item['path'] == cover_page_item['path']
        item['linear'] = false
      end
    }
  end
end