Class: Prophecy::CLI
- Inherits:
-
Thor
- Object
- Thor
- Prophecy::CLI
- Defined in:
- lib/prophecy/cli.rb
Instance Method Summary collapse
- #assets ⇒ Object
- #assets_compile ⇒ Object
- #epub ⇒ Object
- #epub_build ⇒ Object
- #epub_check(filepath) ⇒ Object
- #epub_clean_dir ⇒ Object
- #epub_compile ⇒ Object
- #latex ⇒ Object
- #latex_build ⇒ Object
- #latex_clean_dir ⇒ Object
- #latex_compile ⇒ Object
- #latex_to_markdown ⇒ Object
- #mobi ⇒ Object
- #mobi_build ⇒ Object
- #mobi_clean_dir ⇒ Object
- #mobi_compile ⇒ Object
- #new(title) ⇒ Object
Instance Method Details
#assets ⇒ Object
17 18 19 |
# File 'lib/prophecy/cli.rb', line 17 def assets Prophecy::Generators::Assets.start end |
#assets_compile ⇒ Object
253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/prophecy/cli.rb', line 253 def assets_compile unless Dir.exists?('./assets') return end puts "Running 'compass compile' ..." if system 'cd assets && compass compile' puts "OK" else puts "Error" exit 2 end end |
#epub ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/prophecy/cli.rb', line 22 def epub epub_init assets_compile epub_clean_dir epub_build epub_compile end |
#epub_build ⇒ Object
37 38 39 40 |
# File 'lib/prophecy/cli.rb', line 37 def epub_build epub_init @book.generate_build end |
#epub_check(filepath) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/prophecy/cli.rb', line 74 def epub_check(filepath) unless File.exist?(filepath) warn "File not found: #{filepath}" exit 2 end print "Validating Epub with Epubcheck... " binpath = File.(File.join(__FILE__, '..', '..', '..', 'epubcheck_dir/epubcheck.jar')) cmd = "java -jar #{binpath} #{filepath}" if system(cmd) puts "OK" else puts "There was an error." exit 2 end end |
#epub_clean_dir ⇒ Object
31 32 33 34 |
# File 'lib/prophecy/cli.rb', line 31 def epub_clean_dir epub_init clean_dir end |
#epub_compile ⇒ Object
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/prophecy/cli.rb', line 43 def epub_compile epub_init # Compile Epub with Zip print "Compiling Epub with Zip... " path = File.("./publish/epub/#{@book.compile_name}.epub") if RUBY_PLATFORM =~ /linux|darwin|cygwin/ binpath = "zip" elsif RUBY_PLATFORM =~ /mingw|mswin32/ binpath = File.(File.join(__FILE__, '..', '..', '..', 'bin/zip.exe')) end cmd = "{ cd #{@book.build_dir}" cmd += " && #{binpath} -X \"#{path}\" mimetype" cmd += " && #{binpath} -rg \"#{path}\" META-INF" cmd += " && #{binpath} -rg \"#{path}\" OEBPS; } > zip.log 2>&1" if system(cmd) puts "OK" puts "Find the Epub file in ./publish/epub" else puts "Error. See zip.log" exit 2 end #puts "Validating with epubcheck" #cmd = system("epubcheck builds/epub/book.epub") end |
#latex ⇒ Object
173 174 175 176 177 178 |
# File 'lib/prophecy/cli.rb', line 173 def latex latex_init latex_clean_dir latex_build latex_compile end |
#latex_build ⇒ Object
187 188 189 190 |
# File 'lib/prophecy/cli.rb', line 187 def latex_build latex_init @book.generate_build end |
#latex_clean_dir ⇒ Object
181 182 183 184 |
# File 'lib/prophecy/cli.rb', line 181 def latex_clean_dir latex_init clean_dir end |
#latex_compile ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/prophecy/cli.rb', line 193 def latex_compile latex_init # Is LuaLatex installed? unless system("lualatex --version > /dev/null 2>&1") puts "Error. LuaLaTeX not found." exit 2 end print "Running 'make' in #{@book.build_dir} ... " cmd = "{ cd #{@book.build_dir}" cmd += " && make" cmd += " && cp book_main.pdf ../../publish/pdf/; } > lualatex.log 2>&1" if system(cmd) puts "OK" puts "Find book_main.pdf in ./build/latex/ and ./publish/pdf" else puts "Error. See lualatex.log and ./build/latex/book_main.log" exit 2 end end |
#latex_to_markdown ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/prophecy/cli.rb', line 218 def latex_to_markdown latex_init tex_dir = File.join("manuscript", "tex") markdown_dir = File.join("manuscript", "markdown") unless Dir.exists?(tex_dir) puts "Could not find: #{tex_dir}." exit 2 else if Dir[File.join(tex_dir, '*.tex')].size == 0 puts "No .tex files found in #{tex_dir}" exit 2 end end FileUtils.mkdir(markdown_dir) unless Dir.exists?(markdown_dir) Dir[File.join(tex_dir, '*.tex')].each do |f| dest = File.(File.join(markdown_dir, File.basename(f).sub(/\.tex$/, '.md'))) if File.exist?(dest) print "WARNING: destination exists: #{dest}\nOverwrite? [yN] " a = STDIN.gets.chomp() if a.downcase != 'y' puts "OK, skipping file" next end end r = system "/bin/bash #{File.join(@book.assets_dir, '..', 'generators', 'book', 'helpers', 'tex2md.sh')} '#{File.(f)}' '#{dest}'" warn "WARNING: tex2md.sh returned non-zero for #{f}" unless r end end |
#mobi ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/prophecy/cli.rb', line 95 def mobi mobi_init assets_compile mobi_clean_dir mobi_build mobi_compile end |
#mobi_build ⇒ Object
110 111 112 113 |
# File 'lib/prophecy/cli.rb', line 110 def mobi_build mobi_init @book.generate_build end |
#mobi_clean_dir ⇒ Object
104 105 106 107 |
# File 'lib/prophecy/cli.rb', line 104 def mobi_clean_dir mobi_init clean_dir end |
#mobi_compile ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/prophecy/cli.rb', line 116 def mobi_compile mobi_init # Compile Epub with Zip for conversion with kindlegen print "Compiling Epub (for Mobi) with Zip... " path = File.("./#{@book.compile_name}.epub") if RUBY_PLATFORM =~ /linux|darwin|cygwin/ binpath = "zip" elsif RUBY_PLATFORM =~ /mingw|mswin32/ binpath = File.(File.join(__FILE__, '..', '..', '..', 'bin/zip.exe')) end cmd = "{ cd #{@book.build_dir}" cmd += " && #{binpath} -X \"#{path}\" mimetype" cmd += " && #{binpath} -rg \"#{path}\" META-INF" cmd += " && #{binpath} -rg \"#{path}\" OEBPS; } > zip.log 2>&1" if system(cmd) puts "OK" else puts "Error. See zip.log" exit 2 end # Kindlegen print "Converting Epub with Kindlegen... " binpath = File.(File.join(__FILE__, '..', '..', '..', 'bin/kindlegen')) cmd = "{ #{binpath} \"#{@book.compile_name}.epub\"" cmd += " && mv \"#{@book.compile_name}.mobi\" ./publish/mobi/" cmd += " && rm \"#{@book.compile_name}.epub\"; } > kindlegen.log 2>&1" if system(cmd) puts "OK" else puts "Error. See kindlegen.log" exit 2 end # Stripping extra source print "Stripping the SRCS record (source files) from the Mobi with Kindlestrip... " binpath = File.(File.join(__FILE__, '..', '..', '..', 'bin/kindlestrip.py')) cmd = "{ #{binpath} \"./publish/mobi/#{@book.compile_name}.mobi\" \"./publish/mobi/#{@book.compile_name}.stripped.mobi\"" cmd += " && mv \"./publish/mobi/#{@book.compile_name}.stripped.mobi\" \"./publish/mobi/#{@book.compile_name}.mobi\"; } > kindlestrip.log 2>&1" if system(cmd) puts "OK" puts "Find the Mobi file in ./publish/mobi" else puts "Error. See kindlestrip.log" exit 2 end end |
#new(title) ⇒ Object
12 13 14 |
# File 'lib/prophecy/cli.rb', line 12 def new(title) Prophecy::Generators::New.start([title, ]) end |