lib/epub/publication/package/manifest.rb in epub-parser-0.1.2 vs lib/epub/publication/package/manifest.rb in epub-parser-0.1.3
- old
+ new
@@ -1,7 +1,8 @@
require 'enumerabler'
require 'epub/constants'
+require 'epub/parser/content_document'
module EPUB
module Publication
class Package
class Manifest
@@ -12,13 +13,12 @@
@items ||= {}
item.manifest = self
@items[item.id] = item
end
- # syntax sugar
def navs
- items.selector {|i| i.properties.include? 'nav'}
+ items.selector(&:nav?)
end
def nav
navs.first
end
@@ -60,14 +60,18 @@
def read
rootfile = Addressable::URI.parse(manifest.package.book.ocf.container.rootfile.full_path)
Zip::Archive.open(manifest.package.book.epub_file) {|zip|
path = Addressable::URI.unescape(rootfile + href.normalize.request_uri)
- zip.fopen(path.to_s).read
+ zip.fopen(path).read
}
end
+ def nav?
+ properties.include? 'nav'
+ end
+
# @todo Handle circular fallback chain
def use_fallback_chain(options = {})
supported = EPUB::MediaType::CORE
if ad = options[:supported]
supported = supported | (ad.respond_to?(:to_ary) ? ad : [ad])
@@ -80,9 +84,14 @@
if (bindings = manifest.package.bindings) && (binding_media_type = bindings[media_type])
return yield binding_media_type.handler
end
return fallback.use_fallback_chain(options) {|fb| yield fb} if fallback
raise EPUB::MediaType::UnsupportedError
+ end
+
+ def content_document
+ return nil unless %w[application/xhtml+xml image/svg+xml].include? media_type
+ @content_document ||= Parser::ContentDocument.parse(self)
end
protected
def traverse_fallback_chain(chain)