diff options
Diffstat (limited to 'guides/rails_guides/kindle.rb')
-rw-r--r-- | guides/rails_guides/kindle.rb | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/guides/rails_guides/kindle.rb b/guides/rails_guides/kindle.rb index 6fb8183cb1..9536d0bd3b 100644 --- a/guides/rails_guides/kindle.rb +++ b/guides/rails_guides/kindle.rb @@ -1,9 +1,6 @@ #!/usr/bin/env ruby -unless `which kindlerb` - abort "Please gem install kindlerb" -end - +require "kindlerb" require "nokogiri" require "fileutils" require "yaml" @@ -28,10 +25,9 @@ module Kindle generate_document_metadata(mobi_outfile) puts "Creating MOBI document with kindlegen. This may take a while." - cmd = "kindlerb . > #{File.absolute_path logfile} 2>&1" - puts cmd - system(cmd) - puts "MOBI document generated at #{File.expand_path(mobi_outfile, output_dir)}" + if Kindlerb.run(output_dir) + puts "MOBI document generated at #{File.expand_path(mobi_outfile, output_dir)}" + end end end @@ -56,7 +52,7 @@ module Kindle h2["id"] = h2.inner_text.gsub(/\s/, "-") end add_head_section fdoc, "Front Matter" - File.open("frontmatter.html","w") { |f| f.puts fdoc.to_html } + File.open("frontmatter.html", "w") { |f| f.puts fdoc.to_html } html_pages.unshift "frontmatter.html" end @@ -68,7 +64,7 @@ module Kindle title = doc.at("title").inner_text.gsub("Ruby on Rails Guides: ", "") title = page.capitalize.gsub(".html", "") if title.strip == "" File.open("sections/%03d/_section.txt" % section_idx, "w") { |f| f.puts title } - doc.xpath("//h3[@id]").each_with_index do |h3,item_idx| + doc.xpath("//h3[@id]").each_with_index do |h3, item_idx| subsection = h3.inner_text content = h3.xpath("./following-sibling::*").take_while { |x| x.name != "h3" }.map(&:to_html) item = Nokogiri::HTML(h3.to_html + content.join("\n")) |