cleaned up helpers

This commit is contained in:
B Mathis 2009-11-12 14:13:51 -06:00
parent 0ac4eca1d4
commit c51a1be7f9

View File

@ -85,49 +85,6 @@ module Helpers
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 mail_to(email_address, name = nil, html_options = {})
html_options = html_options.stringify_keys
encode = html_options.delete("encode").to_s
cc, bcc, subject, body = html_options.delete("cc"), html_options.delete("bcc"), html_options.delete("subject"), html_options.delete("body")
string = ''
extras = ''
extras << "cc=#{CGI.escape(cc).gsub("+", "%20")}&" unless cc.nil?
extras << "bcc=#{CGI.escape(bcc).gsub("+", "%20")}&" unless bcc.nil?
extras << "body=#{CGI.escape(body).gsub("+", "%20")}&" unless body.nil?
extras << "subject=#{CGI.escape(subject).gsub("+", "%20")}&" unless subject.nil?
extras = "?" << extras.gsub!(/&?$/,"") unless extras.empty?
email_address = email_address.to_s
email_address_obfuscated = email_address.dup
email_address_obfuscated.gsub!(/@/, html_options.delete("replace_at")) if html_options.has_key?("replace_at")
email_address_obfuscated.gsub!(/\./, html_options.delete("replace_dot")) if html_options.has_key?("replace_dot")
if encode == "javascript"
"document.write('#{content_tag("a", name || email_address_obfuscated, html_options.merge({ "href" => "mailto:"+email_address+extras }))}');".each_byte do |c|
string << sprintf("%%%x", c)
end
"<script type=\"#{Mime::JS}\">eval(decodeURIComponent('#{string}'))</script>"
elsif encode == "hex"
email_address_encoded = ''
email_address_obfuscated.each_byte do |c|
email_address_encoded << sprintf("&#%d;", c)
end
protocol = 'mailto:'
protocol.each_byte { |c| string << sprintf("&#%d;", c) }
email_address.each_byte do |c|
char = c.chr
string << (char =~ /\w/ ? sprintf("%%%x", c) : char)
end
content_tag "a", name || email_address_encoded, html_options.merge({ "href" => "#{string}#{extras}" })
else
content_tag "a", name || email_address_obfuscated, html_options.merge({ "href" => "mailto:#{email_address}#{extras}" })
end
end
private private
def cdata_section(content) def cdata_section(content)
@ -156,15 +113,6 @@ module Helpers
# My added helpers # My added helpers
def to_html_email(address)
email = string_to_html(address)
"<a href=\"#{string_to_html('mailto:')}#{email}\">#{email}</a>"
end
def string_to_html(s)
s.strip.unpack("C*").map{|ch| "&#" + ch.to_s + ";" }.to_s
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)