gem 'activesupport', "2.3.2"
require 'active_support'
require 'rubypants'
module Helpers
module EscapeHelper
HTML_ESCAPE = { '&' => '& ', '>' => '>', '<' => '<', '"' => '"' }
JSON_ESCAPE = { '&' => '\u0026 ', '>' => '\u003E', '<' => '\u003C' }
def html_escape(html)
html.to_s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] }
end
def escape_once(html)
html.to_s.gsub(/[\"><]|&(?!([a-zA-Z]+|(#\d+));)/) { |special| HTML_ESCAPE[special] }
end
alias h escape_once
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
q = request.query.dup
q.each { |(k,v)| q[k.to_s.intern] = v }
q
end
end
end
include ParamsHelper
module TagHelper
def content_tag(name, content, html_options={})
%{<#{name}
end
def tag(name, html_options={})
%{<#{name}
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
function = args[0] || ''
onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function}; return false;"
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)
"\n//#{cdata_section("\n#{content}\n//")}\n"
end
def html_attributes(options)
unless options.blank?
attrs = []
options.each_pair do |key, value|
if value == true
attrs << %(#{key}="#{key}") if value