Module: Softcover::Commands::Check
- Extended by:
- Check, Utils
- Included in:
- Check
- Defined in:
- lib/softcover/commands/check.rb
Constant Summary
Constants included
from Utils
Utils::UNITS
Instance Method Summary
collapse
Methods included from Utils
add_highlight_class!, as_size, book_file_lines, chapter_label, commands, current_book, dependency_filename, digest, executable, execute, in_book_directory?, language_labels, linux?, logged_in?, master_content, master_filename, master_latex_header, mkdir, non_comment_lines, os_x?, path, raw_lines, reset_current_book!, rm, silence, source, tmpify, unpublish_slug, write_master_latex_file, write_pygments_file
Instance Method Details
#check_dependencies! ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/softcover/commands/check.rb', line 9
def check_dependencies!
puts "Checking Softcover dependencies..."
simulate_work(1)
missing_dependencies = []
dependencies.each do |label, name|
printf "%-30s", "Checking for #{name}..."
simulate_work(0.15)
if present?(label)
puts "Found"
else
missing_dependencies << label
puts "Missing"
end
simulate_work(0.1)
end
simulate_work(0.25)
if missing_dependencies.empty?
puts "All dependencies satisfied."
else
puts "Missing dependencies:"
missing_dependencies.each do |dependency|
puts " • " + missing_dependency_message(dependency)
end
end
end
|
#dependencies ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/softcover/commands/check.rb', line 35
def dependencies
[[:latex, 'LaTeX'],
[:ghostscript, 'GhostScript'],
[:convert, 'ImageMagick'],
[:node, 'Node.js'],
[:phantomjs, 'PhantomJS'],
[:inkscape, 'Inkscape'],
[:calibre, 'Calibre'],
[:kindlegen, 'KindleGen'],
[:java, 'Java'],
[:zip, 'zip'],
[:epubcheck, 'EpubCheck'],
]
end
|
#dependency_labels ⇒ Object
50
51
52
|
# File 'lib/softcover/commands/check.rb', line 50
def dependency_labels
dependencies.map(&:first)
end
|
#dependency_names ⇒ Object
54
55
56
|
# File 'lib/softcover/commands/check.rb', line 54
def dependency_names
dependencies.map { |e| e[1] }
end
|
#missing_dependency_message(label) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/softcover/commands/check.rb', line 58
def missing_dependency_message(label)
case label
when :latex
message = "LaTeX (http://latex-project.org/ftp.html)\n"
message += " ∟ Huge download—start it now!"
when :ghostscript
message = "GhostScript (should come with LaTeX)\n"
when :convert
"ImageMagick (http://www.imagemagick.org/script/binary-releases.php)"
when :node
"NodeJS (http://nodejs.org/)"
when :phantomjs
message = "PhantomJS (http://phantomjs.org/)\n"
message += " ∟ Put bin/phantomjs somewhere on your path,"
message += " e.g., in /usr/local/bin"
when :kindlegen
url = 'http://www.amazon.com/gp/feature.html?ie=UTF8&docId=1000765211'
message = "KindleGen (#{url})\n"
message += " ∟ Put the kindlegen executable on your path,"
message += " e.g., in /usr/local/bin"
when :calibre
url = 'http://calibre-ebook.com/'
message = "Calibre (#{url})\n"
message += " ∟ Enable Calibre command-line tools"
message += " (http://manual.calibre-ebook.com/cli/cli-index.html)"
when :java
url = 'http://www.java.com/en/download/help/index_installing.xml'
"Java (#{url})"
when :zip
"Install zip (e.g., apt-get install zip)"
when :epubcheck
url = 'https://github.com/IDPF/epubcheck/releases/'
url += 'download/v3.0/epubcheck-3.0.zip'
message = "EpubCheck 3.0 (#{url})\n"
message += " ∟ Unzip and put epubcheck-3.0/ in $HOME/bin"
when :inkscape
message = "Inkscape (http://inkscape.org/)"
else
raise "Unknown label #{label}"
end
end
|
#present?(label) ⇒ Boolean
100
101
102
|
# File 'lib/softcover/commands/check.rb', line 100
def present?(label)
File.exist?(dependency_filename(label))
end
|
#simulate_work(time) ⇒ Object
Simulate working for given time. ‘softcover check` is more satisfying if it looks like it’s doing work.
106
107
108
|
# File 'lib/softcover/commands/check.rb', line 106
def simulate_work(time)
sleep time unless Softcover::test?
end
|