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:



43
44
45
46
# File 'lib/epub/maker/publication.rb', line 43

def edit
  yield self if block_given?
  save
end

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

Yields:

  • (_self)

Yield Parameters:



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

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



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

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

#make_manifestObject



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

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

#make_metadataObject



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

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

#make_spineObject



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

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

#saveObject



80
81
82
# File 'lib/epub/maker/publication.rb', line 80

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

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



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

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