Class: Verku::Exporter
- Inherits:
-
Object
show all
- Defined in:
- lib/verku/exporter.rb,
lib/verku/exporter/pdf.rb,
lib/verku/exporter/base.rb,
lib/verku/exporter/epub.rb,
lib/verku/exporter/html.rb,
lib/verku/exporter/mobi.rb
Defined Under Namespace
Classes: Base, Epub, HTML, Mobi, PDF
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(root_dir, options) ⇒ Exporter
11
12
13
14
|
# File 'lib/verku/exporter.rb', line 11
def initialize(root_dir, options)
@root_dir = root_dir
@options = options
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
9
10
11
|
# File 'lib/verku/exporter.rb', line 9
def options
@options
end
|
#root_dir ⇒ Object
Returns the value of attribute root_dir.
8
9
10
|
# File 'lib/verku/exporter.rb', line 8
def root_dir
@root_dir
end
|
Class Method Details
.run(root_dir, options) ⇒ Object
3
4
5
6
|
# File 'lib/verku/exporter.rb', line 3
def self.run(root_dir, options)
exporter = new(root_dir, options)
exporter.export
end
|
Instance Method Details
#config ⇒ Object
73
74
75
|
# File 'lib/verku/exporter.rb', line 73
def config
Verku.config(root_dir)
end
|
#export ⇒ Object
20
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
63
64
65
66
67
68
69
70
71
|
# File 'lib/verku/exporter.rb', line 20
def export
helper = root_dir.join("config/helper.rb")
load(helper) if helper.exist?
raise "Missing Templates directory (_templates)" unless File.exist?("_templates")
raise "Missing Images directory (_images)" unless File.exist?("_images")
raise "Missing Output directory (builds)" unless File.exist?("builds")
puts "Missing Kindlegen" unless Dependency.kindlegen?
puts "Missing XeLatex" unless Dependency.xelatex?
export_pdf = [nil, "pdf"].include?(options[:only])
export_html = [nil, "html", "mobi", "epub"].include?(options[:only])
export_epub = [nil, "mobi", "epub"].include?(options[:only])
export_mobi = [nil, "mobi"].include?(options[:only])
export_txt = [nil, "txt"].include?(options[:only])
exported = []
exported << PDF.export!(root_dir) if export_pdf && Dependency.xelatex?
exported << HTML.export!(root_dir) if export_html
epub_done = Epub.export!(root_dir) if export_epub
exported << epub_done
exported << Mobi.export!(root_dir) if export_mobi && epub_done && Dependency.kindlegen?
if exported.all?
color = :green
message = options[:auto] ? "exported!" : "** e-book has been exported"
if options[:open] && export_pdf
filepath = root_dir.join("output/#{File.basename(root_dir)}.pdf")
if RUBY_PLATFORM =~ /darwin/
IO.popen("open -a Preview.app '#{filepath}'").close
elsif RUBY_PLATFORM =~ /linux/
Process.detach(Process.spawn("xdg-open '#{filepath}'", :out => "/dev/null"))
end
end
Notifier.notify(
:image => Verku::ROOT.join("_templates/ebook.png"),
:title => "Verku",
:message => "Your \"#{config[:title]}\" e-book has been exported!"
)
else
color = :red
message = options[:auto] ? "could not be exported!" : "** e-book couldn't be exported"
end
ui.say message, color
end
|
#ui ⇒ Object
16
17
18
|
# File 'lib/verku/exporter.rb', line 16
def ui
@ui ||= Thor::Base.shell.new
end
|