Class: EPUB::Publication::Package::Manifest
- Inherits:
-
Object
- Object
- EPUB::Publication::Package::Manifest
- Includes:
- ContentModel
- Defined in:
- lib/epub/maker/publication.rb
Defined Under Namespace
Classes: Item
Instance Method Summary collapse
- #make {|_self| ... } ⇒ Object
- #make_cover_image(options = {}) ⇒ Object
- #make_item(options = {}) {|item| ... } ⇒ Item
- #make_nav(options = {}) ⇒ Object
- #to_xml_fragment(xml) ⇒ Object
Methods included from ContentModel
Instance Method Details
#make {|_self| ... } ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/epub/maker/publication.rb', line 214 def make yield self if block_given? # @todo more careful unless items.any? &:nav? make_nav do |item, doc| doc.[0].items = items.select(&:xhtml?).collect {|i| nav = ContentDocument::::Item.new nav.item = i nav.href = i.href text = File.basename(i.href.normalize.request_uri, '.*') if i.content_file title = Parser::XMLDocument.new(File.read(i.content_file)).each_element_by_xpath("/xhtml:html/xhtml:head/xhtml:title", EPUB::NAMESPACES).first&.text text = title if title end nav.text = text nav } end end self end |
#make_cover_image(options = {}) ⇒ Object
260 261 262 263 264 265 |
# File 'lib/epub/maker/publication.rb', line 260 def make_cover_image(={}) make_item do |item| item.properties << 'cover-image' yield item if block_given? end end |
#make_item(options = {}) {|item| ... } ⇒ Item
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/epub/maker/publication.rb', line 239 def make_item(={}) item = Item.new [:id, :href, :media_type, :properties, :media_overlay].each do |attr| next unless .key? attr item.__send__ "#{attr}=", [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 |
#make_nav(options = {}) ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/epub/maker/publication.rb', line 267 def make_nav(={}) make_item do |item| item.id = "toc" item.href = Addressable::URI.parse("nav.xhtml") item.media_type = "application/xhtml+xml" item.properties << "nav" doc = ContentDocument::.new doc.item = item nav = ContentDocument::::.new nav.type = ContentDocument::::::Type::TOC doc. << nav yield [item, doc] if block_given? item.content = doc.to_xml end end |
#to_xml_fragment(xml) ⇒ Object
287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/epub/maker/publication.rb', line 287 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 |