Class: Kitabu::Exporter
- Inherits:
-
Object
- Object
- Kitabu::Exporter
- Defined in:
- lib/kitabu/exporter.rb,
lib/kitabu/exporter/css.rb,
lib/kitabu/exporter/pdf.rb,
lib/kitabu/exporter/base.rb,
lib/kitabu/exporter/epub.rb,
lib/kitabu/exporter/html.rb,
lib/kitabu/exporter/mobi.rb
Defined Under Namespace
Classes: Base, CSS, Epub, HTML, Mobi, PDF
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#root_dir ⇒ Object
Returns the value of attribute root_dir.
Class Method Summary collapse
Instance Method Summary collapse
- #config ⇒ Object
- #export! ⇒ Object
-
#initialize(root_dir, options) ⇒ Exporter
constructor
A new instance of Exporter.
- #ui ⇒ Object
Constructor Details
#initialize(root_dir, options) ⇒ Exporter
Returns a new instance of Exporter.
12 13 14 15 |
# File 'lib/kitabu/exporter.rb', line 12 def initialize(root_dir, ) @root_dir = root_dir @options = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/kitabu/exporter.rb', line 10 def @options end |
#root_dir ⇒ Object
Returns the value of attribute root_dir.
10 11 12 |
# File 'lib/kitabu/exporter.rb', line 10 def root_dir @root_dir end |
Class Method Details
.run(root_dir, options) ⇒ Object
5 6 7 8 |
# File 'lib/kitabu/exporter.rb', line 5 def self.run(root_dir, ) exporter = new(root_dir, ) exporter.export! end |
Instance Method Details
#config ⇒ Object
64 65 66 |
# File 'lib/kitabu/exporter.rb', line 64 def config Kitabu.config(root_dir) end |
#export! ⇒ Object
21 22 23 24 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 |
# File 'lib/kitabu/exporter.rb', line 21 def export! helper = root_dir.join("config/helper.rb") load(helper) if helper.exist? FileUtils.rm_rf root_dir.join("output").to_s export_pdf = [nil, "pdf"].include?([:only]) export_epub = [nil, "mobi", "epub"].include?([:only]) export_mobi = [nil, "mobi"].include?([:only]) exported = [] exported << HTML.export(root_dir) exported << PDF.export(root_dir) if export_pdf && Dependency.prince? exported << Epub.export(root_dir) if export_epub exported << Mobi.export(root_dir) if export_mobi && Dependency.calibre? if exported.all? color = :green = [:auto] ? "exported!" : "=> e-book has been exported" if [:open] && export_pdf filepath = root_dir.join("output/#{File.basename(root_dir)}.pdf") case RUBY_PLATFORM when /darwin/ IO.popen("open -a Preview.app '#{filepath}'").close when /linux/ Process.detach(Process.spawn("xdg-open '#{filepath}'", out: "/dev/null")) end end else color = :red = if [:auto] "could not be exported!" else "=> e-book couldn't be exported" end end ui.say , color end |
#ui ⇒ Object
17 18 19 |
# File 'lib/kitabu/exporter.rb', line 17 def ui @ui ||= Thor::Base.shell.new end |