Rails 3's ActiveSupport does not include Fixnum#ordinalize. Any system with this version of ActiveSupport installed will encounter a NoMethodError when running the 'generate' rake task.
Jerod Santo authored on 14/03/2010 at 20:47:21... | ... |
@@ -1,4 +1,4 @@ |
1 |
-gem 'activesupport', ">= 2.3.2" |
|
1 |
+gem 'activesupport', "2.3.2" |
|
2 | 2 |
require 'active_support' |
3 | 3 |
require 'rubypants' |
4 | 4 |
|
... | ... |
@@ -6,7 +6,7 @@ module Helpers |
6 | 6 |
module EscapeHelper |
7 | 7 |
HTML_ESCAPE = { '&' => '& ', '>' => '>', '<' => '<', '"' => '"' } |
8 | 8 |
JSON_ESCAPE = { '&' => '\u0026 ', '>' => '\u003E', '<' => '\u003C' } |
9 |
- |
|
9 |
+ |
|
10 | 10 |
# A utility method for escaping HTML tag characters. |
11 | 11 |
# This method is also aliased as <tt>h</tt>. |
12 | 12 |
# |
... | ... |
@@ -23,7 +23,7 @@ module Helpers |
23 | 23 |
html.to_s.gsub(/[\"><]|&(?!([a-zA-Z]+|(#\d+));)/) { |special| HTML_ESCAPE[special] } |
24 | 24 |
end |
25 | 25 |
alias h escape_once |
26 |
- |
|
26 |
+ |
|
27 | 27 |
# A utility method for escaping HTML entities in JSON strings. |
28 | 28 |
# This method is also aliased as <tt>j</tt>. |
29 | 29 |
# |
... | ... |
@@ -36,11 +36,11 @@ module Helpers |
36 | 36 |
def json_escape(s) |
37 | 37 |
s.to_s.gsub(/[&"><]/) { |special| JSON_ESCAPE[special] } |
38 | 38 |
end |
39 |
- |
|
39 |
+ |
|
40 | 40 |
alias j json_escape |
41 | 41 |
end |
42 | 42 |
include EscapeHelper |
43 |
- |
|
43 |
+ |
|
44 | 44 |
module ParamsHelper |
45 | 45 |
def params |
46 | 46 |
@params ||= begin |
... | ... |
@@ -51,31 +51,31 @@ module Helpers |
51 | 51 |
end |
52 | 52 |
end |
53 | 53 |
include ParamsHelper |
54 |
- |
|
54 |
+ |
|
55 | 55 |
module TagHelper |
56 | 56 |
def content_tag(name, content, html_options={}) |
57 | 57 |
%{<#{name}#{html_attributes(html_options)}>#{content}</#{name}>} |
58 | 58 |
end |
59 |
- |
|
59 |
+ |
|
60 | 60 |
def tag(name, html_options={}) |
61 | 61 |
%{<#{name}#{html_attributes(html_options)} />} |
62 | 62 |
end |
63 |
- |
|
63 |
+ |
|
64 | 64 |
def image_tag(src, html_options = {}) |
65 | 65 |
tag(:img, html_options.merge({:src=>src})) |
66 | 66 |
end |
67 |
- |
|
67 |
+ |
|
68 | 68 |
def javascript_tag(content = nil, html_options = {}) |
69 | 69 |
content_tag(:script, javascript_cdata_section(content), html_options.merge(:type => "text/javascript")) |
70 | 70 |
end |
71 |
- |
|
71 |
+ |
|
72 | 72 |
def link_to(name, href, html_options = {}) |
73 | 73 |
html_options = html_options.stringify_keys |
74 | 74 |
confirm = html_options.delete("confirm") |
75 | 75 |
onclick = "if (!confirm('#{html_escape(confirm)}')) return false;" if confirm |
76 | 76 |
content_tag(:a, name, html_options.merge(:href => href, :onclick=>onclick)) |
77 | 77 |
end |
78 |
- |
|
78 |
+ |
|
79 | 79 |
def link_to_function(name, *args, &block) |
80 | 80 |
html_options = {} |
81 | 81 |
html_options = args.pop if args.last.is_a? Hash |
... | ... |
@@ -84,17 +84,17 @@ module Helpers |
84 | 84 |
href = html_options[:href] || '#' |
85 | 85 |
content_tag(:a, name, html_options.merge(:href => href, :onclick => onclick)) |
86 | 86 |
end |
87 |
- |
|
87 |
+ |
|
88 | 88 |
private |
89 |
- |
|
89 |
+ |
|
90 | 90 |
def cdata_section(content) |
91 | 91 |
"<![CDATA[#{content}]]>" |
92 | 92 |
end |
93 |
- |
|
93 |
+ |
|
94 | 94 |
def javascript_cdata_section(content) #:nodoc: |
95 | 95 |
"\n//#{cdata_section("\n#{content}\n//")}\n" |
96 | 96 |
end |
97 |
- |
|
97 |
+ |
|
98 | 98 |
def html_attributes(options) |
99 | 99 |
unless options.blank? |
100 | 100 |
attrs = [] |
... | ... |
@@ -110,7 +110,7 @@ module Helpers |
110 | 110 |
end |
111 | 111 |
end |
112 | 112 |
include TagHelper |
113 |
- |
|
113 |
+ |
|
114 | 114 |
def to_html_email(address) |
115 | 115 |
email = string_to_html(address) |
116 | 116 |
"<a href=\"#{string_to_html('mailto:')}#{email}\">#{email}</a>" |
... | ... |
@@ -119,7 +119,7 @@ module Helpers |
119 | 119 |
def string_to_html(s) |
120 | 120 |
s.strip.unpack("C*").map{|ch| "&#" + ch.to_s + ";" }.to_s |
121 | 121 |
end |
122 |
- |
|
122 |
+ |
|
123 | 123 |
def show_part (file) |
124 | 124 |
data = '' |
125 | 125 |
f = File.open(Dir.pwd+"/source/"+file) |
... | ... |
@@ -128,16 +128,16 @@ module Helpers |
128 | 128 |
end |
129 | 129 |
data |
130 | 130 |
end |
131 |
- |
|
131 |
+ |
|
132 | 132 |
def shorten_words (string, word_limit = 25) |
133 | 133 |
words = string.split(/\s/) |
134 | 134 |
if words.size >= word_limit |
135 | 135 |
words[0,(word_limit-1)].join(" ") + '…' |
136 |
- else |
|
136 |
+ else |
|
137 | 137 |
string |
138 | 138 |
end |
139 | 139 |
end |
140 |
- |
|
140 |
+ |
|
141 | 141 |
def shorten (string, char_limit = 55) |
142 | 142 |
chars = string.scan(/.{1,1}/) |
143 | 143 |
if chars.size >= char_limit |
... | ... |
@@ -146,20 +146,20 @@ module Helpers |
146 | 146 |
"blah2" |
147 | 147 |
end |
148 | 148 |
end |
149 |
- |
|
149 |
+ |
|
150 | 150 |
def absolute_url(input, url) |
151 | 151 |
input.gsub(/(href|src)(\s*=\s*)(["'])(\/.*?)\3/) { $1 + $2 + $3 + url + $4 + $3 } |
152 | 152 |
end |
153 |
- |
|
153 |
+ |
|
154 | 154 |
def rp(input) |
155 | 155 |
RubyPants.new(input).to_html |
156 | 156 |
end |
157 | 157 |
def style_amp(input) |
158 | 158 |
input.gsub(" & "," <span class='amp'>&</span> ") |
159 | 159 |
end |
160 |
- |
|
160 |
+ |
|
161 | 161 |
module PartialsHelper |
162 |
- |
|
162 |
+ |
|
163 | 163 |
# A very hackish way to handle partials. We'll go with it till it breaks... |
164 | 164 |
def include(partial_name) |
165 | 165 |
file_ext = partial_name[(partial_name.index('.') + 1)..partial_name.length] |
... | ... |
@@ -176,15 +176,15 @@ module Helpers |
176 | 176 |
end |
177 | 177 |
end |
178 | 178 |
end |
179 |
- |
|
179 |
+ |
|
180 | 180 |
include PartialsHelper |
181 |
- |
|
181 |
+ |
|
182 | 182 |
end |
183 | 183 |
|
184 | 184 |
class String |
185 | 185 |
def titlecase |
186 | 186 |
small_words = %w(a an and as at but by en for if in of on or the to v v. via vs vs.) |
187 |
- |
|
187 |
+ |
|
188 | 188 |
x = split(" ").map do |word| |
189 | 189 |
# note: word could contain non-word characters! |
190 | 190 |
# downcase all small_words, capitalize the rest |
... | ... |
@@ -197,11 +197,11 @@ class String |
197 | 197 |
# small words after colons are capitalized |
198 | 198 |
x.join(" ").gsub(/:\s?(\W*#{small_words.join("|")}\W*)\s/) { ": #{$1.smart_capitalize} " } |
199 | 199 |
end |
200 |
- |
|
200 |
+ |
|
201 | 201 |
def titlecase! |
202 | 202 |
replace(titlecase) |
203 | 203 |
end |
204 |
- |
|
204 |
+ |
|
205 | 205 |
def smart_capitalize |
206 | 206 |
# ignore any leading crazy characters and capitalize the first real character |
207 | 207 |
if self =~ /^['"\(\[']*([a-z])/ |
... | ... |
@@ -212,7 +212,7 @@ class String |
212 | 212 |
end |
213 | 213 |
self |
214 | 214 |
end |
215 |
- |
|
215 |
+ |
|
216 | 216 |
def smart_capitalize! |
217 | 217 |
replace(smart_capitalize) |
218 | 218 |
end |