Class: BbEPUB::Transform::Spine
- Inherits:
-
Bookbinder::Transform
- Object
- Bookbinder::Transform
- BbEPUB::Transform::Spine
- Defined in:
- lib/bb-epub/transform/spine.rb
Instance Method Summary collapse
Instance Method Details
#dependencies ⇒ Object
3 4 5 |
# File 'lib/bb-epub/transform/spine.rb', line 3 def dependencies [BbEPUB::Transform::Resources] end |
#from_map(package) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/bb-epub/transform/spine.rb', line 24 def from_map(package) opf_doc = package.file(:opf).document package.map['spine'].each { |cmpt| # Convert component to valid XHTML cmpt_file = package.file(cmpt['path']) cmpt_doc = cmpt_file.document # Add the EPUB namespace: # FIXME: only add the EPUB namespace if there are any epub:* attrs? cmpt_doc.add_namespace('epub') # Update the OPF manifest opf_doc.new_node('item', :append => 'opf|manifest') { |manifest_item_tag| manifest_item_tag['href'] = package.make_href(cmpt['path']) manifest_item_tag['id'] = cmpt['id'] manifest_item_tag['media-type'] = cmpt['media-type'] props = component_properties(cmpt, cmpt_doc) manifest_item_tag['properties'] = props.join(' ') if props.any? } # Update the OPF spine opf_doc.new_node('itemref', :append => 'opf|spine') { |spine_item_tag| spine_item_tag['idref'] = cmpt['id'] spine_item_tag['linear'] = 'no' unless cmpt['linear'] } } end |
#to_map(package) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/bb-epub/transform/spine.rb', line 8 def to_map(package) opf_doc = package.file(:opf).document('r') itemrefs = opf_doc.search('opf|spine > opf|itemref') package.map['spine'] = itemrefs.collect { |itemref| cmpt = package.map['resources'].detect { |r| r['id'] == itemref['idref'] } if cmpt package.map['resources'].delete(cmpt) cmpt['linear'] = itemref['linear'] == 'no' ? false : true cmpt else package.warn("No manifest item for spine idref: #{itemref['idref']}") end }.compact end |