Sha256: f434f0ed00efbdf5ed19b7b6ee970879dd71cee61809fc84c2d50ba9694a8277

Contents?: true

Size: 1.57 KB

Versions: 9

Compression:

Stored size: 1.57 KB

Contents

require 'epub/ocf'
require 'epub/maker/ocf/physical_container'
require "nokogiri"

# @todo Use refinement
module EPUB
  class OCF
    DIRECTORY = 'META-INF'

    def make
      yield self if block_given?
      self
    end

    def save
      book.container_adapter.write book.epub_file, File.join(DIRECTORY, Container::FILE), self.container.to_xml if self.container
    end

    # @overload make_container
    #   @return [Container]
    # @overload make_container
    #   @return [Container]
    #   @yield [container] if block given
    #   @yieldparam [Container]
    def make_container
      self.container = Container.new
      yield container if block_given?
      container
    end

    class Container
      def to_xml(options={:encoding => 'UTF-8'})
        Nokogiri::XML::Builder.new(options) {|xml|
          xml.container('xmlns' => EPUB::NAMESPACES['ocf'], 'version' => '1.0') {
            xml.rootfiles {
              rootfiles.each do |rootfile|
                xml.rootfile('full-path' => rootfile.full_path,
                             'media-type' => rootfile.media_type)
              end
            }
          }
        }.to_xml
      end

      # @option full_path [String|nil] full path to package document file in container such like "OPS/content.opf"
      # @option media_type [String] media type
      # @yield [Rootfile] rootfile
      def make_rootfile(full_path: nil, media_type: EPUB::MediaType::ROOTFILE)
        rootfile = Rootfile.new(full_path, media_type)
        @rootfiles << rootfile
        yield rootfile if block_given?
        rootfile
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
epub-maker-0.1.8 lib/epub/maker/ocf.rb
epub-maker-0.1.7 lib/epub/maker/ocf.rb
epub-maker-0.1.6 lib/epub/maker/ocf.rb
epub-maker-0.1.5 lib/epub/maker/ocf.rb
epub-maker-0.1.4 lib/epub/maker/ocf.rb
epub-maker-0.1.3 lib/epub/maker/ocf.rb
epub-maker-0.1.2 lib/epub/maker/ocf.rb
epub-maker-0.1.1 lib/epub/maker/ocf.rb
epub-maker-0.1.0 lib/epub/maker/ocf.rb