diff options
author | Xavier Noria <fxn@hashref.com> | 2016-08-06 19:21:59 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2016-08-06 19:21:59 +0200 |
commit | 6b3719b7577ab81171bab94a0492ae383dd279fe (patch) | |
tree | dda0bb85b771cafd16acf5bea1288233feca8e09 /guides/rails_guides | |
parent | 8b4e6bf23338e2080af537ea4f295e65a1d11388 (diff) | |
download | rails-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')
-rw-r--r-- | guides/rails_guides/generator.rb | 60 | ||||
-rw-r--r-- | guides/rails_guides/helpers.rb | 16 | ||||
-rw-r--r-- | guides/rails_guides/indexer.rb | 8 | ||||
-rw-r--r-- | guides/rails_guides/kindle.rb | 56 | ||||
-rw-r--r-- | guides/rails_guides/markdown.rb | 28 | ||||
-rw-r--r-- | guides/rails_guides/markdown/renderer.rb | 22 |
6 files changed, 95 insertions, 95 deletions
diff --git a/guides/rails_guides/generator.rb b/guides/rails_guides/generator.rb index 48ac90fca4..fdd525a594 100644 --- a/guides/rails_guides/generator.rb +++ b/guides/rails_guides/generator.rb @@ -49,18 +49,18 @@ # # --------------------------------------------------------------------------- -require 'set' -require 'fileutils' +require "set" +require "fileutils" -require 'active_support/core_ext/string/output_safety' -require 'active_support/core_ext/object/blank' -require 'action_controller' -require 'action_view' +require "active_support/core_ext/string/output_safety" +require "active_support/core_ext/object/blank" +require "action_controller" +require "action_view" -require 'rails_guides/markdown' -require 'rails_guides/indexer' -require 'rails_guides/helpers' -require 'rails_guides/levenshtein' +require "rails_guides/markdown" +require "rails_guides/indexer" +require "rails_guides/helpers" +require "rails_guides/levenshtein" module RailsGuides class Generator @@ -81,12 +81,12 @@ module RailsGuides end def set_flags_from_environment - @edge = ENV['EDGE'] == '1' - @warnings = ENV['WARNINGS'] == '1' - @all = ENV['ALL'] == '1' - @kindle = ENV['KINDLE'] == '1' - @version = ENV['RAILS_VERSION'] || 'local' - @lang = ENV['GUIDES_LANGUAGE'] + @edge = ENV["EDGE"] == "1" + @warnings = ENV["WARNINGS"] == "1" + @all = ENV["ALL"] == "1" + @kindle = ENV["KINDLE"] == "1" + @version = ENV["RAILS_VERSION"] || "local" + @lang = ENV["GUIDES_LANGUAGE"] end def register_kindle_mime_types @@ -113,18 +113,18 @@ module RailsGuides end def generate_mobi - require 'rails_guides/kindle' + require "rails_guides/kindle" out = "#{output_dir}/kindlegen.out" Kindle.generate(output_dir, mobi, out) puts "(kindlegen log at #{out})." end def mobi - "ruby_on_rails_guides_#@version%s.mobi" % (@lang.present? ? ".#@lang" : '') + "ruby_on_rails_guides_#@version%s.mobi" % (@lang.present? ? ".#@lang" : "") end def initialize_dirs(output) - @guides_dir = File.join(File.dirname(__FILE__), '..') + @guides_dir = File.join(File.dirname(__FILE__), "..") @source_dir = "#@guides_dir/source/#@lang" @output_dir = if output output @@ -132,7 +132,7 @@ module RailsGuides "#@guides_dir/output/kindle/#@lang" else "#@guides_dir/output/#@lang" - end.sub(%r</$>, '') + end.sub(%r</$>, "") end def create_output_dir_if_needed @@ -151,18 +151,18 @@ module RailsGuides if kindle? Dir.entries("#{source_dir}/kindle").grep(GUIDES_RE).map do |entry| - next if entry == 'KINDLE.md' + next if entry == "KINDLE.md" guides << "kindle/#{entry}" end end - ENV.key?('ONLY') ? select_only(guides) : guides + ENV.key?("ONLY") ? select_only(guides) : guides end def select_only(guides) - prefixes = ENV['ONLY'].split(",").map(&:strip) + prefixes = ENV["ONLY"].split(",").map(&:strip) guides.select do |guide| - guide.start_with?('kindle'.freeze, *prefixes) + guide.start_with?("kindle".freeze, *prefixes) end end @@ -171,10 +171,10 @@ module RailsGuides end def output_file_for(guide) - if guide.end_with?('.md') - guide.sub(/md\z/, 'html') + if guide.end_with?(".md") + guide.sub(/md\z/, "html") else - guide.sub(/\.erb\z/, '') + guide.sub(/\.erb\z/, "") end end @@ -191,9 +191,9 @@ module RailsGuides def generate_guide(guide, output_file) output_path = output_path_for(output_file) puts "Generating #{guide} as #{output_file}" - layout = kindle? ? 'kindle/layout' : 'layout' + layout = kindle? ? "kindle/layout" : "layout" - File.open(output_path, 'w') do |f| + File.open(output_path, "w") do |f| view = ActionView::Base.new(source_dir, :edge => @edge, :version => @version, :mobi => "kindle/#{mobi}", :lang => @lang) view.extend(Helpers) @@ -236,7 +236,7 @@ module RailsGuides def check_fragment_identifiers(html, anchors) html.scan(/<a\s+href="#([^"]+)/).flatten.each do |fragment_identifier| - next if fragment_identifier == 'mainCol' # in layout, jumps to some DIV + next if fragment_identifier == "mainCol" # in layout, jumps to some DIV unless anchors.member?(fragment_identifier) guess = anchors.min { |a, b| Levenshtein.distance(fragment_identifier, a) <=> Levenshtein.distance(fragment_identifier, b) diff --git a/guides/rails_guides/helpers.rb b/guides/rails_guides/helpers.rb index 5bf73da16c..4dd7bf4def 100644 --- a/guides/rails_guides/helpers.rb +++ b/guides/rails_guides/helpers.rb @@ -1,4 +1,4 @@ -require 'yaml' +require "yaml" module RailsGuides module Helpers @@ -7,7 +7,7 @@ module RailsGuides result = content_tag(:dt, link) if options[:work_in_progress] - result << content_tag(:dd, 'Work in progress', :class => 'work-in-progress') + result << content_tag(:dd, "Work in progress", :class => "work-in-progress") end result << content_tag(:dd, capture(&block)) @@ -19,30 +19,30 @@ module RailsGuides end def documents_flat - documents_by_section.flat_map {|section| section['documents']} + documents_by_section.flat_map {|section| section["documents"]} end def finished_documents(documents) - documents.reject { |document| document['work_in_progress'] } + documents.reject { |document| document["work_in_progress"] } end def docs_for_menu(position=nil) if position.nil? documents_by_section - elsif position == 'L' + elsif position == "L" documents_by_section.to(3) else documents_by_section.from(4) end end - def author(name, nick, image = 'credits_pic_blank.gif', &block) + def author(name, nick, image = "credits_pic_blank.gif", &block) image = "images/#{image}" - result = tag(:img, :src => image, :class => 'left pic', :alt => name, :width => 91, :height => 91) + result = tag(:img, :src => image, :class => "left pic", :alt => name, :width => 91, :height => 91) result << content_tag(:h3, name) result << content_tag(:p, capture(&block)) - content_tag(:div, result, :class => 'clearfix', :id => nick) + content_tag(:div, result, :class => "clearfix", :id => nick) end def code(&block) diff --git a/guides/rails_guides/indexer.rb b/guides/rails_guides/indexer.rb index 89fbccbb1d..be1c3fab80 100644 --- a/guides/rails_guides/indexer.rb +++ b/guides/rails_guides/indexer.rb @@ -1,5 +1,5 @@ -require 'active_support/core_ext/object/blank' -require 'active_support/core_ext/string/inflections' +require "active_support/core_ext/object/blank" +require "active_support/core_ext/string/inflections" module RailsGuides class Indexer @@ -34,7 +34,7 @@ module RailsGuides return level_hash elsif level == current_level index = counters.join(".") - idx ||= '#' + title_to_idx(title) + idx ||= "#" + title_to_idx(title) raise "Parsing Fail" unless @result.sub!(matched, "h#{level}(#{idx}). #{index} #{title}") @@ -58,7 +58,7 @@ module RailsGuides end def title_to_idx(title) - idx = title.strip.parameterize.sub(/^\d+/, '') + idx = title.strip.parameterize.sub(/^\d+/, "") if warnings && idx.blank? puts "BLANK ID: please put an explicit ID for section #{title}, as in h5(#my-id)" end 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 diff --git a/guides/rails_guides/markdown.rb b/guides/rails_guides/markdown.rb index 69c7cd5136..6c44353b3b 100644 --- a/guides/rails_guides/markdown.rb +++ b/guides/rails_guides/markdown.rb @@ -1,6 +1,6 @@ -require 'redcarpet' -require 'nokogiri' -require 'rails_guides/markdown/renderer' +require "redcarpet" +require "nokogiri" +require "rails_guides/markdown/renderer" module RailsGuides class Markdown @@ -8,7 +8,7 @@ module RailsGuides @view = view @layout = layout @index_counter = Hash.new(0) - @raw_header = '' + @raw_header = "" @node_ids = {} end @@ -47,10 +47,10 @@ module RailsGuides def dom_id_text(text) escaped_chars = Regexp.escape('\\/`*_{}[]()#+-.!:,;|&<>^~=\'"') - text.downcase.gsub(/\?/, '-questionmark') - .gsub(/!/, '-bang') - .gsub(/[#{escaped_chars}]+/, ' ').strip - .gsub(/\s+/, '-') + text.downcase.gsub(/\?/, "-questionmark") + .gsub(/!/, "-bang") + .gsub(/[#{escaped_chars}]+/, " ").strip + .gsub(/\s+/, "-") end def engine @@ -87,15 +87,15 @@ module RailsGuides doc.children.each do |node| if node.name =~ /^h[3-6]$/ case node.name - when 'h3' + when "h3" hierarchy = [node] @headings_for_index << [1, node, node.inner_html] - when 'h4' + when "h4" hierarchy = hierarchy[0, 1] + [node] @headings_for_index << [2, node, node.inner_html] - when 'h5' + when "h5" hierarchy = hierarchy[0, 2] + [node] - when 'h6' + when "h6" hierarchy = hierarchy[0, 3] + [node] end @@ -109,7 +109,7 @@ module RailsGuides def generate_index if @headings_for_index.present? - raw_index = '' + raw_index = "" @headings_for_index.each do |level, node, label| if level == 1 raw_index += "1. [#{label}](##{node[:id]})\n" @@ -119,7 +119,7 @@ module RailsGuides end @index = Nokogiri::HTML.fragment(engine.render(raw_index)).tap do |doc| - doc.at('ol')[:class] = 'chapters' + doc.at("ol")[:class] = "chapters" end.to_html @index = <<-INDEX.html_safe diff --git a/guides/rails_guides/markdown/renderer.rb b/guides/rails_guides/markdown/renderer.rb index 73ca600361..ec858460e8 100644 --- a/guides/rails_guides/markdown/renderer.rb +++ b/guides/rails_guides/markdown/renderer.rb @@ -25,7 +25,7 @@ HTML def paragraph(text) if text =~ /^(TIP|IMPORTANT|CAUTION|WARNING|NOTE|INFO|TODO)[.:]/ convert_notes(text) - elsif text.include?('DO NOT READ THIS FILE ON GITHUB') + elsif text.include?("DO NOT READ THIS FILE ON GITHUB") elsif text =~ /^\[<sup>(\d+)\]:<\/sup> (.+)$/ linkback = %(<a href="#footnote-#{$1}-ref"><sup>#{$1}</sup></a>) %(<p class="footnote" id="footnote-#{$1}">#{linkback} #{$2}</p>) @@ -46,14 +46,14 @@ HTML def brush_for(code_type) case code_type - when 'ruby', 'sql', 'plain' + when "ruby", "sql", "plain" code_type - when 'erb', 'html+erb' - 'ruby; html-script: true' - when 'html' - 'xml' # HTML is understood, but there are .xml rules in the CSS + when "erb", "html+erb" + "ruby; html-script: true" + when "html" + "xml" # HTML is understood, but there are .xml rules in the CSS else - 'plain' + "plain" end end @@ -68,10 +68,10 @@ HTML # asterisk. body.gsub(/^(TIP|IMPORTANT|CAUTION|WARNING|NOTE|INFO|TODO)[.:](.*?)(\n(?=\n)|\Z)/m) do css_class = case $1 - when 'CAUTION', 'IMPORTANT' - 'warning' - when 'TIP' - 'info' + when "CAUTION", "IMPORTANT" + "warning" + when "TIP" + "info" else $1.downcase end |