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:



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/epub/maker/publication.rb', line 212

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:



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/epub/maker/publication.rb', line 246

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?
  unless item.media_type
    path = item.href.to_s
    item.media_type =
      if path.end_with? ".html"
        "application/xhtml+xml"
      else
        MimeMagic.by_path(item.href.to_s).type
      end
  end
  self << item
  item
end

#to_xml_fragment(xml) ⇒ Object



267
268
269
270
271
272
273
274
275
276
277
# File 'lib/epub/maker/publication.rb', line 267

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