Class: EPUB::Publication::Package::Manifest

Inherits:
Object
  • Object
show all
Includes:
ContentModel
Defined in:
lib/epub/maker/publication.rb

Defined Under Namespace

Classes: Item

Instance Method Summary collapse

Methods included from ContentModel

#to_xml_attribute

Instance Method Details

#make {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/epub/maker/publication.rb', line 194

def make
  yield self if block_given?

  # @todo more careful
  unless items.any? &:nav?
    nav = Item.new
    nav.id = 'toc'
    nav.href = Addressable::URI.parse('nav.xhtml')
    nav.media_type = 'application/xhtml+xml'
    nav.properties << 'nav'

    nav_doc = ContentDocument::Navigation.new
    nav_doc.item = nav

    nav_nav = ContentDocument::Navigation::Navigation.new
    nav_nav.type = ContentDocument::Navigation::Navigation::Type::TOC
    nav_nav.items = items.select(&:xhtml?).map {|item; nav|
      nav = ContentDocument::Navigation::Item.new
      nav.item = item
      nav.href = item.href
      nav.text = File.basename(item.href.normalize.request_uri, '.*')
      nav
    }
    nav_doc.navigations << nav_nav

    nav.content = nav_doc.to_xml

    self << nav
  end

  self
end

#make_item(options = {}) {|item| ... } ⇒ Item

Yields:

  • (item)

Returns:



228
229
230
231
232
233
234
235
236
237
238
# File 'lib/epub/maker/publication.rb', line 228

def make_item(options={})
  item = Item.new
  [:id, :href, :media_type, :properties, :media_overlay].each do |attr|
    next unless options.key? attr
    item.__send__ "#{attr}=", options[attr]
  end
  item.manifest = self
  yield item if block_given?
  self << item
  item
end

#to_xml_fragment(xml) ⇒ Object



240
241
242
243
244
245
246
247
248
249
250
# File 'lib/epub/maker/publication.rb', line 240

def to_xml_fragment(xml)
  node = xml.manifest_ {
    items.each do |item|
      item_node = xml.item_
      to_xml_attribute item_node, item, [:id, :href, :media_type, :media_overlay]
      item_node['properties'] = item.properties.to_a.join(' ') unless item.properties.empty?
      item_node['fallback'] = item.fallback.id if item.fallback
    end
  }
  to_xml_attribute node, self, [:id]
end