public
Description: A Ruby web application framework
Homepage: http://www.mackframework.com
Clone URL: git://github.com/markbates/mack.git
Click here to lend your support to: mack and make a donation at www.pledgie.com !
Added mail_to HTML helper. [#83 state:resolved]
markbates (author)
Fri Aug 08 11:16:02 -0700 2008
commit  5df6fe20c63f83b9ace55dcd6a92d58d8df31ec0
tree    e9f9ed03dc977788582485be34abc7a76094a137
parent  c9ff2bb597018796f83858b7fe6e0f166e285db9
...
 
1
2
3
...
1
2
3
4
0
@@ -1,3 +1,4 @@
0
+* [#83] Added mail_to HTML helper.
0
 * [#82] Added ACL support to mack-distributed
0
 * [#81] Fixed sessions working with redirects in testing
0
 * [#80] Distributed objects present both the DRb::DRbObject inspect and the original object's inspect when asked.
...
124
125
126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
128
129
...
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
0
@@ -124,6 +124,34 @@ module Mack
0
         # content_tag(:form, options, &block)
0
       end
0
       
0
+      # Builds a mailto href. By default it will generate 
0
+      # JavaScript to help prevent phishing. To turn this off
0
+      # pass in the option :format => :plain
0
+      # 
0
+      #   mail_to("Saul Frami", "frami.saul@klocko.ca") # => 
0
+      #   <script>document.write(String.fromCharCode(60,97,32,104,114,101,
0
+      #   102,61,34,109,97,105,108,116,111,58,102,114,97,109,105,46,115,97,117,
0
+      #   108,64,107,108,111,99,107,111,46,99,97,34,62,83,97,117,108,32,70,114,97,109,105,60,47,97,62));</script>
0
+      def mail_to(text, email_address = nil, options = {})
0
+        email_address = text if email_address.blank?
0
+        options = {:format => :js}.merge(options)
0
+        format = options[:format]
0
+        options - [:format]
0
+        link = link_to(text, "mailto:#{email_address}", options)
0
+        if format == :js
0
+          y = ''
0
+          link.size.times {y << 'a'}
0
+          js_link = "<script>"
0
+          c_code = []
0
+          link.each_byte {|c| c_code << c}
0
+          js_link << "document.write(String.fromCharCode(#{c_code.join(",")}));"
0
+          js_link << "</script>"
0
+          return js_link
0
+        else
0
+          return link
0
+        end
0
+      end
0
+      
0
       private
0
       def build_options(options)
0
         opts = ""
...
13
14
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
17
18
...
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
0
@@ -13,6 +13,22 @@ end
0
 describe Mack::ViewHelpers::HtmlHelpers do
0
   include HTMLSpecHelpers
0
   
0
+  describe "mail_to" do
0
+    
0
+    it "should use the 'text' parameter for the email parameter if one isn't given" do
0
+      mail_to("iii.blick.randy@langworthtowne.co.uk").should == %{<script>document.write(String.fromCharCode(60,97,32,104,114,101,102,61,34,109,97,105,108,116,111,58,105,105,105,46,98,108,105,99,107,46,114,97,110,100,121,64,108,97,110,103,119,111,114,116,104,116,111,119,110,101,46,99,111,46,117,107,34,62,105,105,105,46,98,108,105,99,107,46,114,97,110,100,121,64,108,97,110,103,119,111,114,116,104,116,111,119,110,101,46,99,111,46,117,107,60,47,97,62));</script>}.strip
0
+    end
0
+    
0
+    it "should build a javascript link by default" do
0
+      mail_to("Randy Blick III", "iii.blick.randy@langworthtowne.co.uk").should == %{<script>document.write(String.fromCharCode(60,97,32,104,114,101,102,61,34,109,97,105,108,116,111,58,105,105,105,46,98,108,105,99,107,46,114,97,110,100,121,64,108,97,110,103,119,111,114,116,104,116,111,119,110,101,46,99,111,46,117,107,34,62,82,97,110,100,121,32,66,108,105,99,107,32,73,73,73,60,47,97,62));</script>}.strip
0
+    end
0
+    
0
+    it "should generate a 'plain' version of the link if specified" do
0
+      mail_to("Randy Blick III", "iii.blick.randy@langworthtowne.co.uk", :format => :plain).should == link_to("Randy Blick III", "mailto:iii.blick.randy@langworthtowne.co.uk")
0
+    end
0
+    
0
+  end
0
+  
0
   describe "submit_tag" do
0
     
0
     it "should build a simple submit tag" do

Comments