Class: Repub::App::Builder::BuilderSupport
- Includes:
- Logger
- Defined in:
- lib/repub/app/builder.rb
Constant Summary
Constants included from Logger
Logger::LOGGER_NORMAL, Logger::LOGGER_QUIET, Logger::LOGGER_VERBOSE
Instance Attribute Summary collapse
-
#document_path ⇒ Object
readonly
Returns the value of attribute document_path.
-
#output_path ⇒ Object
readonly
Returns the value of attribute output_path.
Instance Method Summary collapse
- #build(parser) ⇒ Object
-
#initialize(options) ⇒ BuilderSupport
constructor
A new instance of BuilderSupport.
Methods included from Logger
Constructor Details
#initialize(options) ⇒ BuilderSupport
Returns a new instance of BuilderSupport.
21 22 23 |
# File 'lib/repub/app/builder.rb', line 21 def initialize() @options = end |
Instance Attribute Details
#document_path ⇒ Object (readonly)
Returns the value of attribute document_path.
19 20 21 |
# File 'lib/repub/app/builder.rb', line 19 def document_path @document_path end |
#output_path ⇒ Object (readonly)
Returns the value of attribute output_path.
18 19 20 |
# File 'lib/repub/app/builder.rb', line 18 def output_path @output_path end |
Instance Method Details
#build(parser) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/repub/app/builder.rb', line 25 def build(parser) @parser = parser # Initialize Container @ocf = Epub::OCF.new # Initialize Package @opf = Epub::OPF.new(@parser.uid) @ocf << @opf # Default title is the parsed one @opf..title = @parser.title # Override metadata values specified in options if @options[:metadata] @opf..members.each do |m| m = m.to_sym # Do not allow to override uid next if m == :identifier if @options[:metadata][m] @opf.[m] = @options[:metadata][m] log.debug "-- Setting metadata #{m} to \"#{@opf.[m]}\"" end end end # Initialize TOC @ncx = Epub::NCX.new(@parser.uid) @opf << @ncx @ncx.title = @opf..title @ncx.nav_map.points = @parser.toc # Setup output filename and path @output_path = File.(@options[:output_path].if_blank('.')) if File.exist?(@output_path) && File.directory?(@output_path) @output_path = File.join(@output_path, @opf..title.gsub(/\s/, '_')) end @output_path = @output_path + '.epub' log.debug "-- Output path is #{@output_path}" # Build EPUB tmpdir = Dir.mktmpdir(App::name) begin FileUtils.chdir(tmpdir) do copy_and_process_assets @ncx.save @opf.save @ocf.save @ocf.zip(@output_path) end ensure # Keep tmp folder if we're going open processed doc in browser FileUtils.remove_entry_secure(tmpdir) unless @options[:browser] end self end |