Explicitly require ActiveSupport 2.3.2.

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.
This commit is contained in:
Jerod Santo 2010-03-15 04:47:21 +08:00 committed by Brandon Mathis
parent ac9addf8f3
commit 80b276c21e

View File

@ -1,4 +1,4 @@
gem 'activesupport', ">= 2.3.2" gem 'activesupport', "2.3.2"
require 'active_support' require 'active_support'
require 'rubypants' require 'rubypants'
@ -6,7 +6,7 @@ module Helpers
module EscapeHelper module EscapeHelper
HTML_ESCAPE = { '&' => '&amp; ', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;' } HTML_ESCAPE = { '&' => '&amp; ', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;' }
JSON_ESCAPE = { '&' => '\u0026 ', '>' => '\u003E', '<' => '\u003C' } JSON_ESCAPE = { '&' => '\u0026 ', '>' => '\u003E', '<' => '\u003C' }
# A utility method for escaping HTML tag characters. # A utility method for escaping HTML tag characters.
# This method is also aliased as <tt>h</tt>. # This method is also aliased as <tt>h</tt>.
# #
@ -23,7 +23,7 @@ module Helpers
html.to_s.gsub(/[\"><]|&(?!([a-zA-Z]+|(#\d+));)/) { |special| HTML_ESCAPE[special] } html.to_s.gsub(/[\"><]|&(?!([a-zA-Z]+|(#\d+));)/) { |special| HTML_ESCAPE[special] }
end end
alias h escape_once alias h escape_once
# A utility method for escaping HTML entities in JSON strings. # A utility method for escaping HTML entities in JSON strings.
# This method is also aliased as <tt>j</tt>. # This method is also aliased as <tt>j</tt>.
# #
@ -36,11 +36,11 @@ module Helpers
def json_escape(s) def json_escape(s)
s.to_s.gsub(/[&"><]/) { |special| JSON_ESCAPE[special] } s.to_s.gsub(/[&"><]/) { |special| JSON_ESCAPE[special] }
end end
alias j json_escape alias j json_escape
end end
include EscapeHelper include EscapeHelper
module ParamsHelper module ParamsHelper
def params def params
@params ||= begin @params ||= begin
@ -51,31 +51,31 @@ module Helpers
end end
end end
include ParamsHelper include ParamsHelper
module TagHelper module TagHelper
def content_tag(name, content, html_options={}) def content_tag(name, content, html_options={})
%{<#{name}#{html_attributes(html_options)}>#{content}</#{name}>} %{<#{name}#{html_attributes(html_options)}>#{content}</#{name}>}
end end
def tag(name, html_options={}) def tag(name, html_options={})
%{<#{name}#{html_attributes(html_options)} />} %{<#{name}#{html_attributes(html_options)} />}
end end
def image_tag(src, html_options = {}) def image_tag(src, html_options = {})
tag(:img, html_options.merge({:src=>src})) tag(:img, html_options.merge({:src=>src}))
end end
def javascript_tag(content = nil, html_options = {}) def javascript_tag(content = nil, html_options = {})
content_tag(:script, javascript_cdata_section(content), html_options.merge(:type => "text/javascript")) content_tag(:script, javascript_cdata_section(content), html_options.merge(:type => "text/javascript"))
end end
def link_to(name, href, html_options = {}) def link_to(name, href, html_options = {})
html_options = html_options.stringify_keys html_options = html_options.stringify_keys
confirm = html_options.delete("confirm") confirm = html_options.delete("confirm")
onclick = "if (!confirm('#{html_escape(confirm)}')) return false;" if confirm onclick = "if (!confirm('#{html_escape(confirm)}')) return false;" if confirm
content_tag(:a, name, html_options.merge(:href => href, :onclick=>onclick)) content_tag(:a, name, html_options.merge(:href => href, :onclick=>onclick))
end end
def link_to_function(name, *args, &block) def link_to_function(name, *args, &block)
html_options = {} html_options = {}
html_options = args.pop if args.last.is_a? Hash html_options = args.pop if args.last.is_a? Hash
@ -84,17 +84,17 @@ module Helpers
href = html_options[:href] || '#' href = html_options[:href] || '#'
content_tag(:a, name, html_options.merge(:href => href, :onclick => onclick)) content_tag(:a, name, html_options.merge(:href => href, :onclick => onclick))
end end
private private
def cdata_section(content) def cdata_section(content)
"<![CDATA[#{content}]]>" "<![CDATA[#{content}]]>"
end end
def javascript_cdata_section(content) #:nodoc: def javascript_cdata_section(content) #:nodoc:
"\n//#{cdata_section("\n#{content}\n//")}\n" "\n//#{cdata_section("\n#{content}\n//")}\n"
end end
def html_attributes(options) def html_attributes(options)
unless options.blank? unless options.blank?
attrs = [] attrs = []
@ -110,7 +110,7 @@ module Helpers
end end
end end
include TagHelper include TagHelper
def to_html_email(address) def to_html_email(address)
email = string_to_html(address) email = string_to_html(address)
"<a href=\"#{string_to_html('mailto:')}#{email}\">#{email}</a>" "<a href=\"#{string_to_html('mailto:')}#{email}\">#{email}</a>"
@ -119,7 +119,7 @@ module Helpers
def string_to_html(s) def string_to_html(s)
s.strip.unpack("C*").map{|ch| "&#" + ch.to_s + ";" }.to_s s.strip.unpack("C*").map{|ch| "&#" + ch.to_s + ";" }.to_s
end end
def show_part (file) def show_part (file)
data = '' data = ''
f = File.open(Dir.pwd+"/source/"+file) f = File.open(Dir.pwd+"/source/"+file)
@ -128,16 +128,16 @@ module Helpers
end end
data data
end end
def shorten_words (string, word_limit = 25) def shorten_words (string, word_limit = 25)
words = string.split(/\s/) words = string.split(/\s/)
if words.size >= word_limit if words.size >= word_limit
words[0,(word_limit-1)].join(" ") + '&hellip;' words[0,(word_limit-1)].join(" ") + '&hellip;'
else else
string string
end end
end end
def shorten (string, char_limit = 55) def shorten (string, char_limit = 55)
chars = string.scan(/.{1,1}/) chars = string.scan(/.{1,1}/)
if chars.size >= char_limit if chars.size >= char_limit
@ -146,20 +146,20 @@ module Helpers
"blah2" "blah2"
end end
end end
def absolute_url(input, url) def absolute_url(input, url)
input.gsub(/(href|src)(\s*=\s*)(["'])(\/.*?)\3/) { $1 + $2 + $3 + url + $4 + $3 } input.gsub(/(href|src)(\s*=\s*)(["'])(\/.*?)\3/) { $1 + $2 + $3 + url + $4 + $3 }
end end
def rp(input) def rp(input)
RubyPants.new(input).to_html RubyPants.new(input).to_html
end end
def style_amp(input) def style_amp(input)
input.gsub(" & "," <span class='amp'>&</span> ") input.gsub(" & "," <span class='amp'>&</span> ")
end end
module PartialsHelper module PartialsHelper
# A very hackish way to handle partials. We'll go with it till it breaks... # A very hackish way to handle partials. We'll go with it till it breaks...
def include(partial_name) def include(partial_name)
file_ext = partial_name[(partial_name.index('.') + 1)..partial_name.length] file_ext = partial_name[(partial_name.index('.') + 1)..partial_name.length]
@ -176,15 +176,15 @@ module Helpers
end end
end end
end end
include PartialsHelper include PartialsHelper
end end
class String class String
def titlecase def titlecase
small_words = %w(a an and as at but by en for if in of on or the to v v. via vs vs.) small_words = %w(a an and as at but by en for if in of on or the to v v. via vs vs.)
x = split(" ").map do |word| x = split(" ").map do |word|
# note: word could contain non-word characters! # note: word could contain non-word characters!
# downcase all small_words, capitalize the rest # downcase all small_words, capitalize the rest
@ -197,11 +197,11 @@ class String
# small words after colons are capitalized # small words after colons are capitalized
x.join(" ").gsub(/:\s?(\W*#{small_words.join("|")}\W*)\s/) { ": #{$1.smart_capitalize} " } x.join(" ").gsub(/:\s?(\W*#{small_words.join("|")}\W*)\s/) { ": #{$1.smart_capitalize} " }
end end
def titlecase! def titlecase!
replace(titlecase) replace(titlecase)
end end
def smart_capitalize def smart_capitalize
# ignore any leading crazy characters and capitalize the first real character # ignore any leading crazy characters and capitalize the first real character
if self =~ /^['"\(\[']*([a-z])/ if self =~ /^['"\(\[']*([a-z])/
@ -212,7 +212,7 @@ class String
end end
self self
end end
def smart_capitalize! def smart_capitalize!
replace(smart_capitalize) replace(smart_capitalize)
end end