Skip to content

Commit 18eb80c

Browse files
committed
Merge docrails
1 parent 4185a4a commit 18eb80c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1915
-876
lines changed

actionpack/lib/action_controller/integration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
module ActionController
66
module Integration #:nodoc:
77
# An integration Session instance represents a set of requests and responses
8-
# performed sequentially by some virtual user. Becase you can instantiate
8+
# performed sequentially by some virtual user. Because you can instantiate
99
# multiple sessions and run them side-by-side, you can also mimic (to some
1010
# limited extent) multiple simultaneous users interacting with your system.
1111
#

actionpack/lib/action_view/helpers/date_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,8 +876,8 @@ def input_id_from_type(type)
876876
input_name_from_type(type).gsub(/([\[\(])|(\]\[)/, '_').gsub(/[\]\)]/, '')
877877
end
878878

879-
# Given an ordering of datetime components, create the selection html
880-
# and join them with their appropriate seperators
879+
# Given an ordering of datetime components, create the selection HTML
880+
# and join them with their appropriate separators.
881881
def build_selects_from_types(order)
882882
select = ''
883883
order.reverse.each do |type|

actionpack/lib/action_view/helpers/number_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def number_to_percentage(number, options = {})
140140
# number_with_delimiter(12345678) # => 12,345,678
141141
# number_with_delimiter(12345678.05) # => 12,345,678.05
142142
# number_with_delimiter(12345678, :delimiter => ".") # => 12.345.678
143-
# number_with_delimiter(12345678, :seperator => ",") # => 12,345,678
143+
# number_with_delimiter(12345678, :separator => ",") # => 12,345,678
144144
# number_with_delimiter(98765432.98, :delimiter => " ", :separator => ",")
145145
# # => 98 765 432,98
146146
#

activemodel/lib/active_model/validations/inclusion.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module ClassMethods
44
# Validates whether the value of the specified attribute is available in a particular enumerable object.
55
#
66
# class Person < ActiveRecord::Base
7-
# validates_inclusion_of :gender, :in => %w( m f ), :message => "woah! what are you then!??!!"
7+
# validates_inclusion_of :gender, :in => %w( m f )
88
# validates_inclusion_of :age, :in => 0..99
99
# validates_inclusion_of :format, :in => %w( jpg gif png ), :message => "extension %s is not included in the list"
1010
# end

activerecord/lib/active_record/associations/association_collection.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ def transaction(*args)
143143
end
144144

145145
# Remove all records from this association
146+
#
147+
# See delete for more info.
146148
def delete_all
147149
load_target
148150
delete(@target)
@@ -200,11 +202,11 @@ def delete(*records)
200202
end
201203
end
202204

203-
# Destroy +records+ and remove from this association calling +before_remove+
204-
# and +after_remove+ callbacks.
205+
# Destroy +records+ and remove them from this association calling
206+
# +before_remove+ and +after_remove+ callbacks.
205207
#
206-
# Note this method will always remove records from database ignoring the
207-
# +:dependent+ option.
208+
# Note that this method will _always_ remove records from the database
209+
# ignoring the +:dependent+ option.
208210
def destroy(*records)
209211
remove_records(records) do |records, old_records|
210212
old_records.each { |record| record.destroy }
@@ -226,7 +228,9 @@ def clear
226228
self
227229
end
228230

229-
# Destory all the records from this association
231+
# Destory all the records from this association.
232+
#
233+
# See destroy for more info.
230234
def destroy_all
231235
load_target
232236
destroy(@target)

activerecord/lib/active_record/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,12 +736,12 @@ def create(attributes = nil, &block)
736736
# ==== Parameters
737737
#
738738
# * +id+ - This should be the id or an array of ids to be updated.
739-
# * +attributes+ - This should be a Hash of attributes to be set on the object, or an array of Hashes.
739+
# * +attributes+ - This should be a hash of attributes to be set on the object, or an array of hashes.
740740
#
741741
# ==== Examples
742742
#
743743
# # Updating one record:
744-
# Person.update(15, { :user_name => 'Samuel', :group => 'expert' })
744+
# Person.update(15, :user_name => 'Samuel', :group => 'expert')
745745
#
746746
# # Updating multiple records:
747747
# people = { 1 => { "first_name" => "David" }, 2 => { "first_name" => "Jeremy" } }

activerecord/lib/active_record/batches.rb

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@ def self.included(base)
44
base.extend(ClassMethods)
55
end
66

7-
# When processing large numbers of records, it's often a good idea to do so in batches to prevent memory ballooning.
7+
# When processing large numbers of records, it's often a good idea to do
8+
# so in batches to prevent memory ballooning.
89
module ClassMethods
9-
# Yields each record that was found by the find +options+. The find is performed by find_in_batches
10-
# with a batch size of 1000 (or as specified by the +batch_size+ option).
10+
# Yields each record that was found by the find +options+. The find is
11+
# performed by find_in_batches with a batch size of 1000 (or as
12+
# specified by the <tt>:batch_size</tt> option).
1113
#
1214
# Example:
1315
#
1416
# Person.find_each(:conditions => "age > 21") do |person|
1517
# person.party_all_night!
1618
# end
1719
#
18-
# Note: This method is only intended to use for batch processing of large amounts of records that wouldn't fit in
19-
# memory all at once. If you just need to loop over less than 1000 records, it's probably better just to use the
20-
# regular find methods.
20+
# Note: This method is only intended to use for batch processing of
21+
# large amounts of records that wouldn't fit in memory all at once. If
22+
# you just need to loop over less than 1000 records, it's probably
23+
# better just to use the regular find methods.
2124
def find_each(options = {})
2225
find_in_batches(options) do |records|
2326
records.each { |record| yield record }
@@ -26,17 +29,22 @@ def find_each(options = {})
2629
self
2730
end
2831

29-
# Yields each batch of records that was found by the find +options+ as an array. The size of each batch is
30-
# set by the +batch_size+ option; the default is 1000.
32+
# Yields each batch of records that was found by the find +options+ as
33+
# an array. The size of each batch is set by the <tt>:batch_size</tt>
34+
# option; the default is 1000.
3135
#
32-
# You can control the starting point for the batch processing by supplying the +start+ option. This is especially
33-
# useful if you want multiple workers dealing with the same processing queue. You can make worker 1 handle all the
34-
# records between id 0 and 10,000 and worker 2 handle from 10,000 and beyond (by setting the +start+ option on that
35-
# worker).
36+
# You can control the starting point for the batch processing by
37+
# supplying the <tt>:start</tt> option. This is especially useful if you
38+
# want multiple workers dealing with the same processing queue. You can
39+
# make worker 1 handle all the records between id 0 and 10,000 and
40+
# worker 2 handle from 10,000 and beyond (by setting the <tt>:start</tt>
41+
# option on that worker).
3642
#
37-
# It's not possible to set the order. That is automatically set to ascending on the primary key ("id ASC")
38-
# to make the batch ordering work. This also mean that this method only works with integer-based primary keys.
39-
# You can't set the limit either, that's used to control the the batch sizes.
43+
# It's not possible to set the order. That is automatically set to
44+
# ascending on the primary key ("id ASC") to make the batch ordering
45+
# work. This also mean that this method only works with integer-based
46+
# primary keys. You can't set the limit either, that's used to control
47+
# the the batch sizes.
4048
#
4149
# Example:
4250
#

activerecord/lib/active_record/validations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ def validates_format_of(*attr_names)
802802
# Validates whether the value of the specified attribute is available in a particular enumerable object.
803803
#
804804
# class Person < ActiveRecord::Base
805-
# validates_inclusion_of :gender, :in => %w( m f ), :message => "woah! what are you then!??!!"
805+
# validates_inclusion_of :gender, :in => %w( m f )
806806
# validates_inclusion_of :age, :in => 0..99
807807
# validates_inclusion_of :format, :in => %w( jpg gif png ), :message => "extension {{value}} is not included in the list"
808808
# end

activesupport/lib/active_support/core_ext/date/calculations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module ActiveSupport #:nodoc:
22
module CoreExtensions #:nodoc:
33
module Date #:nodoc:
4-
# Enables the use of time calculations within Time itself
4+
# Enables the use of time calculations within Date itself
55
module Calculations
66
def self.included(base) #:nodoc:
77
base.extend ClassMethods

railties/guides/files/stylesheets/main.css

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ h6 {
337337
margin-top: 0.25em;
338338
}
339339

340-
#mainCol dd.warning, #subCol dd.warning {
340+
#mainCol div.warning, #subCol dd.warning {
341341
background: #f9d9d8 url(http://github.com/..%3Cspan%20class=pl-c1%3E/%3C/span%3E..%3Cspan%20class=pl-c1%3E/%3C/span%3Eimages/tab_red.gif) no-repeat left top;
342342
border: none;
343343
padding: 1.25em 1.25em 1.25em 48px;
@@ -426,4 +426,16 @@ code {
426426
.clearfix {display: inline-block;}
427427
* html .clearfix {height: 1%;}
428428
.clearfix {display: block;}
429-
.clear { clear:both; }
429+
.clear { clear:both; }
430+
431+
/* Same bottom margin for special boxes than for regular paragraphs, this way
432+
intermediate whitespace looks uniform. */
433+
div.code_container, div.important, div.caution, div.warning, div.note, div.info {
434+
margin-bottom: 1.5em;
435+
}
436+
437+
/* Remove bottom margin of paragraphs in special boxes, otherwise they get a
438+
spurious blank area below with the box background. */
439+
div.important p, div.caution p, div.warning p, div.note p, div.info p {
440+
margin-bottom: 0px;
441+
}
6.06 KB
Loading

railties/guides/images/fxn.jpg

17.4 KB
Loading
Loading
Loading
Loading
Loading
-20.4 KB
Loading

railties/guides/rails_guides.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module RailsGuides
2222
autoload :Indexer, "rails_guides/indexer"
2323
autoload :Helpers, "rails_guides/helpers"
2424
autoload :TextileExtensions, "rails_guides/textile_extensions"
25+
autoload :Levenshtein, "rails_guides/levenshtein"
2526
end
2627

2728
RedCloth.send(:include, RailsGuides::TextileExtensions)

railties/guides/rails_guides/generator.rb

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ def set_index(body, view)
109109
end
110110

111111
def textile(body)
112-
# If the issue with nontextile is fixed just remove the wrapper.
113-
with_workaround_for_nontextile(body) do |body|
112+
# If the issue with notextile is fixed just remove the wrapper.
113+
with_workaround_for_notextile(body) do |body|
114114
t = RedCloth.new(body)
115115
t.hard_breaks = false
116116
t.to_html(:notestuff, :plusplus, :code, :tip)
@@ -120,33 +120,51 @@ def textile(body)
120120
# For some reason the notextile tag does not always turn off textile. See
121121
# LH ticket of the security guide (#7). As a temporary workaround we deal
122122
# with code blocks by hand.
123-
def with_workaround_for_nontextile(body)
123+
def with_workaround_for_notextile(body)
124124
code_blocks = []
125125
body.gsub!(%r{<(yaml|shell|ruby|erb|html|sql|plain)>(.*?)</\1>}m) do |m|
126126
es = ERB::Util.h($2)
127127
css_class = ['erb', 'shell'].include?($1) ? 'html' : $1
128128
code_blocks << %{<div class="code_container"><code class="#{css_class}">#{es}</code></div>}
129-
"dirty_workaround_for_nontextile_#{code_blocks.size - 1}"
129+
"\ndirty_workaround_for_notextile_#{code_blocks.size - 1}\n"
130130
end
131131

132132
body = yield body
133133

134-
body.gsub(%r{<p>dirty_workaround_for_nontextile_(\d+)</p>}) do |_|
134+
body.gsub(%r{<p>dirty_workaround_for_notextile_(\d+)</p>}) do |_|
135135
code_blocks[$1.to_i]
136136
end
137137
end
138138

139139
def warn_about_broken_links(html)
140+
anchors = extract_anchors(html)
141+
check_fragment_identifiers(html, anchors)
142+
end
143+
144+
def extract_anchors(html)
140145
# Textile generates headers with IDs computed from titles.
141-
anchors = Set.new(html.scan(/<h\d\s+id="([^"]+)/).flatten)
146+
anchors = Set.new
147+
html.scan(/<h\d\s+id="([^"]+)/).flatten.each do |anchor|
148+
if anchors.member?(anchor)
149+
puts "*** DUPLICATE HEADER ID: #{anchor}, please consider rewording"
150+
else
151+
anchors << anchor
152+
end
153+
end
154+
142155
# Also, footnotes are rendered as paragraphs this way.
143156
anchors += Set.new(html.scan(/<p\s+class="footnote"\s+id="([^"]+)/).flatten)
144-
145-
# Check fragment identifiers.
157+
return anchors
158+
end
159+
160+
def check_fragment_identifiers(html, anchors)
146161
html.scan(/<a\s+href="#([^"]+)/).flatten.each do |fragment_identifier|
147162
next if fragment_identifier == 'mainCol' # in layout, jumps to some DIV
148163
unless anchors.member?(fragment_identifier)
149-
puts "BROKEN LINK: ##{fragment_identifier}"
164+
guess = anchors.min { |a, b|
165+
Levenshtein.distance(fragment_identifier, a) <=> Levenshtein.distance(fragment_identifier, b)
166+
}
167+
puts "*** BROKEN LINK: ##{fragment_identifier}, perhaps you meant ##{guess}."
150168
end
151169
end
152170
end

railties/guides/rails_guides/indexer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def process(string, current_level= 3, counters = [1])
2929
return level_hash
3030
elsif level == current_level
3131
index = counters.join(".")
32-
bookmark = '#' + title.gsub(/[^a-z0-9\-_]+/i, '').underscore.dasherize
32+
bookmark = '#' + title.strip.downcase.gsub(/\s+|_/, '-').delete('^a-z0-9-')
3333

3434
raise "Parsing Fail" unless @result.sub!(matched, "h#{level}(#{bookmark}). #{index}#{title}")
3535

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#
2+
# Levenshtein distance algorithm implementation for Ruby, with UTF-8 support
3+
#
4+
# Author:: Paul BATTLEY (pbattley @ gmail.com)
5+
# Version:: 1.3
6+
# Date:: 2005-04-19
7+
#
8+
# == About
9+
#
10+
# The Levenshtein distance is a measure of how similar two strings s and t are,
11+
# calculated as the number of deletions/insertions/substitutions needed to
12+
# transform s into t. The greater the distance, the more the strings differ.
13+
#
14+
# The Levenshtein distance is also sometimes referred to as the
15+
# easier-to-pronounce-and-spell 'edit distance'.
16+
#
17+
# == Revision history
18+
#
19+
# * 2005-05-19 1.3 Repairing an oversight, distance can now be called via
20+
# Levenshtein.distance(s, t)
21+
# * 2005-05-04 1.2 Now uses just one 1-dimensional array. I think this is as
22+
# far as optimisation can go.
23+
# * 2005-05-04 1.1 Now storing only the current and previous rows of the matrix
24+
# instead of the whole lot.
25+
#
26+
# == Licence
27+
#
28+
# Copyright (c) 2005 Paul Battley
29+
#
30+
# Usage of the works is permitted provided that this instrument is retained
31+
# with the works, so that any entity that uses the works is notified of this
32+
# instrument.
33+
#
34+
# DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
35+
#
36+
37+
module Levenshtein
38+
39+
#
40+
# Calculate the Levenshtein distance between two strings +str1+ and +str2+.
41+
# +str1+ and +str2+ should be ASCII or UTF-8.
42+
#
43+
def distance(str1, str2)
44+
s = str1.unpack('U*')
45+
t = str2.unpack('U*')
46+
n = s.length
47+
m = t.length
48+
return m if (0 == n)
49+
return n if (0 == m)
50+
51+
d = (0..m).to_a
52+
x = nil
53+
54+
(0...n).each do |i|
55+
e = i+1
56+
(0...m).each do |j|
57+
cost = (s[i] == t[j]) ? 0 : 1
58+
x = [
59+
d[j+1] + 1, # insertion
60+
e + 1, # deletion
61+
d[j] + cost # substitution
62+
].min
63+
d[j] = e
64+
e = x
65+
end
66+
d[m] = x
67+
end
68+
69+
return x
70+
end
71+
72+
extend self
73+
end
74+
75+
if (__FILE__ == $0)
76+
require 'test/unit'
77+
78+
class LevenshteinTest < Test::Unit::TestCase
79+
include Levenshtein
80+
81+
EXPECTED = [
82+
# Easy ones
83+
['test', 'test', 0],
84+
['test', 'tent', 1],
85+
['gumbo', 'gambol', 2],
86+
['kitten', 'sitting', 3],
87+
# Empty strings
88+
['foo', '', 3],
89+
['', '', 0],
90+
['a', '', 1],
91+
# UTF-8
92+
["f\303\266o", 'foo', 1],
93+
["fran\303\247ais", 'francais', 1],
94+
["fran\303\247ais", "fran\303\246ais", 1],
95+
["\347\247\201\343\201\256\345\220\215\345\211\215\343\201\257"<<
96+
"\343\203\235\343\203\274\343\203\253\343\201\247\343\201\231",
97+
"\343\201\274\343\201\217\343\201\256\345\220\215\345\211\215\343\201"<<
98+
"\257\343\203\235\343\203\274\343\203\253\343\201\247\343\201\231",
99+
2], # Japanese
100+
# Edge cases
101+
['a', 'a', 0],
102+
['0123456789', 'abcdefghijklmnopqrstuvwxyz', 26]
103+
]
104+
105+
def test_known_distances
106+
EXPECTED.each do |a,b,x|
107+
assert_equal(x, distance(a, b))
108+
assert_equal(x, distance(b, a))
109+
end
110+
end
111+
end
112+
end

0 commit comments

Comments
 (0)