Class: EeePub::Maker
- Inherits:
-
Object
- Object
- EeePub::Maker
- Defined in:
- lib/eeepub/lib/eeepub/maker.rb
Overview
The class to make ePub easily
Direct Known Subclasses
Instance Method Summary collapse
- #identifier(id, options) ⇒ Object
-
#initialize(&block) ⇒ Maker
constructor
A new instance of Maker.
-
#save(filename) ⇒ Object
Save as ePub file.
Constructor Details
#initialize(&block) ⇒ Maker
Returns a new instance of Maker.
64 65 66 67 68 69 70 71 |
# File 'lib/eeepub/lib/eeepub/maker.rb', line 64 def initialize(&block) @files ||= [] @nav ||= [] @ncx_file ||= 'toc.ncx' @opf_file ||= 'content.opf' instance_eval(&block) if block_given? end |
Instance Method Details
#identifier(id, options) ⇒ Object
58 59 60 61 |
# File 'lib/eeepub/lib/eeepub/maker.rb', line 58 def identifier(id, ) @identifiers ||= [] @identifiers << {:value => id, :scheme => [:scheme]} end |
#save(filename) ⇒ Object
Save as ePub file
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/eeepub/lib/eeepub/maker.rb', line 76 def save(filename) Dir.mktmpdir do |dir| @files.each do |file| case file when String FileUtils.cp(file, dir) when Hash file_path, dir_path = *file.first dest_dir = File.join(dir, dir_path) FileUtils.mkdir_p(dest_dir) FileUtils.cp(file_path, dest_dir) end end NCX.new( :uid => @uid, :title => @titles[0], :nav => @nav ).save(File.join(dir, @ncx_file)) OPF.new( :title => @titles, :identifier => @identifiers, :creator => @creators, :publisher => @publishers, :date => @dates, :language => @languages, :subject => @subjects, :description => @descriptions, :rights => @rightss, :relation => @relations, :guide=> @guide, :manifest => @files.map{|file| case file when String File.basename(file) when Hash file_path, dir_path = *file.first File.join(dir_path, File.basename(file_path)) end }, :ncx => @ncx_file ).save(File.join(dir, @opf_file)) OCF.new( :dir => dir, :container => @opf_file ).save(filename) end end |