Class: EPUB::Publication::Package

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

Defined Under Namespace

Modules: ContentModel Classes: Bindings, Manifest, Metadata, Spine

Instance Method Summary collapse

Instance Method Details

#edit {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



45
46
47
48
# File 'lib/epub/maker/publication.rb', line 45

def edit
  yield self if block_given?
  save
end

#make {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



35
36
37
38
39
40
41
42
43
# File 'lib/epub/maker/publication.rb', line 35

def make
  (CONTENT_MODELS - [:bindings, :guide]).each do |model|
    klass = self.class.const_get(model.to_s.capitalize)
    obj = klass.new
    __send__ "#{model}=", obj
  end
  yield self if block_given?
  self
end

#make_bindingsObject



74
75
76
77
78
79
80
# File 'lib/epub/maker/publication.rb', line 74

def make_bindings
  self.bindings = Bindings.new
  bindings.make do
    yield bindings if block_given?
  end
  bindings
end

#make_manifestObject



58
59
60
61
62
63
64
# File 'lib/epub/maker/publication.rb', line 58

def make_manifest
  self.manifest = Manifest.new
  manifest.make do
    yield manifest if block_given?
  end
  manifest
end

#make_metadataObject



50
51
52
53
54
55
56
# File 'lib/epub/maker/publication.rb', line 50

def 
  self. = .new
  .make do
    yield  if block_given?
  end
  
end

#make_spineObject



66
67
68
69
70
71
72
# File 'lib/epub/maker/publication.rb', line 66

def make_spine
  self.spine = Spine.new
  spine.make do
    yield spine if block_given?
  end
  spine
end

#saveObject



82
83
84
# File 'lib/epub/maker/publication.rb', line 82

def save
  book.container_adapter.write book.epub_file, book.rootfile_path, to_xml
end

#to_xml(options = {:encoding => 'UTF-8'}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/epub/maker/publication.rb', line 8

def to_xml(options={:encoding => 'UTF-8'})
  Nokogiri::XML::Builder.new(options) {|xml|
    attrs = {
      'version'           => '3.0',
      'xmlns'             => EPUB::NAMESPACES['opf'],
      'unique-identifier' => unique_identifier.id
    }
    [
     ['dir', dir],
     ['id', id],
     ['xml:lang', xml_lang],
     ['prefix', prefix.reduce('') {|attr, (pfx, iri)| [attr, [pfx, iri].join(':')].join(' ')}]
    ].each do |(name, value)|
      next if value.nil? or value.empty?
      attrs[name] = value
    end
    xml.package_(attrs) do
      (EPUB::Publication::Package::CONTENT_MODELS - [:bindings, :guide]).each do |model|
        __send__(model).to_xml_fragment xml
      end
      if bindings and !bindings.media_types.empty?
        bindings.to_xml_fragment xml
      end
    end
  }.to_xml
end