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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contentObject

Returns the value of attribute content.



280
281
282
# File 'lib/epub/maker/publication.rb', line 280

def content
  @content
end

#content_fileObject

Returns the value of attribute content_file.



280
281
282
# File 'lib/epub/maker/publication.rb', line 280

def content_file
  @content_file
end

Instance Method Details

#editObject

Save document into EPUB archive when block ended



302
303
304
305
# File 'lib/epub/maker/publication.rb', line 302

def edit
  yield if block_given?
  save
end

#edit_with_nokogiri {|Nokgiri::XML::Document| ... } ⇒ Object

Save document into EPUB archive at end of block

Yields:

  • (Nokgiri::XML::Document)


319
320
321
322
323
324
# File 'lib/epub/maker/publication.rb', line 319

def edit_with_nokogiri
  doc = Nokogiri.XML(read)
  yield doc if block_given?
  self.content = doc.to_xml
  save
end

#edit_with_rexml {|REXML::Document| ... } ⇒ Object

Save document into EPUB archive at end of block

Yields:

  • (REXML::Document)


309
310
311
312
313
314
315
# File 'lib/epub/maker/publication.rb', line 309

def edit_with_rexml
  require 'rexml/document'
  doc = REXML::Document.new(read)
  yield doc if block_given?
  self.content = doc.to_s
  save
end

#saveObject

TODO:

Don’t read content from file when content_file exists. If container adapter is Archive::Zip, it writes content to file twice.

Raises:

  • StandardError when no content nor content_file



284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/epub/maker/publication.rb', line 284

def save
  content_to_save =
    if content
      content
    elsif content_file
      File.read(content_file)
    else
      begin
        read
      rescue OCF::PhysicalContainer::NoEntry
        raise 'no content nor content_file'
      end
    end
  book = manifest.package.book
  book.container_adapter.write book.epub_file, entry_name, content_to_save
end