We got nominated! Help us out and vote for GitHub as Best Bootstrapped Startup of 2008. (You can vote once a day.) [ hide ]

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 some more rdoc and fixed a bug or two with html form helpers. [#19]
markbates (author)
Thu Aug 14 13:38:29 -0700 2008
commit  7201f443900acb6f7e010d1aa6df4766416a5fd5
tree    c1315ee82dafe9cedaf5245a4e5afc49b5059ee7
parent  d83e931e8bd246ca664547f181fdc30c516d56c4
...
55
56
57
58
59
 
 
 
60
61
62
63
64
65
66
67
68
69
70
71
 
 
 
 
 
 
 
 
 
72
73
74
 
 
 
 
 
 
75
76
77
...
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
0
@@ -55,23 +55,31 @@ class Symbol
0
   #
0
   # Examples:
0
   # @user = User.new(:level => 1)
0
- # <%= :user.radio_button :level %> # => <input checked="checked" id="user_level" name="user[level]" type="radio" />
0
- # <%= :i_dont_exist.radio_button %> # => <input id="i_dont_exist" name="i_dont_exist" type="radio" />
0
+ # <%= :user.radio_button :level %> # => <input checked="checked" id="user_level" name="user[level]" type="radio" value="1" />
0
+ # <%= :user.radio_button :level, :value => 2 %> # => <input id="user_level" name="user[level]" type="radio" value="2" />
0
+ # <%= :i_dont_exist.radio_button %> # => <input id="i_dont_exist" name="i_dont_exist" type="radio" value="" />
0
   def radio_button(*args)
0
     Thread.current[:view_template].radio_button(self, *args)
0
   end
0
   
0
- # See Mack::ViewHelpers::FormHelpers select for more information
0
- def select(*args)
0
- Thread.current[:view_template].select(self, *args)
0
- end
0
-
0
- # See Mack::ViewHelpers::FormHelpers submit for more information
0
- def submit(*args)
0
- Thread.current[:view_template].submit(self, *args)
0
+ # See Mack::ViewHelpers::FormHelpers select_tag for more information
0
+ #
0
+ # Examples:
0
+ # @user = User.new(:level => 1)
0
+ # <%= :user.select_tag :level, :options => [["one", 1], ["two", 2]] %> # => <select id="user_level" name="user[level]"><option value="1" selected>one</option><option value="2" >two</option></select>
0
+ # <%= :user.select_tag :level, :options => {:one => 1, :two => 2} %> # => <select id="user_level" name="user[level]"><option value="1" selected>one</option><option value="2" >two</option></select>
0
+ # <%= :i_dont_exist.select_tag :options => [["one", 1], ["two", 2]], :selected => 1 %> # => <select id="i_dont_exist" name="i_dont_exist"><option value="1" selected>one</option><option value="2" >two</option></select>
0
+ def select_tag(*args)
0
+ Thread.current[:view_template].select_tag(self, *args)
0
   end
0
   
0
   # See Mack::ViewHelpers::FormHelpers text_area for more information
0
+ #
0
+ # Examples:
0
+ # @user = User.new(:bio => "my bio here")
0
+ # <%= :user.text_area :bio %> # => <textarea id="user_bio" name="user[bio]">my bio here</textarea>
0
+ # <%= :i_dont_exist.text_area %> # => <textarea id="i_dont_exist" name="i_dont_exist"></textarea>
0
+ # <%= :i_dont_exist.text_area :value => "hi there" %> # => <textarea id="i_dont_exist" name="i_dont_exist">hi there</textarea>
0
   def text_area(*args)
0
     Thread.current[:view_template].text_area(self, *args)
0
   end
...
24
25
26
27
28
 
 
29
30
31
32
 
 
 
 
33
34
35
...
67
68
69
70
 
71
72
73
...
107
108
109
110
 
 
 
111
112
113
...
24
25
26
 
 
27
28
29
30
 
 
31
32
33
34
35
36
37
...
69
70
71
 
72
73
74
75
...
109
110
111
 
112
113
114
115
116
117
0
@@ -24,12 +24,14 @@ module Mack
0
       end
0
       
0
       def submit_tag(value = "Submit", options = {}, *original_args)
0
- Mack.logger.warn("DEPRECATED: 'submit_tag'. Please use 'submit' instead")
0
- submit(value, options, *original_args)
0
+ Mack.logger.warn("DEPRECATED: 'submit_tag'. Please use 'submit_button' instead")
0
+ submit_button(value, options, *original_args)
0
       end
0
       
0
- # Builds an HTML submit tag
0
- def submit(value = "Submit", options = {}, *original_args)
0
+ # Examples:
0
+ # <%= submit_button %> # => <input type="submit" value="Submit" />
0
+ # <%= submit_button "Login" %> # => <input type="submit" value="Login" />
0
+ def submit_button(value = "Submit", options = {}, *original_args)
0
         non_content_tag(:input, {:type => :submit, :value => value}.merge(options))
0
       end
0
       
0
@@ -67,7 +69,7 @@ module Mack
0
         content_tag(:label, fe.options, content)
0
       end
0
 
0
- def select(name, *args)
0
+ def select_tag(name, *args)
0
         var = instance_variable_get("@#{name}")
0
         fe = FormElement.new(*args)
0
         options = {:name => name, :id => name}
0
@@ -107,7 +109,9 @@ module Mack
0
         fe = FormElement.new(*args)
0
         options = {:name => name, :id => name}
0
         if var.nil?
0
- return content_tag(:textarea, options.merge(fe.options))
0
+ value = fe.options[:value]
0
+ fe.options.delete(:value)
0
+ return content_tag(:textarea, options.merge(fe.options), value)
0
         else
0
           unless fe.calling_method == :to_s
0
             options.merge!(:name => "#{name}[#{fe.calling_method}]", :id => "#{name}_#{fe.calling_method}")
...
168
169
170
171
 
172
173
174
 
175
176
177
178
 
179
180
181
182
 
183
184
185
186
 
187
188
189
190
 
191
192
193
194
 
195
196
197
...
208
209
210
 
211
212
213
...
278
279
280
281
 
282
283
284
 
285
286
287
288
 
289
290
291
292
 
293
294
295
...
168
169
170
 
171
172
173
 
174
175
176
177
 
178
179
180
181
 
182
183
184
185
 
186
187
188
189
 
190
191
192
193
 
194
195
196
197
...
208
209
210
211
212
213
214
...
279
280
281
 
282
283
284
 
285
286
287
288
 
289
290
291
292
 
293
294
295
296
0
@@ -168,30 +168,30 @@ describe Mack::ViewHelpers::FormHelpers do
0
     
0
   end
0
   
0
- describe "select" do
0
+ describe "select_tag" do
0
     
0
     it "should create a nested select tag for a model" do
0
- select(:cop, :level).should == %{<select id="cop_level" name="cop[level]"></select>}
0
+ select_tag(:cop, :level).should == %{<select id="cop_level" name="cop[level]"></select>}
0
     end
0
     
0
     it "should create a non-nested select tag for a simple model" do
0
- select(:simple).should == %{<select id="simple" name="simple"></select>}
0
+ select_tag(:simple).should == %{<select id="simple" name="simple"></select>}
0
     end
0
     
0
     it "should build the options from a given array of arrays" do
0
- select(:simple, :options => @select_options).should == %{<select id="simple" name="simple"><option value="1" >one</option><option value="2" >two</option><option value="3" >three</option></select>}
0
+ select_tag(:simple, :options => @select_options).should == %{<select id="simple" name="simple"><option value="1" >one</option><option value="2" >two</option><option value="3" >three</option></select>}
0
     end
0
     
0
     it "should build the options from a given hash" do
0
- select(:simple, :options => {"one" => 1, "two" => 2, "three" => 3}).should == %{<select id="simple" name="simple"><option value="1" >one</option><option value="3" >three</option><option value="2" >two</option></select>}
0
+ select_tag(:simple, :options => {"one" => 1, "two" => 2, "three" => 3}).should == %{<select id="simple" name="simple"><option value="1" >one</option><option value="3" >three</option><option value="2" >two</option></select>}
0
     end
0
     
0
     it "should mark an option as selected if the model has it seleceted" do
0
- select(:cop, :level, :options => @select_options).should == %{<select id="cop_level" name="cop[level]"><option value="1" selected>one</option><option value="2" >two</option><option value="3" >three</option></select>}
0
+ select_tag(:cop, :level, :options => @select_options).should == %{<select id="cop_level" name="cop[level]"><option value="1" selected>one</option><option value="2" >two</option><option value="3" >three</option></select>}
0
     end
0
     
0
     it "should mark an option as selected if the selected options is available" do
0
- select(:simple, :options => @select_options, :selected => 1).should == %{<select id="simple" name="simple"><option value="1" selected>one</option><option value="2" >two</option><option value="3" >three</option></select>}
0
+ select_tag(:simple, :options => @select_options, :selected => 1).should == %{<select id="simple" name="simple"><option value="1" selected>one</option><option value="2" >two</option><option value="3" >three</option></select>}
0
     end
0
     
0
   end
0
@@ -208,6 +208,7 @@ describe Mack::ViewHelpers::FormHelpers do
0
     
0
     it "should create a non-nested text_area for just a symbol" do
0
       text_area(:unknown).should == %{<textarea id="unknown" name="unknown"></textarea>}
0
+ text_area(:unknown, :value => "hi there").should == %{<textarea id="unknown" name="unknown">hi there</textarea>}
0
     end
0
 
0
     it "should create a nested text_area for a model with an empty value if value is false" do
0
@@ -278,18 +279,18 @@ Hello
0
     
0
   end
0
   
0
- describe "submit" do
0
+ describe "submit_button" do
0
     
0
     it "should build a simple submit tag" do
0
- submit.should == %{<input type="submit" value="Submit" />}
0
+ submit_button.should == %{<input type="submit" value="Submit" />}
0
     end
0
     
0
     it "should allow you to change the value" do
0
- submit("Login").should == %{<input type="submit" value="Login" />}
0
+ submit_button("Login").should == %{<input type="submit" value="Login" />}
0
     end
0
     
0
     it "should take options" do
0
- submit("Login", {:class => :foo}).should == %{<input class="foo" type="submit" value="Login" />}
0
+ submit_button("Login", {:class => :foo}).should == %{<input class="foo" type="submit" value="Login" />}
0
     end
0
     
0
   end

Comments

    No one has commented yet.