1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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.
This commit is contained in:
Xavier Noria 2016-08-06 19:21:59 +02:00
parent 8b4e6bf233
commit 6b3719b757
15 changed files with 160 additions and 160 deletions

View file

@ -1,7 +1,7 @@
namespace :guides do
desc 'Generate guides (for authors), use ONLY=foo to process just "foo.md"'
task :generate => 'generate:html'
task :generate => "generate:html"
namespace :generate do
@ -19,8 +19,8 @@ namespace :guides do
unless `convert` =~ /convert/
abort "Please install ImageMagick`"
end
ENV['KINDLE'] = '1'
Rake::Task['guides:generate:html'].invoke
ENV["KINDLE"] = "1"
Rake::Task["guides:generate:html"].invoke
end
end
@ -76,4 +76,4 @@ Examples:
end
end
task :default => 'guides:help'
task :default => "guides:help"

View file

@ -1,30 +1,30 @@
begin
require 'bundler/inline'
require "bundler/inline"
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source 'https://rubygems.org'
source "https://rubygems.org"
# Activate the gem you are reporting the issue against.
gem 'rails', '5.0.0'
gem "rails", "5.0.0"
end
require 'rack/test'
require 'action_controller/railtie'
require "rack/test"
require "action_controller/railtie"
class TestApp < Rails::Application
config.root = File.dirname(__FILE__)
config.session_store :cookie_store, key: 'cookie_store_key'
secrets.secret_token = 'secret_token'
secrets.secret_key_base = 'secret_key_base'
config.session_store :cookie_store, key: "cookie_store_key"
secrets.secret_token = "secret_token"
secrets.secret_key_base = "secret_key_base"
config.logger = Logger.new($stdout)
Rails.logger = config.logger
routes.draw do
get '/' => 'test#index'
get "/" => "test#index"
end
end
@ -32,11 +32,11 @@ class TestController < ActionController::Base
include Rails.application.routes.url_helpers
def index
render plain: 'Home'
render plain: "Home"
end
end
require 'minitest/autorun'
require "minitest/autorun"
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
@ -45,7 +45,7 @@ class BugTest < Minitest::Test
include Rack::Test::Methods
def test_returns_success
get '/'
get "/"
assert last_response.ok?
end

View file

@ -1,28 +1,28 @@
begin
require 'bundler/inline'
require "bundler/inline"
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
source "https://rubygems.org"
gem "rails", github: "rails/rails"
end
require 'action_controller/railtie'
require "action_controller/railtie"
class TestApp < Rails::Application
config.root = File.dirname(__FILE__)
config.session_store :cookie_store, key: 'cookie_store_key'
secrets.secret_token = 'secret_token'
secrets.secret_key_base = 'secret_key_base'
config.session_store :cookie_store, key: "cookie_store_key"
secrets.secret_token = "secret_token"
secrets.secret_key_base = "secret_key_base"
config.logger = Logger.new($stdout)
Rails.logger = config.logger
routes.draw do
get '/' => 'test#index'
get "/" => "test#index"
end
end
@ -30,18 +30,18 @@ class TestController < ActionController::Base
include Rails.application.routes.url_helpers
def index
render plain: 'Home'
render plain: "Home"
end
end
require 'minitest/autorun'
require 'rack/test'
require "minitest/autorun"
require "rack/test"
class BugTest < Minitest::Test
include Rack::Test::Methods
def test_returns_success
get '/'
get "/"
assert last_response.ok?
end

View file

@ -1,26 +1,26 @@
begin
require 'bundler/inline'
require "bundler/inline"
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source 'https://rubygems.org'
source "https://rubygems.org"
# Activate the gem you are reporting the issue against.
gem 'activerecord', '5.0.0'
gem 'sqlite3'
gem "activerecord", "5.0.0"
gem "sqlite3"
end
require 'active_record'
require 'minitest/autorun'
require 'logger'
require "active_record"
require "minitest/autorun"
require "logger"
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do

View file

@ -1,22 +1,22 @@
begin
require 'bundler/inline'
require "bundler/inline"
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'sqlite3'
source "https://rubygems.org"
gem "rails", github: "rails/rails"
gem "sqlite3"
end
require 'active_record'
require 'minitest/autorun'
require 'logger'
require "active_record"
require "minitest/autorun"
require "logger"
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do

View file

@ -1,18 +1,18 @@
begin
require 'bundler/inline'
require "bundler/inline"
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source 'https://rubygems.org'
source "https://rubygems.org"
# Activate the gem you are reporting the issue against.
gem 'activesupport', '5.0.0'
gem "activesupport", "5.0.0"
end
require 'active_support/core_ext/object/blank'
require 'minitest/autorun'
require "active_support/core_ext/object/blank"
require "minitest/autorun"
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)

View file

@ -1,18 +1,18 @@
begin
require 'bundler/inline'
require "bundler/inline"
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
source "https://rubygems.org"
gem "rails", github: "rails/rails"
end
require 'active_support'
require 'active_support/core_ext/object/blank'
require 'minitest/autorun'
require "active_support"
require "active_support/core_ext/object/blank"
require "minitest/autorun"
class BugTest < Minitest::Test
def test_stuff

View file

@ -10,7 +10,7 @@ begin
$:.unshift ap_lib if File.directory?(ap_lib)
rescue LoadError
# Guides generation from gems.
gem "actionpack", '>= 3.0'
gem "actionpack", ">= 3.0"
end
require "rails_guides/generator"

View file

@ -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)

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -26,7 +26,7 @@
#
# ---------------------------------------------------------------------------
require 'w3c_validators'
require "w3c_validators"
include W3CValidators
module RailsGuides
@ -62,11 +62,11 @@ module RailsGuides
guides.delete("./output/layout.html")
guides.delete("./output/_license.html")
guides.delete("./output/_welcome.html")
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|
prefixes.any? {|p| guide.start_with?("./output/#{p}")}
end