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.



253
254
255
# File 'lib/epub/maker/publication.rb', line 253

def content
  @content
end

#content_fileObject

Returns the value of attribute content_file.



253
254
255
# File 'lib/epub/maker/publication.rb', line 253

def content_file
  @content_file
end

Instance Method Details

#editObject

Save document into EPUB archive when block ended



271
272
273
274
# File 'lib/epub/maker/publication.rb', line 271

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)


288
289
290
291
292
293
# File 'lib/epub/maker/publication.rb', line 288

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)


278
279
280
281
282
283
284
# File 'lib/epub/maker/publication.rb', line 278

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



257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/epub/maker/publication.rb', line 257

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