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 !
Refactored out Mack::ViewHelpers::HtmlHelpers into 
Mack::ViewHelpers::HtmlHelpers, Mack::ViewHelpers::FormHelpers and 
Mack::ViewHelpers::linkHelpers [#85 state:resolved]
markbates (author)
Fri Aug 08 12:16:13 -0700 2008
commit  727e04e0c5dae38476648eeac6641c72cd7ebd5a
tree    d954e8094a576508e1afd8ab67a66a7d73ecb9fe
parent  e773d47ce14b37d1bb8dded88c3944328fb2f8e0
...
 
 
1
2
3
...
1
2
3
4
5
0
@@ -1,3 +1,5 @@
0
+* [#85] Refactored out Mack::ViewHelpers::HtmlHelpers into Mack::ViewHelpers::HtmlHelpers, Mack::ViewHelpers::FormHelpers and
0
+        Mack::ViewHelpers::linkHelpers
0
 * [#84] Added Mack::Distributed.lookup(url) to retrieve specific distributed services.
0
 * [#83] Added mail_to HTML helper.
0
 * [#82] Added ACL support to mack-distributed
...
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
...
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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
...
2
3
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
6
7
...
31
32
33
 
 
 
 
 
 
 
 
 
 
 
 
 
34
35
36
37
38
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
41
42
0
@@ -2,59 +2,6 @@ module Mack
0
   module ViewHelpers # :nodoc:
0
     module HtmlHelpers
0
       
0
-      # This is just an alias to 
0
-      # 
0
-      # Examples:
0
-      #   <%= link_to("http://www.mackframework.com") %> # => <a href="http://www.mackframework.com">http://www.mackframework.com</a>
0
-      #   <%= link_to("Mack", "http://www.mackframework.com") %> # => <a href="http://www.mackframework.com">Mack</a>
0
-      #   <%= link_to("Mack", "http://www.mackframework.com", :target => "_blank") %> # => <a href="http://www.mackframework.com" target="_blank">Mack</a>
0
-      #   <%= link_to("Mack", "http://www.mackframework.com", :target => "_blank", :rel => :nofollow) %> # => <a href="http://www.mackframework.com" target="_blank" rel="nofollow">Mack</a>
0
-      # If you pass in :method as an option it will be a JavaScript form that will post to the specified link with the 
0
-      # methd specified.
0
-      #   <%= link_to("Mack", "http://www.mackframework.com", :method => :delete) %>
0
-      # If you use the :method option you can also pass in a :confirm option. The :confirm option will generate a 
0
-      # javascript confirmation window. If 'OK' is selected the the form will submit. If 'cancel' is selected, then
0
-      # nothing will happen. This is extremely useful for 'delete' type of links.
0
-      #   <%= link_to("Mack", "http://www.mackframework.com", :method => :delete, :confirm => "Are you sure?") %>
0
-      def link_to(link_text, url = link_text, html_options = {})
0
-        options = {:href => url}.merge(html_options)
0
-        a(link_text, options)
0
-      end
0
-      
0
-      # Used in views to create href links. It takes link_text, url, and a Hash that gets added
0
-      # to the href as options.
0
-      # 
0
-      # Examples:
0
-      #    a("http://www.mackframework.com") # => <a href="http://www.mackframework.com">http://www.mackframework.com</a>
0
-      #    a("Mack", :href => "http://www.mackframework.com") # => <a href="http://www.mackframework.com">Mack</a>
0
-      #    a("Mack", :href => "http://www.mackframework.com", :target => "_blank") # => <a href="http://www.mackframework.com" target="_blank">Mack</a>
0
-      #    a("Mack", :href => "http://www.mackframework.com", :target => "_blank", :rel => :nofollow) # => <a href="http://www.mackframework.com" target="_blank" rel="nofollow">Mack</a>
0
-      # If you pass in :method as an option it will be a JavaScript form that will post to the specified link with the 
0
-      # methd specified.
0
-      #    a("Mack", :href => "http://www.mackframework.com", :method => :delete)
0
-      # If you use the :method option you can also pass in a :confirm option. The :confirm option will generate a 
0
-      # javascript confirmation window. If 'OK' is selected the the form will submit. If 'cancel' is selected, then
0
-      # nothing will happen. This is extremely useful for 'delete' type of links.
0
-      #    a("Mack", :href => "http://www.mackframework.com", :method => :delete, :confirm => "Are you sure?")
0
-      def a(link_text, options = {})
0
-        options = {:href => link_text}.merge(options)
0
-        if options[:method]
0
-          meth = nil
0
-          confirm = nil
0
-        
0
-          meth = %{var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var s = document.createElement('input'); s.setAttribute('type', 'hidden'); s.setAttribute('name', '_method'); s.setAttribute('value', '#{options[:method]}'); f.appendChild(s);f.submit()}
0
-          options.delete(:method)
0
-        
0
-          if options[:confirm]
0
-            confirm = %{if (confirm('#{options[:confirm]}'))}
0
-            options.delete(:confirm)
0
-          end
0
-        
0
-          options[:onclick] = (confirm ? (confirm + " { ") : "") << meth << (confirm ? (" } ") : "") << ";return false;"
0
-        end
0
-        content_tag(:a, options, link_text)
0
-      end
0
-      
0
       # Builds an HTML tag.
0
       # 
0
       # Examples:
0
@@ -84,74 +31,12 @@ module Mack
0
         non_content_tag(:img, {:src => image_src}.merge(options))
0
       end
0
       
0
-      # Builds an HTML submit tag
0
-      def submit_tag(value = "Submit", options = {})
0
-        non_content_tag(:input, {:type => :submit, :value => value}.merge(options))
0
-      end
0
-      
0
-      # Wraps an image tag with a link tag.
0
-      # 
0
-      # Examples:
0
-      #   <%= link_image_to("/images/foo.jpg", "#" %> # => <a href="#"><img src="/images/foo.jpg"></a>
0
-      def link_image_to(image_url, url, image_options = {}, html_options = {})
0
-        link_to(img(image_url, image_options), url, html_options)
0
-      end
0
-      
0
       # Example:
0
       #   <%= rss_tag(posts_index_url(:format => :xml)) %>
0
       def rss_tag(url)
0
         "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" href=\"#{url}\">"
0
       end
0
       
0
-      def form(action, options = {}, &block)
0
-        options = {:method => :post, :action => action}.merge(options)
0
-        if options[:id]
0
-          options = {:class => options[:id]}.merge(options)
0
-        end
0
-        if options[:multipart]
0
-          options = {:enctype => "multipart/form-data"}.merge(options)
0
-          options.delete(:multipart)
0
-        end
0
-        meth = nil
0
-        unless options[:method] == :get || options[:method] == :post
0
-          meth = "<input name=\"_method\" type=\"hidden\" value=\"#{options[:method]}\" />\n"
0
-          options[:method] = :post
0
-        end
0
-        concat("<form#{build_options(options)}>\n", block.binding)
0
-        concat(meth, block.binding) unless meth.blank?
0
-        yield
0
-        concat("</form>", block.binding)
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 = ""
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
15
16
17
...
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
...
1
2
3
 
 
 
 
 
 
 
 
 
4
 
5
6
7
8
...
20
21
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
24
25
0
@@ -1,17 +1,8 @@
0
 require 'pathname'
0
 require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
0
 
0
-module HTMLSpecHelpers
0
-  include Mack::ViewHelpers::HtmlHelpers
0
-  
0
-  def my_url
0
-    return "http://www.mackframework.com"
0
-  end
0
-  
0
-end
0
-
0
 describe Mack::ViewHelpers::HtmlHelpers do
0
-  include HTMLSpecHelpers
0
+  include Mack::ViewHelpers
0
   
0
   describe "mail_to" do
0
     
0
@@ -29,62 +20,6 @@ describe Mack::ViewHelpers::HtmlHelpers do
0
     
0
   end
0
   
0
-  describe "submit_tag" do
0
-    
0
-    it "should build a simple submit tag" do
0
-      submit_tag.should == %{<input type="submit" value="Submit" />}
0
-    end
0
-    
0
-    it "should allow you to change the value" do
0
-      submit_tag("Login").should == %{<input type="submit" value="Login" />}
0
-    end
0
-    
0
-    it "should take options" do
0
-      submit_tag("Login", {:class => :foo}).should == %{<input class="foo" type="submit" value="Login" />}
0
-    end
0
-    
0
-  end
0
-  
0
-  describe "a" do
0
-    
0
-    it "should return content when a(...) is called" do
0
-      link_to(my_url).should_not be_nil
0
-      link_to(my_url).should_not be_empty
0
-    end
0
-    
0
-    it "should return proper html when called without options" do
0
-      a(my_url).should == %{<a href="#{my_url}">#{my_url}</a>}
0
-    end
0
-    
0
-    it "should return proper html when called with options" do
0
-      a("Mack", :href => my_url).should == %{<a href="#{my_url}">Mack</a>}
0
-      a("Mack", :href => my_url, :target => "_blank").should == %{<a href="#{my_url}" target=\"_blank">Mack</a>}
0
-      
0
-      result = %{<a href="#{my_url}" onclick="var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var s = document.createElement('input'); s.setAttribute('type', 'hidden'); s.setAttribute('name', '_method'); s.setAttribute('value', 'delete'); f.appendChild(s);f.submit();return false;">Mack</a>}
0
-      a("Mack", :href => my_url, :method => :delete).should == result
0
-             
0
-      result = %{<a href="#{my_url}" onclick="if (confirm('Are you sure?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var s = document.createElement('input'); s.setAttribute('type', 'hidden'); s.setAttribute('name', '_method'); s.setAttribute('value', 'update'); f.appendChild(s);f.submit() } ;return false;">Mack</a>}
0
-      link = a("Mack", :href => my_url, :method => :update, :confirm => "Are you sure?")
0
-      link.should == result
0
-    end
0
-  end
0
-  
0
-  describe "link_to" do
0
-    it "should return content when link_to(...) is called" do
0
-      a(my_url).should_not be_nil
0
-      a(my_url).should_not be_empty
0
-    end
0
-    
0
-    it "should return proper html when link_to(...) is called" do
0
-      link_to(my_url).should == a(my_url)
0
-      link_to("Mack", my_url).should == a("Mack", :href => my_url)
0
-      link_to("Mack", my_url, :target => "_blank").should == a("Mack", :href => my_url, :target => "_blank")
0
-      link_to("Mack", my_url, :method => :delete).should == a("Mack", :href => my_url, :method => :delete)
0
-      link_to("Mack", my_url, :method => :update, :confirm => "Are you sure?").should ==  
0
-            a("Mack", :href => my_url, :method => :update, :confirm => "Are you sure?")
0
-    end
0
-  end
0
-  
0
   describe "rss_tag" do
0
     it "should return content when rss() is called" do
0
       rss_tag("foo_bar").should_not be_nil

Comments