diff options
author | Jerod Santo <jerod.santo@gmail.com> | 2010-03-15 04:47:21 +0800 |
---|---|---|
committer | Brandon Mathis <brandon@imathis.com> | 2010-05-24 08:32:37 +0800 |
commit | 80b276c21e27a269a3caece56f15af59b0e27b8f (patch) | |
tree | 5f06de2a4f8b65d56e212ff84db8e7fb9eabc16e /source/_helpers.rb | |
parent | ac9addf8f35d933b490d1dbfc0821a816d8c5984 (diff) | |
download | my_new_personal_website-80b276c21e27a269a3caece56f15af59b0e27b8f.tar.xz my_new_personal_website-80b276c21e27a269a3caece56f15af59b0e27b8f.zip |
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.
Diffstat (limited to 'source/_helpers.rb')
-rw-r--r-- | source/_helpers.rb | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/source/_helpers.rb b/source/_helpers.rb index 11d78523..0c200c48 100644 --- a/source/_helpers.rb +++ b/source/_helpers.rb @@ -1,4 +1,4 @@ -gem 'activesupport', ">= 2.3.2" +gem 'activesupport', "2.3.2" require 'active_support' require 'rubypants' @@ -6,7 +6,7 @@ module Helpers module EscapeHelper HTML_ESCAPE = { '&' => '& ', '>' => '>', '<' => '<', '"' => '"' } JSON_ESCAPE = { '&' => '\u0026 ', '>' => '\u003E', '<' => '\u003C' } - + # A utility method for escaping HTML tag characters. # 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] } end alias h escape_once - + # A utility method for escaping HTML entities in JSON strings. # This method is also aliased as <tt>j</tt>. # @@ -36,11 +36,11 @@ module Helpers def json_escape(s) s.to_s.gsub(/[&"><]/) { |special| JSON_ESCAPE[special] } end - + alias j json_escape end include EscapeHelper - + module ParamsHelper def params @params ||= begin @@ -51,31 +51,31 @@ module Helpers end end include ParamsHelper - + module TagHelper def content_tag(name, content, html_options={}) %{<#{name}#{html_attributes(html_options)}>#{content}</#{name}>} end - + def tag(name, html_options={}) %{<#{name}#{html_attributes(html_options)} />} end - + def image_tag(src, html_options = {}) tag(:img, html_options.merge({:src=>src})) end - + def javascript_tag(content = nil, html_options = {}) content_tag(:script, javascript_cdata_section(content), html_options.merge(:type => "text/javascript")) end - + def link_to(name, href, html_options = {}) html_options = html_options.stringify_keys confirm = html_options.delete("confirm") onclick = "if (!confirm('#{html_escape(confirm)}')) return false;" if confirm content_tag(:a, name, html_options.merge(:href => href, :onclick=>onclick)) end - + def link_to_function(name, *args, &block) html_options = {} html_options = args.pop if args.last.is_a? Hash @@ -84,17 +84,17 @@ module Helpers href = html_options[:href] || '#' content_tag(:a, name, html_options.merge(:href => href, :onclick => onclick)) end - + private - + def cdata_section(content) "<![CDATA[#{content}]]>" end - + def javascript_cdata_section(content) #:nodoc: "\n//#{cdata_section("\n#{content}\n//")}\n" end - + def html_attributes(options) unless options.blank? attrs = [] @@ -110,7 +110,7 @@ module Helpers end end include TagHelper - + def to_html_email(address) email = string_to_html(address) "<a href=\"#{string_to_html('mailto:')}#{email}\">#{email}</a>" @@ -119,7 +119,7 @@ module Helpers def string_to_html(s) s.strip.unpack("C*").map{|ch| "&#" + ch.to_s + ";" }.to_s end - + def show_part (file) data = '' f = File.open(Dir.pwd+"/source/"+file) @@ -128,16 +128,16 @@ module Helpers end data end - + def shorten_words (string, word_limit = 25) words = string.split(/\s/) if words.size >= word_limit words[0,(word_limit-1)].join(" ") + '…' - else + else string end end - + def shorten (string, char_limit = 55) chars = string.scan(/.{1,1}/) if chars.size >= char_limit @@ -146,20 +146,20 @@ module Helpers "blah2" end end - + def absolute_url(input, url) input.gsub(/(href|src)(\s*=\s*)(["'])(\/.*?)\3/) { $1 + $2 + $3 + url + $4 + $3 } end - + def rp(input) RubyPants.new(input).to_html end def style_amp(input) input.gsub(" & "," <span class='amp'>&</span> ") end - + module PartialsHelper - + # A very hackish way to handle partials. We'll go with it till it breaks... def include(partial_name) file_ext = partial_name[(partial_name.index('.') + 1)..partial_name.length] @@ -176,15 +176,15 @@ module Helpers end end end - + include PartialsHelper - + end class String 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.) - + x = split(" ").map do |word| # note: word could contain non-word characters! # downcase all small_words, capitalize the rest @@ -197,11 +197,11 @@ class String # small words after colons are capitalized x.join(" ").gsub(/:\s?(\W*#{small_words.join("|")}\W*)\s/) { ": #{$1.smart_capitalize} " } end - + def titlecase! replace(titlecase) end - + def smart_capitalize # ignore any leading crazy characters and capitalize the first real character if self =~ /^['"\(\[']*([a-z])/ @@ -212,7 +212,7 @@ class String end self end - + def smart_capitalize! replace(smart_capitalize) end |