rails 4.0.0 → 4.2.11.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +30 -23
  3. data/guides/CHANGELOG.md +108 -6
  4. data/guides/Rakefile +21 -6
  5. data/guides/assets/images/akshaysurve.jpg +0 -0
  6. data/guides/assets/images/edge_badge.png +0 -0
  7. data/guides/assets/images/feature_tile.gif +0 -0
  8. data/guides/assets/images/footer_tile.gif +0 -0
  9. data/guides/assets/images/fxn.png +0 -0
  10. data/guides/assets/images/getting_started/article_with_comments.png +0 -0
  11. data/guides/assets/images/getting_started/challenge.png +0 -0
  12. data/guides/assets/images/getting_started/confirm_dialog.png +0 -0
  13. data/guides/assets/images/getting_started/forbidden_attributes_for_new_article.png +0 -0
  14. data/guides/assets/images/getting_started/form_with_errors.png +0 -0
  15. data/guides/assets/images/getting_started/index_action_with_edit_link.png +0 -0
  16. data/guides/assets/images/getting_started/new_article.png +0 -0
  17. data/guides/assets/images/getting_started/rails_welcome.png +0 -0
  18. data/guides/assets/images/getting_started/routing_error_no_controller.png +0 -0
  19. data/guides/assets/images/getting_started/routing_error_no_route_matches.png +0 -0
  20. data/guides/assets/images/getting_started/show_action_for_articles.png +0 -0
  21. data/guides/assets/images/getting_started/template_is_missing_articles_new.png +0 -0
  22. data/guides/assets/images/getting_started/unknown_action_create_for_articles.png +0 -0
  23. data/guides/assets/images/getting_started/unknown_action_new_for_articles.png +0 -0
  24. data/guides/assets/images/header_tile.gif +0 -0
  25. data/guides/assets/images/icons/README +1 -1
  26. data/guides/assets/images/icons/callouts/11.png +0 -0
  27. data/guides/assets/images/icons/callouts/12.png +0 -0
  28. data/guides/assets/images/icons/callouts/13.png +0 -0
  29. data/guides/assets/images/icons/callouts/15.png +0 -0
  30. data/guides/assets/images/icons/caution.png +0 -0
  31. data/guides/assets/images/icons/example.png +0 -0
  32. data/guides/assets/images/radar.png +0 -0
  33. data/guides/assets/images/rails4_features.png +0 -0
  34. data/guides/assets/images/rails_guides_kindle_cover.jpg +0 -0
  35. data/guides/assets/images/vijaydev.jpg +0 -0
  36. data/guides/assets/javascripts/guides.js +36 -34
  37. data/guides/assets/stylesheets/main.css +6 -2
  38. data/guides/assets/stylesheets/print.css +1 -1
  39. data/guides/bug_report_templates/action_controller_gem.rb +47 -0
  40. data/guides/bug_report_templates/action_controller_master.rb +54 -0
  41. data/guides/bug_report_templates/active_record_gem.rb +5 -2
  42. data/guides/bug_report_templates/active_record_master.rb +3 -2
  43. data/guides/bug_report_templates/generic_gem.rb +15 -0
  44. data/guides/bug_report_templates/generic_master.rb +26 -0
  45. data/guides/rails_guides.rb +23 -4
  46. data/guides/rails_guides/generator.rb +1 -1
  47. data/guides/rails_guides/helpers.rb +4 -2
  48. data/guides/rails_guides/levenshtein.rb +27 -21
  49. data/guides/rails_guides/markdown.rb +11 -7
  50. data/guides/rails_guides/markdown/renderer.rb +1 -1
  51. data/guides/source/2_2_release_notes.md +3 -3
  52. data/guides/source/2_3_release_notes.md +12 -12
  53. data/guides/source/3_0_release_notes.md +10 -13
  54. data/guides/source/3_1_release_notes.md +7 -4
  55. data/guides/source/3_2_release_notes.md +17 -14
  56. data/guides/source/4_0_release_notes.md +110 -54
  57. data/guides/source/4_1_release_notes.md +730 -0
  58. data/guides/source/4_2_release_notes.md +877 -0
  59. data/guides/source/_license.html.erb +1 -1
  60. data/guides/source/_welcome.html.erb +6 -2
  61. data/guides/source/action_controller_overview.md +223 -57
  62. data/guides/source/action_mailer_basics.md +129 -76
  63. data/guides/source/action_view_overview.md +247 -246
  64. data/guides/source/active_job_basics.md +339 -0
  65. data/guides/source/active_model_basics.md +374 -20
  66. data/guides/source/active_record_basics.md +46 -45
  67. data/guides/source/active_record_callbacks.md +83 -28
  68. data/guides/source/{migrations.md → active_record_migrations.md} +191 -275
  69. data/guides/source/active_record_postgresql.md +433 -0
  70. data/guides/source/active_record_querying.md +382 -300
  71. data/guides/source/active_record_validations.md +64 -55
  72. data/guides/source/active_support_core_extensions.md +229 -187
  73. data/guides/source/active_support_instrumentation.md +23 -22
  74. data/guides/source/api_documentation_guidelines.md +167 -15
  75. data/guides/source/asset_pipeline.md +768 -294
  76. data/guides/source/association_basics.md +188 -96
  77. data/guides/source/autoloading_and_reloading_constants.md +1311 -0
  78. data/guides/source/caching_with_rails.md +45 -11
  79. data/guides/source/command_line.md +96 -65
  80. data/guides/source/configuring.md +404 -70
  81. data/guides/source/contributing_to_ruby_on_rails.md +270 -130
  82. data/guides/source/credits.html.erb +7 -3
  83. data/guides/source/debugging_rails_applications.md +471 -284
  84. data/guides/source/development_dependencies_install.md +115 -21
  85. data/guides/source/documents.yaml +31 -9
  86. data/guides/source/engines.md +737 -291
  87. data/guides/source/form_helpers.md +137 -89
  88. data/guides/source/generators.md +60 -28
  89. data/guides/source/getting_started.md +1007 -596
  90. data/guides/source/i18n.md +178 -96
  91. data/guides/source/index.html.erb +2 -1
  92. data/guides/source/initialization.md +248 -104
  93. data/guides/source/kindle/toc.html.erb +1 -1
  94. data/guides/source/layout.html.erb +14 -22
  95. data/guides/source/layouts_and_rendering.md +78 -46
  96. data/guides/source/maintenance_policy.md +78 -0
  97. data/guides/source/nested_model_forms.md +10 -7
  98. data/guides/source/plugins.md +66 -57
  99. data/guides/source/rails_application_templates.md +49 -12
  100. data/guides/source/rails_on_rack.md +50 -60
  101. data/guides/source/routing.md +190 -139
  102. data/guides/source/ruby_on_rails_guides_guidelines.md +12 -13
  103. data/guides/source/security.md +134 -83
  104. data/guides/source/testing.md +322 -200
  105. data/guides/source/upgrading_ruby_on_rails.md +834 -37
  106. data/guides/source/working_with_javascript_in_rails.md +36 -26
  107. data/guides/w3c_validator.rb +2 -0
  108. metadata +93 -116
  109. data/guides/assets/images/getting_started/forbidden_attributes_for_new_post.png +0 -0
  110. data/guides/assets/images/getting_started/new_post.png +0 -0
  111. data/guides/assets/images/getting_started/post_with_comments.png +0 -0
  112. data/guides/assets/images/getting_started/show_action_for_posts.png +0 -0
  113. data/guides/assets/images/getting_started/template_is_missing_posts_new.png +0 -0
  114. data/guides/assets/images/getting_started/undefined_method_post_path.png +0 -0
  115. data/guides/assets/images/getting_started/unknown_action_create_for_posts.png +0 -0
  116. data/guides/assets/images/getting_started/unknown_action_new_for_posts.png +0 -0
  117. data/guides/assets/images/jaimeiniesta.jpg +0 -0
  118. data/guides/code/getting_started/Gemfile +0 -43
  119. data/guides/code/getting_started/Gemfile.lock +0 -150
  120. data/guides/code/getting_started/README.rdoc +0 -28
  121. data/guides/code/getting_started/Rakefile +0 -6
  122. data/guides/code/getting_started/app/assets/javascripts/application.js +0 -16
  123. data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +0 -3
  124. data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +0 -3
  125. data/guides/code/getting_started/app/assets/javascripts/welcome.js.coffee +0 -3
  126. data/guides/code/getting_started/app/assets/stylesheets/application.css +0 -13
  127. data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +0 -3
  128. data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +0 -3
  129. data/guides/code/getting_started/app/assets/stylesheets/welcome.css.scss +0 -3
  130. data/guides/code/getting_started/app/controllers/application_controller.rb +0 -5
  131. data/guides/code/getting_started/app/controllers/comments_controller.rb +0 -17
  132. data/guides/code/getting_started/app/controllers/posts_controller.rb +0 -47
  133. data/guides/code/getting_started/app/controllers/welcome_controller.rb +0 -4
  134. data/guides/code/getting_started/app/helpers/application_helper.rb +0 -2
  135. data/guides/code/getting_started/app/helpers/comments_helper.rb +0 -2
  136. data/guides/code/getting_started/app/helpers/posts_helper.rb +0 -2
  137. data/guides/code/getting_started/app/helpers/welcome_helper.rb +0 -2
  138. data/guides/code/getting_started/app/models/comment.rb +0 -3
  139. data/guides/code/getting_started/app/models/post.rb +0 -7
  140. data/guides/code/getting_started/app/views/comments/_comment.html.erb +0 -15
  141. data/guides/code/getting_started/app/views/comments/_form.html.erb +0 -13
  142. data/guides/code/getting_started/app/views/layouts/application.html.erb +0 -14
  143. data/guides/code/getting_started/app/views/posts/_form.html.erb +0 -27
  144. data/guides/code/getting_started/app/views/posts/edit.html.erb +0 -5
  145. data/guides/code/getting_started/app/views/posts/index.html.erb +0 -21
  146. data/guides/code/getting_started/app/views/posts/new.html.erb +0 -5
  147. data/guides/code/getting_started/app/views/posts/show.html.erb +0 -18
  148. data/guides/code/getting_started/app/views/welcome/index.html.erb +0 -3
  149. data/guides/code/getting_started/bin/bundle +0 -4
  150. data/guides/code/getting_started/bin/rails +0 -4
  151. data/guides/code/getting_started/bin/rake +0 -4
  152. data/guides/code/getting_started/config.ru +0 -4
  153. data/guides/code/getting_started/config/application.rb +0 -18
  154. data/guides/code/getting_started/config/boot.rb +0 -4
  155. data/guides/code/getting_started/config/database.yml +0 -25
  156. data/guides/code/getting_started/config/environment.rb +0 -5
  157. data/guides/code/getting_started/config/environments/development.rb +0 -30
  158. data/guides/code/getting_started/config/environments/production.rb +0 -80
  159. data/guides/code/getting_started/config/environments/test.rb +0 -36
  160. data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +0 -7
  161. data/guides/code/getting_started/config/initializers/filter_parameter_logging.rb +0 -4
  162. data/guides/code/getting_started/config/initializers/inflections.rb +0 -16
  163. data/guides/code/getting_started/config/initializers/locale.rb +0 -9
  164. data/guides/code/getting_started/config/initializers/mime_types.rb +0 -5
  165. data/guides/code/getting_started/config/initializers/secret_token.rb +0 -12
  166. data/guides/code/getting_started/config/initializers/session_store.rb +0 -3
  167. data/guides/code/getting_started/config/initializers/wrap_parameters.rb +0 -14
  168. data/guides/code/getting_started/config/locales/en.yml +0 -23
  169. data/guides/code/getting_started/config/routes.rb +0 -7
  170. data/guides/code/getting_started/db/migrate/20130122042648_create_posts.rb +0 -10
  171. data/guides/code/getting_started/db/migrate/20130122045842_create_comments.rb +0 -11
  172. data/guides/code/getting_started/db/schema.rb +0 -33
  173. data/guides/code/getting_started/db/seeds.rb +0 -7
  174. data/guides/code/getting_started/public/404.html +0 -58
  175. data/guides/code/getting_started/public/422.html +0 -58
  176. data/guides/code/getting_started/public/500.html +0 -57
  177. data/guides/code/getting_started/public/favicon.ico +0 -0
  178. data/guides/code/getting_started/public/robots.txt +0 -5
  179. data/guides/code/getting_started/test/controllers/comments_controller_test.rb +0 -7
  180. data/guides/code/getting_started/test/controllers/posts_controller_test.rb +0 -7
  181. data/guides/code/getting_started/test/controllers/welcome_controller_test.rb +0 -9
  182. data/guides/code/getting_started/test/fixtures/comments.yml +0 -11
  183. data/guides/code/getting_started/test/fixtures/posts.yml +0 -9
  184. data/guides/code/getting_started/test/helpers/comments_helper_test.rb +0 -4
  185. data/guides/code/getting_started/test/helpers/posts_helper_test.rb +0 -4
  186. data/guides/code/getting_started/test/helpers/welcome_helper_test.rb +0 -4
  187. data/guides/code/getting_started/test/models/comment_test.rb +0 -7
  188. data/guides/code/getting_started/test/models/post_test.rb +0 -7
  189. data/guides/code/getting_started/test/test_helper.rb +0 -15
  190. data/guides/source/kindle/KINDLE.md +0 -26
@@ -129,6 +129,7 @@ body {
129
129
  font-family: Helvetica, Arial, Sans-Serif;
130
130
  text-decoration: none;
131
131
  vertical-align: middle;
132
+ cursor: pointer;
132
133
  }
133
134
  .red-button:active {
134
135
  border-top: none;
@@ -244,7 +245,7 @@ body {
244
245
  #subCol {
245
246
  position: absolute;
246
247
  z-index: 0;
247
- top: 0;
248
+ top: 21px;
248
249
  right: 0;
249
250
  background: #FFF;
250
251
  padding: 1em 1.5em 1em 1.25em;
@@ -380,9 +381,12 @@ a, a:link, a:visited {
380
381
  font: inherit;
381
382
  padding-left: .75em;
382
383
  font-size: .95em;
383
- background-position: 96% -65px;
384
+ background-position: 96% 16px;
384
385
  -webkit-appearance: none;
385
386
  }
387
+ .guides-index-small .guides-index-item:hover{
388
+ background-position: 96% -65px;
389
+ }
386
390
  }
387
391
 
388
392
  #guides {
@@ -36,7 +36,7 @@ hr {
36
36
  }
37
37
 
38
38
  h1,h2,h3,h4,h5,h6 { font-family: "Helvetica Neue", Arial, "Lucida Grande", sans-serif; }
39
- code { font:.9em "Courier New", Monaco, Courier, monospace; }
39
+ code { font:.9em "Courier New", Monaco, Courier, monospace; display:inline}
40
40
 
41
41
  img { float:left; margin:1.5em 1.5em 1.5em 0; }
42
42
  a img { border:none; }
@@ -0,0 +1,47 @@
1
+ # Activate the gem you are reporting the issue against.
2
+ gem 'rails', '4.2.0'
3
+
4
+ require 'rails'
5
+ require 'action_controller/railtie'
6
+
7
+ class TestApp < Rails::Application
8
+ config.root = File.dirname(__FILE__)
9
+ config.session_store :cookie_store, key: 'cookie_store_key'
10
+ secrets.secret_token = 'secret_token'
11
+ secrets.secret_key_base = 'secret_key_base'
12
+
13
+ config.logger = Logger.new($stdout)
14
+ Rails.logger = config.logger
15
+
16
+ routes.draw do
17
+ get '/' => 'test#index'
18
+ end
19
+ end
20
+
21
+ class TestController < ActionController::Base
22
+ include Rails.application.routes.url_helpers
23
+
24
+ def index
25
+ render text: 'Home'
26
+ end
27
+ end
28
+
29
+ require 'minitest/autorun'
30
+ require 'rack/test'
31
+
32
+ # Ensure backward compatibility with Minitest 4
33
+ Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
34
+
35
+ class BugTest < Minitest::Test
36
+ include Rack::Test::Methods
37
+
38
+ def test_returns_success
39
+ get '/'
40
+ assert last_response.ok?
41
+ end
42
+
43
+ private
44
+ def app
45
+ Rails.application
46
+ end
47
+ end
@@ -0,0 +1,54 @@
1
+ unless File.exist?('Gemfile')
2
+ File.write('Gemfile', <<-GEMFILE)
3
+ source 'https://rubygems.org'
4
+ gem 'rails', github: 'rails/rails'
5
+ gem 'arel', github: 'rails/arel'
6
+ GEMFILE
7
+
8
+ system 'bundle'
9
+ end
10
+
11
+ require 'bundler'
12
+ Bundler.setup(:default)
13
+
14
+ require 'rails'
15
+ require 'action_controller/railtie'
16
+
17
+ class TestApp < Rails::Application
18
+ config.root = File.dirname(__FILE__)
19
+ config.session_store :cookie_store, key: 'cookie_store_key'
20
+ secrets.secret_token = 'secret_token'
21
+ secrets.secret_key_base = 'secret_key_base'
22
+
23
+ config.logger = Logger.new($stdout)
24
+ Rails.logger = config.logger
25
+
26
+ routes.draw do
27
+ get '/' => 'test#index'
28
+ end
29
+ end
30
+
31
+ class TestController < ActionController::Base
32
+ include Rails.application.routes.url_helpers
33
+
34
+ def index
35
+ render text: 'Home'
36
+ end
37
+ end
38
+
39
+ require 'minitest/autorun'
40
+ require 'rack/test'
41
+
42
+ class BugTest < Minitest::Test
43
+ include Rack::Test::Methods
44
+
45
+ def test_returns_success
46
+ get '/'
47
+ assert last_response.ok?
48
+ end
49
+
50
+ private
51
+ def app
52
+ Rails.application
53
+ end
54
+ end
@@ -1,9 +1,12 @@
1
1
  # Activate the gem you are reporting the issue against.
2
- gem 'activerecord', '3.2.13'
2
+ gem 'activerecord', '4.2.0'
3
3
  require 'active_record'
4
4
  require 'minitest/autorun'
5
5
  require 'logger'
6
6
 
7
+ # Ensure backward compatibility with Minitest 4
8
+ Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
9
+
7
10
  # This connection will do for database-independent bug reports.
8
11
  ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
9
12
  ActiveRecord::Base.logger = Logger.new(STDOUT)
@@ -25,7 +28,7 @@ class Comment < ActiveRecord::Base
25
28
  belongs_to :post
26
29
  end
27
30
 
28
- class BugTest < MiniTest::Unit::TestCase
31
+ class BugTest < Minitest::Test
29
32
  def test_association_stuff
30
33
  post = Post.create!
31
34
  post.comments << Comment.create!
@@ -1,7 +1,8 @@
1
- unless File.exists?('Gemfile')
1
+ unless File.exist?('Gemfile')
2
2
  File.write('Gemfile', <<-GEMFILE)
3
3
  source 'https://rubygems.org'
4
4
  gem 'rails', github: 'rails/rails'
5
+ gem 'arel', github: 'rails/arel'
5
6
  gem 'sqlite3'
6
7
  GEMFILE
7
8
 
@@ -36,7 +37,7 @@ class Comment < ActiveRecord::Base
36
37
  belongs_to :post
37
38
  end
38
39
 
39
- class BugTest < MiniTest::Unit::TestCase
40
+ class BugTest < Minitest::Test
40
41
  def test_association_stuff
41
42
  post = Post.create!
42
43
  post.comments << Comment.create!
@@ -0,0 +1,15 @@
1
+ # Activate the gems you are reporting the issue against.
2
+ gem 'activesupport', '4.2.0'
3
+ require 'active_support'
4
+ require 'active_support/core_ext/object/blank'
5
+ require 'minitest/autorun'
6
+
7
+ # Ensure backward compatibility with Minitest 4
8
+ Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
9
+
10
+ class BugTest < Minitest::Test
11
+ def test_stuff
12
+ assert "zomg".present?
13
+ refute "".present?
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ unless File.exist?('Gemfile')
2
+ File.write('Gemfile', <<-GEMFILE)
3
+ source 'https://rubygems.org'
4
+ gem 'rails', github: 'rails/rails'
5
+ gem 'arel', github: 'rails/arel'
6
+ GEMFILE
7
+
8
+ system 'bundle'
9
+ end
10
+
11
+ require 'bundler'
12
+ Bundler.setup(:default)
13
+
14
+ require 'active_support'
15
+ require 'active_support/core_ext/object/blank'
16
+ require 'minitest/autorun'
17
+
18
+ # Ensure backward compatibility with Minitest 4
19
+ Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
20
+
21
+ class BugTest < Minitest::Test
22
+ def test_stuff
23
+ assert "zomg".present?
24
+ refute "".present?
25
+ end
26
+ end
@@ -5,7 +5,7 @@ $:.unshift pwd
5
5
  def bundler?
6
6
  # Note that rake sets the cwd to the one that contains the Rakefile
7
7
  # being executed.
8
- File.exists?('Gemfile')
8
+ File.exist?('Gemfile')
9
9
  end
10
10
 
11
11
  begin
@@ -22,13 +22,32 @@ end
22
22
 
23
23
  begin
24
24
  require 'redcarpet'
25
- rescue Gem::LoadError
25
+ rescue LoadError
26
+ # This can happen if doc:guides is executed in an application.
27
+ $stderr.puts('Generating guides requires Redcarpet 3.1.2+.')
28
+ $stderr.puts(<<ERROR) if bundler?
29
+ Please add
30
+
31
+ gem 'redcarpet', '~> 3.1.2'
32
+
33
+ to the Gemfile, run
34
+
35
+ bundle install
36
+
37
+ and try again.
38
+ ERROR
39
+ exit 1
40
+ end
41
+
42
+ begin
43
+ require 'nokogiri'
44
+ rescue LoadError
26
45
  # This can happen if doc:guides is executed in an application.
27
- $stderr.puts('Generating guides requires Redcarpet 2.1.1+.')
46
+ $stderr.puts('Generating guides requires Nokogiri.')
28
47
  $stderr.puts(<<ERROR) if bundler?
29
48
  Please add
30
49
 
31
- gem 'redcarpet', '~> 2.1.1'
50
+ gem 'nokogiri'
32
51
 
33
52
  to the Gemfile, run
34
53
 
@@ -184,7 +184,7 @@ module RailsGuides
184
184
  def generate?(source_file, output_file)
185
185
  fin = File.join(source_dir, source_file)
186
186
  fout = output_path_for(output_file)
187
- all || !File.exists?(fout) || File.mtime(fout) < File.mtime(fin)
187
+ all || !File.exist?(fout) || File.mtime(fout) < File.mtime(fin)
188
188
  end
189
189
 
190
190
  def generate_guide(guide, output_file)
@@ -1,3 +1,5 @@
1
+ require 'yaml'
2
+
1
3
  module RailsGuides
2
4
  module Helpers
3
5
  def guide(name, url, options = {}, &block)
@@ -17,7 +19,7 @@ module RailsGuides
17
19
  end
18
20
 
19
21
  def documents_flat
20
- documents_by_section.map {|section| section['documents']}.flatten
22
+ documents_by_section.flat_map {|section| section['documents']}
21
23
  end
22
24
 
23
25
  def finished_documents(documents)
@@ -37,7 +39,7 @@ module RailsGuides
37
39
  def author(name, nick, image = 'credits_pic_blank.gif', &block)
38
40
  image = "images/#{image}"
39
41
 
40
- result = content_tag(:img, nil, :src => image, :class => 'left pic', :alt => name, :width => 91, :height => 91)
42
+ result = tag(:img, :src => image, :class => 'left pic', :alt => name, :width => 91, :height => 91)
41
43
  result << content_tag(:h3, name)
42
44
  result << content_tag(:p, capture(&block))
43
45
  content_tag(:div, result, :class => 'clearfix', :id => nick)
@@ -1,31 +1,37 @@
1
1
  module RailsGuides
2
2
  module Levenshtein
3
- # Based on the pseudocode in http://en.wikipedia.org/wiki/Levenshtein_distance
4
- def self.distance(s1, s2)
5
- s = s1.unpack('U*')
6
- t = s2.unpack('U*')
7
- m = s.length
8
- n = t.length
3
+ # This code is based directly on the Text gem implementation
4
+ # Returns a value representing the "cost" of transforming str1 into str2
5
+ def self.distance str1, str2
6
+ s = str1
7
+ t = str2
8
+ n = s.length
9
+ m = t.length
9
10
 
10
- # matrix initialization
11
- d = []
12
- 0.upto(m) { |i| d << [i] }
13
- 0.upto(n) { |j| d[0][j] = j }
11
+ return m if (0 == n)
12
+ return n if (0 == m)
14
13
 
15
- # distance computation
16
- 1.upto(m) do |i|
17
- 1.upto(n) do |j|
18
- cost = s[i] == t[j] ? 0 : 1
19
- d[i][j] = [
20
- d[i-1][j] + 1, # deletion
21
- d[i][j-1] + 1, # insertion
22
- d[i-1][j-1] + cost, # substitution
23
- ].min
14
+ d = (0..m).to_a
15
+ x = nil
16
+
17
+ str1.each_char.each_with_index do |char1,i|
18
+ e = i+1
19
+
20
+ str2.each_char.each_with_index do |char2,j|
21
+ cost = (char1 == char2) ? 0 : 1
22
+ x = [
23
+ d[j+1] + 1, # insertion
24
+ e + 1, # deletion
25
+ d[j] + cost # substitution
26
+ ].min
27
+ d[j] = e
28
+ e = x
24
29
  end
30
+
31
+ d[m] = x
25
32
  end
26
33
 
27
- # all done
28
- return d[m][n]
34
+ return x
29
35
  end
30
36
  end
31
37
  end
@@ -47,8 +47,12 @@ module RailsGuides
47
47
  end
48
48
 
49
49
  def dom_id_text(text)
50
- text.downcase.gsub(/\?/, '-questionmark').gsub(/!/, '-bang').gsub(/[^a-z0-9]+/, ' ')
51
- .strip.gsub(/\s+/, '-')
50
+ escaped_chars = Regexp.escape('\\/`*_{}[]()#+-.!:,;|&<>^~=\'"')
51
+
52
+ text.downcase.gsub(/\?/, '-questionmark')
53
+ .gsub(/!/, '-bang')
54
+ .gsub(/[#{escaped_chars}]+/, ' ').strip
55
+ .gsub(/\s+/, '-')
52
56
  end
53
57
 
54
58
  def engine
@@ -79,10 +83,10 @@ module RailsGuides
79
83
  def generate_structure
80
84
  @headings_for_index = []
81
85
  if @body.present?
82
- @body = Nokogiri::HTML(@body).tap do |doc|
86
+ @body = Nokogiri::HTML.fragment(@body).tap do |doc|
83
87
  hierarchy = []
84
88
 
85
- doc.at('body').children.each do |node|
89
+ doc.children.each do |node|
86
90
  if node.name =~ /^h[3-6]$/
87
91
  case node.name
88
92
  when 'h3'
@@ -116,7 +120,7 @@ module RailsGuides
116
120
  end
117
121
  end
118
122
 
119
- @index = Nokogiri::HTML(engine.render(raw_index)).tap do |doc|
123
+ @index = Nokogiri::HTML.fragment(engine.render(raw_index)).tap do |doc|
120
124
  doc.at('ol')[:class] = 'chapters'
121
125
  end.to_html
122
126
 
@@ -130,8 +134,8 @@ module RailsGuides
130
134
  end
131
135
 
132
136
  def generate_title
133
- if heading = Nokogiri::HTML(@header).at(:h2)
134
- @title = "#{heading.text} — Ruby on Rails Guides".html_safe
137
+ if heading = Nokogiri::HTML.fragment(@header).at(:h2)
138
+ @title = "#{heading.text} — Ruby on Rails Guides"
135
139
  else
136
140
  @title = "Ruby on Rails Guides"
137
141
  end
@@ -50,7 +50,7 @@ HTML
50
50
  when 'erb'
51
51
  'ruby; html-script: true'
52
52
  when 'html'
53
- 'xml' # html is understood, but there are .xml rules in the CSS
53
+ 'xml' # HTML is understood, but there are .xml rules in the CSS
54
54
  else
55
55
  'plain'
56
56
  end
@@ -1,7 +1,7 @@
1
1
  Ruby on Rails 2.2 Release Notes
2
2
  ===============================
3
3
 
4
- Rails 2.2 delivers a number of new and improved features. This list covers the major upgrades, but doesn't include every little bug fix and change. If you want to see everything, check out the [list of commits](http://github.com/rails/rails/commits/master) in the main Rails repository on GitHub.
4
+ Rails 2.2 delivers a number of new and improved features. This list covers the major upgrades, but doesn't include every little bug fix and change. If you want to see everything, check out the [list of commits](http://github.com/rails/rails/commits/2-2-stable) in the main Rails repository on GitHub.
5
5
 
6
6
  Along with Rails, 2.2 marks the launch of the [Ruby on Rails Guides](http://guides.rubyonrails.org/), the first results of the ongoing [Rails Guides hackfest](http://hackfest.rubyonrails.org/guide). This site will deliver high-quality documentation of the major features of Rails.
7
7
 
@@ -327,7 +327,7 @@ Other features of memoization include `unmemoize`, `unmemoize_all`, and `memoize
327
327
  The `each_with_object` method provides an alternative to `inject`, using a method backported from Ruby 1.9. It iterates over a collection, passing the current element and the memo into the block.
328
328
 
329
329
  ```ruby
330
- %w(foo bar).each_with_object({}) { |str, hsh| hsh[str] = str.upcase } #=> {'foo' => 'FOO', 'bar' => 'BAR'}
330
+ %w(foo bar).each_with_object({}) { |str, hsh| hsh[str] = str.upcase } # => {'foo' => 'FOO', 'bar' => 'BAR'}
331
331
  ```
332
332
 
333
333
  Lead Contributor: [Adam Keys](http://therealadam.com/)
@@ -366,7 +366,7 @@ Lead Contributor: [Daniel Schierbeck](http://workingwithrails.com/person/5830-da
366
366
  * `Inflector#parameterize` produces a URL-ready version of its input, for use in `to_param`.
367
367
  * `Time#advance` recognizes fractional days and weeks, so you can do `1.7.weeks.ago`, `1.5.hours.since`, and so on.
368
368
  * The included TzInfo library has been upgraded to version 0.3.12.
369
- * `ActiveSuport::StringInquirer` gives you a pretty way to test for equality in strings: `ActiveSupport::StringInquirer.new("abc").abc? => true`
369
+ * `ActiveSupport::StringInquirer` gives you a pretty way to test for equality in strings: `ActiveSupport::StringInquirer.new("abc").abc? => true`
370
370
 
371
371
  Railties
372
372
  --------