aboutsummaryrefslogtreecommitdiffstats
path: root/guides/rails_guides/kindle.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2016-08-06 19:21:59 +0200
committerXavier Noria <fxn@hashref.com>2016-08-06 19:21:59 +0200
commit6b3719b7577ab81171bab94a0492ae383dd279fe (patch)
treedda0bb85b771cafd16acf5bea1288233feca8e09 /guides/rails_guides/kindle.rb
parent8b4e6bf23338e2080af537ea4f295e65a1d11388 (diff)
downloadrails-6b3719b7577ab81171bab94a0492ae383dd279fe.tar.gz
rails-6b3719b7577ab81171bab94a0492ae383dd279fe.tar.bz2
rails-6b3719b7577ab81171bab94a0492ae383dd279fe.zip
applies new string literal convention in guides
The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
Diffstat (limited to 'guides/rails_guides/kindle.rb')
-rw-r--r--guides/rails_guides/kindle.rb56
1 files changed, 28 insertions, 28 deletions
diff --git a/guides/rails_guides/kindle.rb b/guides/rails_guides/kindle.rb
index 081afcb09f..3686e195e0 100644
--- a/guides/rails_guides/kindle.rb
+++ b/guides/rails_guides/kindle.rb
@@ -4,10 +4,10 @@ unless `which kindlerb`
abort "Please gem install kindlerb"
end
-require 'nokogiri'
-require 'fileutils'
-require 'yaml'
-require 'date'
+require "nokogiri"
+require "fileutils"
+require "yaml"
+require "date"
module Kindle
extend self
@@ -18,7 +18,7 @@ module Kindle
puts "=> Using output dir: #{output_dir}"
puts "=> Arranging html pages in document order"
toc = File.read("toc.ncx")
- doc = Nokogiri::XML(toc).xpath("//ncx:content", 'ncx' => "http://www.daisy.org/z3986/2005/ncx/")
+ doc = Nokogiri::XML(toc).xpath("//ncx:content", "ncx" => "http://www.daisy.org/z3986/2005/ncx/")
html_pages = doc.select {|c| c[:src]}.map {|c| c[:src]}.uniq
generate_front_matter(html_pages)
@@ -49,14 +49,14 @@ module Kindle
fdoc = Nokogiri::HTML(html)
fdoc.search("h3").each do |h3|
- h3.name = 'h4'
+ h3.name = "h4"
end
fdoc.search("h2").each do |h2|
- h2.name = 'h3'
- h2['id'] = h2.inner_text.gsub(/\s/, '-')
+ h2.name = "h3"
+ 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
@@ -65,9 +65,9 @@ module Kindle
html_pages.each_with_index do |page, section_idx|
FileUtils::mkdir_p("sections/%03d" % section_idx)
doc = Nokogiri::HTML(File.open(page))
- 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}
+ 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|
subsection = h3.inner_text
content = h3.xpath("./following-sibling::*").take_while {|x| x.name != "h3"}.map(&:to_html)
@@ -75,10 +75,10 @@ module Kindle
item_path = "sections/%03d/%03d.html" % [section_idx, item_idx]
add_head_section(item, subsection)
item.search("img").each do |img|
- img['src'] = "#{Dir.pwd}/#{img['src']}"
+ img["src"] = "#{Dir.pwd}/#{img['src']}"
end
item.xpath("//li/p").each {|p| p.swap(p.children); p.remove}
- File.open(item_path, 'w') {|f| f.puts item.to_html}
+ File.open(item_path, "w") {|f| f.puts item.to_html}
end
end
end
@@ -87,21 +87,21 @@ module Kindle
puts "=> Generating _document.yml"
x = Nokogiri::XML(File.open("rails_guides.opf")).remove_namespaces!
cover_jpg = "#{Dir.pwd}/images/rails_guides_kindle_cover.jpg"
- cover_gif = cover_jpg.sub(/jpg$/, 'gif')
+ cover_gif = cover_jpg.sub(/jpg$/, "gif")
puts `convert #{cover_jpg} #{cover_gif}`
document = {
- 'doc_uuid' => x.at("package")['unique-identifier'],
- 'title' => x.at("title").inner_text.gsub(/\(.*$/, " v2"),
- 'publisher' => x.at("publisher").inner_text,
- 'author' => x.at("creator").inner_text,
- 'subject' => x.at("subject").inner_text,
- 'date' => x.at("date").inner_text,
- 'cover' => cover_gif,
- 'masthead' => nil,
- 'mobi_outfile' => mobi_outfile
+ "doc_uuid" => x.at("package")["unique-identifier"],
+ "title" => x.at("title").inner_text.gsub(/\(.*$/, " v2"),
+ "publisher" => x.at("publisher").inner_text,
+ "author" => x.at("creator").inner_text,
+ "subject" => x.at("subject").inner_text,
+ "date" => x.at("date").inner_text,
+ "cover" => cover_gif,
+ "masthead" => nil,
+ "mobi_outfile" => mobi_outfile
}
puts document.to_yaml
- File.open("_document.yml", 'w'){|f| f.puts document.to_yaml}
+ File.open("_document.yml", "w"){|f| f.puts document.to_yaml}
end
def add_head_section(doc, title)
@@ -110,9 +110,9 @@ module Kindle
title_node.content = title
title_node.parent = head
css = Nokogiri::XML::Node.new "link", doc
- css['rel'] = 'stylesheet'
- css['type'] = 'text/css'
- css['href'] = "#{Dir.pwd}/stylesheets/kindle.css"
+ css["rel"] = "stylesheet"
+ css["type"] = "text/css"
+ css["href"] = "#{Dir.pwd}/stylesheets/kindle.css"
css.parent = head
doc.at("body").before head
end