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:



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

def edit
  yield self if block_given?
  save
end

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

Yields:

  • (_self)

Yield Parameters:



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

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



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

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

#make_manifestObject



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

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

#make_metadataObject



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

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

#make_spineObject



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

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

#saveObject



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

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

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



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
34
# File 'lib/epub/maker/publication.rb', line 9

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