lib/kitabu/cli.rb in kitabu-1.0.0.rc1 vs lib/kitabu/cli.rb in kitabu-1.0.0.rc2

- old
+ new

@@ -44,34 +44,69 @@ def version say "Kitabu version #{Version::STRING}" end + desc "check", "Check if all external dependencies are installed" + + def check + result = [] + + result << { + :description => "Prince XML: Converts HTML files into PDF files.", + :installed => Kitabu::Dependency.prince? + } + + result << { + :description => "KindleGen: Converts ePub e-books into .mobi files.", + :installed => Kitabu::Dependency.kindlegen? + } + + result << { + :description => "html2text: Converts HTML documents into plain text.", + :installed => Kitabu::Dependency.html2text? + } + + result << { + :description => "pygments.rb: A generic syntax highlight. If installed, replaces CodeRay.", + :installed => Kitabu::Dependency.pygments_rb? + } + + result.each do |result| + text = color(result[:name], :blue) + text << "\n" << result[:description] + text << "\n" << (result[:installed] ? color("Installed.", :green) : color("Not installed.", :red)) + text << "\n" + + say(text) + end + end + desc "permalinks", "List title permalinks" def permalinks - html = Kitabu::Parser::Html.new(root_dir).content - toc = Kitabu::Toc.generate(html) + inside_ebook! - color_support = shell.instance_of?(Thor::Shell::Color) + html = Kitabu::Parser::HTML.new(root_dir).content + toc = Kitabu::TOC::HTML.generate(html) toc.toc.each do |options| level = options[:level] - 1 title = " #{options[:text]}: " permalink = "##{options[:permalink]}" text = "*" * level - text << (color_support ? shell.set_color(title, :blue) : title) - text << (color_support ? shell.set_color(permalink, :yellow) : permalink) + text << color(title, :blue) + text << color(permalink, :yellow) say(text) end end private def inside_ebook! unless File.exist?(config_path) - raise Error, "You can't export files when you're outside an e-book directory" + raise Error, "You have to run this command from inside an e-book directory." end end def config YAML.load_file(config_path).with_indifferent_access @@ -81,8 +116,16 @@ root_dir.join("config/kitabu.yml") end def root_dir @root ||= Pathname.new(Dir.pwd) + end + + def color(text, color) + color? ? shell.set_color(text, color) : text + end + + def color? + shell.instance_of?(Thor::Shell::Color) end end end