Class: BbEPUB::Transform::Resources

Inherits:
Bookbinder::Transform
  • Object
show all
Defined in:
lib/bb-epub/transform/resources.rb

Instance Method Summary collapse

Instance Method Details

#dependenciesObject



3
4
5
# File 'lib/bb-epub/transform/resources.rb', line 3

def dependencies
  [BbEPUB::Transform::OPF]
end

#from_map(package) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bb-epub/transform/resources.rb', line 25

def from_map(package)
  return  unless package.map['resources']
  opf_doc = package.file(:opf).document
  manifest_tag = opf_doc.find('opf|manifest')
  package.map['resources'].each { |rsrc|
    opf_doc.new_node('item', :append => manifest_tag) { |manifest_item_tag|
      manifest_item_tag['href'] = package.make_href(rsrc['path'])
      manifest_item_tag['media-type'] = rsrc['media-type']
      manifest_item_tag['id'] = rsrc['id']
    }
  }
end

#to_map(package) ⇒ Object

Find all the items in the manifest – except all spine items, the NCX, and the NAV.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/bb-epub/transform/resources.rb', line 11

def to_map(package)
  opf_doc = package.file(:opf).document('r')
  items = opf_doc.search('opf|manifest > opf|item')
  package.map['resources'] = items.collect { |item|
    path = package.make_path(item['href'])
    {
      'path' => path,
      'media-type' => item['media-type'],
      'id' => item['id'] || package.make_id(path)
    }
  }
end