ramaze 2011.01.30 → 2011.07.25
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/.mailmap +2 -0
- data/.rvmrc +1 -0
- data/README.md +119 -197
- data/Rakefile +14 -97
- data/bin/ramaze +6 -14
- data/doc/AUTHORS +8 -4
- data/doc/CHANGELOG +3784 -3339
- data/examples/app/chat/start.rb +2 -2
- data/lib/proto/app.rb +2 -3
- data/lib/proto/config.ru +4 -5
- data/lib/proto/controller/init.rb +11 -4
- data/lib/proto/controller/main.rb +12 -7
- data/lib/proto/layout/default.xhtml +56 -23
- data/lib/proto/model/init.rb +3 -1
- data/lib/proto/public/css/grid.css +107 -0
- data/lib/proto/public/css/layout.css +81 -0
- data/lib/proto/public/css/reset.css +123 -0
- data/lib/proto/public/css/text.css +109 -0
- data/lib/proto/public/images/bg.png +0 -0
- data/lib/proto/spec/main.rb +2 -2
- data/lib/proto/start.rb +11 -1
- data/lib/proto/view/index.xhtml +27 -23
- data/lib/ramaze.rb +0 -1
- data/lib/ramaze/app.rb +85 -12
- data/lib/ramaze/app_graph.rb +107 -0
- data/lib/ramaze/bin/console.rb +87 -0
- data/lib/ramaze/bin/create.rb +94 -0
- data/lib/ramaze/bin/helper.rb +107 -0
- data/lib/ramaze/bin/restart.rb +95 -0
- data/lib/ramaze/bin/runner.rb +141 -0
- data/lib/ramaze/bin/start.rb +206 -0
- data/lib/ramaze/bin/status.rb +152 -0
- data/lib/ramaze/bin/stop.rb +112 -0
- data/lib/ramaze/cache.rb +9 -4
- data/lib/ramaze/cache/localmemcache.rb +10 -13
- data/lib/ramaze/cache/lru.rb +49 -7
- data/lib/ramaze/cache/memcache.rb +170 -92
- data/lib/ramaze/cache/sequel.rb +301 -118
- data/lib/ramaze/controller.rb +108 -9
- data/lib/ramaze/controller/default.rb +15 -2
- data/lib/ramaze/current.rb +14 -2
- data/lib/ramaze/dependencies.rb +46 -0
- data/lib/ramaze/files.rb +38 -3
- data/lib/ramaze/gestalt.rb +12 -12
- data/lib/ramaze/helper.rb +0 -2
- data/lib/ramaze/helper/auth.rb +30 -23
- data/lib/ramaze/helper/blue_form.rb +175 -126
- data/lib/ramaze/helper/csrf.rb +76 -91
- data/lib/ramaze/helper/email.rb +105 -0
- data/lib/ramaze/helper/erector.rb +16 -15
- data/lib/ramaze/helper/gestalt.rb +2 -2
- data/lib/ramaze/helper/layout.rb +89 -73
- data/lib/ramaze/helper/link.rb +7 -6
- data/lib/ramaze/helper/localize.rb +6 -5
- data/lib/ramaze/helper/markaby.rb +25 -23
- data/lib/ramaze/helper/maruku.rb +3 -3
- data/lib/ramaze/helper/paginate.rb +19 -27
- data/lib/ramaze/helper/remarkably.rb +3 -3
- data/lib/ramaze/helper/request_accessor.rb +3 -3
- data/lib/ramaze/helper/send_file.rb +12 -8
- data/lib/ramaze/helper/simple_captcha.rb +5 -6
- data/lib/ramaze/helper/stack.rb +7 -4
- data/lib/ramaze/helper/tagz.rb +10 -11
- data/lib/ramaze/helper/thread.rb +19 -16
- data/lib/ramaze/helper/ultraviolet.rb +7 -4
- data/lib/ramaze/helper/user.rb +40 -21
- data/lib/ramaze/helper/xhtml.rb +29 -20
- data/lib/ramaze/log.rb +3 -11
- data/lib/ramaze/log/analogger.rb +5 -4
- data/lib/ramaze/log/growl.rb +9 -7
- data/lib/ramaze/log/hub.rb +3 -5
- data/lib/ramaze/log/informer.rb +15 -12
- data/lib/ramaze/log/knotify.rb +3 -5
- data/lib/ramaze/log/logger.rb +3 -5
- data/lib/ramaze/log/logging.rb +6 -8
- data/lib/ramaze/log/rotatinginformer.rb +27 -17
- data/lib/ramaze/log/syslog.rb +7 -7
- data/lib/ramaze/log/xosd.rb +3 -5
- data/lib/ramaze/middleware_compiler.rb +27 -4
- data/lib/ramaze/reloader.rb +50 -12
- data/lib/ramaze/reloader/watch_inotify.rb +4 -5
- data/lib/ramaze/reloader/watch_stat.rb +3 -3
- data/lib/ramaze/request.rb +18 -8
- data/lib/ramaze/response.rb +38 -7
- data/lib/ramaze/rest.rb +36 -0
- data/lib/ramaze/setup.rb +101 -31
- data/lib/ramaze/spec.rb +1 -1
- data/lib/ramaze/spec/bacon.rb +6 -3
- data/lib/ramaze/spec/helper/bacon.rb +0 -1
- data/lib/ramaze/version.rb +1 -1
- data/lib/ramaze/view.rb +2 -11
- data/lib/ramaze/view/erector.rb +46 -31
- data/lib/ramaze/view/erubis.rb +7 -3
- data/lib/ramaze/view/ezamar.rb +7 -3
- data/lib/ramaze/view/gestalt.rb +9 -3
- data/lib/ramaze/view/haml.rb +7 -3
- data/lib/ramaze/view/liquid.rb +3 -3
- data/lib/ramaze/view/lokar.rb +7 -3
- data/lib/ramaze/view/mustache.rb +11 -5
- data/lib/ramaze/view/nagoro.rb +3 -3
- data/lib/ramaze/view/sass.rb +1 -1
- data/lib/ramaze/view/slippers.rb +40 -13
- data/lib/ramaze/view/tagz.rb +9 -5
- data/ramaze.gemspec +23 -128
- data/spec/helper.rb +5 -0
- data/spec/ramaze/bin/app/config.ru +11 -0
- data/spec/ramaze/bin/create.rb +28 -0
- data/spec/ramaze/bin/runner.rb +30 -0
- data/spec/ramaze/bin/start.rb +38 -0
- data/spec/ramaze/cache/memcache.rb +10 -3
- data/spec/ramaze/cache/sequel.rb +7 -0
- data/spec/ramaze/controller/provide_inheritance.rb +0 -10
- data/spec/ramaze/dispatcher/file.rb +19 -15
- data/spec/ramaze/helper/auth.rb +10 -9
- data/spec/ramaze/helper/blue_form.rb +121 -68
- data/spec/ramaze/helper/email.rb +69 -0
- data/spec/ramaze/helper/layout.rb +12 -15
- data/spec/ramaze/helper/layout/alternative.xhtml +5 -0
- data/spec/ramaze/helper/user.rb +2 -0
- data/spec/ramaze/log/growl.rb +14 -1
- data/spec/{contrib → ramaze}/rest.rb +1 -1
- data/spec/ramaze/session/memcache.rb +2 -2
- data/spec/ramaze/view/sass.rb +1 -1
- data/tasks/bacon.rake +3 -3
- data/tasks/gem.rake +17 -18
- data/tasks/rcov.rake +2 -3
- data/tasks/release.rake +8 -65
- data/tasks/setup.rake +10 -8
- data/tasks/todo.rake +9 -5
- data/tasks/yard.rake +3 -2
- metadata +105 -397
- data/MANIFEST +0 -532
- data/TODO.md +0 -19
- data/benchmark/bench_templates/bench.rb +0 -67
- data/benchmark/bench_templates/view/large.erb +0 -79
- data/benchmark/bench_templates/view/large.haml +0 -41
- data/benchmark/bench_templates/view/large.lok +0 -79
- data/benchmark/bench_templates/view/large.xhtml +0 -79
- data/benchmark/bench_templates/view/small.erb +0 -21
- data/benchmark/bench_templates/view/small.haml +0 -12
- data/benchmark/bench_templates/view/small.lok +0 -21
- data/benchmark/bench_templates/view/small.xhtml +0 -21
- data/benchmark/results.txt +0 -131
- data/benchmark/run.rb +0 -355
- data/benchmark/suite/minimal.rb +0 -11
- data/benchmark/suite/no_informer.rb +0 -7
- data/benchmark/suite/no_sessions.rb +0 -9
- data/benchmark/suite/no_template.rb +0 -7
- data/benchmark/suite/simple.rb +0 -5
- data/benchmark/suite/template_erubis.rb +0 -8
- data/benchmark/suite/template_etanni.rb +0 -8
- data/benchmark/suite/template_ezamar.rb +0 -8
- data/benchmark/suite/template_haml.rb +0 -13
- data/benchmark/suite/template_liquid.rb +0 -11
- data/benchmark/suite/template_markaby.rb +0 -9
- data/benchmark/suite/template_nagoro.rb +0 -8
- data/benchmark/suite/template_redcloth.rb +0 -13
- data/benchmark/suite/template_tenjin.rb +0 -8
- data/benchmark/test.rb +0 -35
- data/doc/FAQ +0 -92
- data/doc/INSTALL +0 -92
- data/doc/TODO +0 -29
- data/doc/meta/announcement.txt +0 -119
- data/doc/meta/configuration.txt +0 -163
- data/doc/meta/internals.txt +0 -278
- data/doc/meta/users.kml +0 -64
- data/doc/tutorial/todolist.html +0 -1512
- data/doc/tutorial/todolist.txt +0 -920
- data/examples/app/sourceview/public/coderay.css +0 -104
- data/examples/app/sourceview/public/images/file.gif +0 -0
- data/examples/app/sourceview/public/images/folder.gif +0 -0
- data/examples/app/sourceview/public/images/tv-collapsable-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-collapsable.gif +0 -0
- data/examples/app/sourceview/public/images/tv-expandable-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-expandable.gif +0 -0
- data/examples/app/sourceview/public/images/tv-item-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-item.gif +0 -0
- data/examples/app/sourceview/public/jquery.js +0 -11
- data/examples/app/sourceview/public/jquery.treeview.css +0 -48
- data/examples/app/sourceview/public/jquery.treeview.js +0 -223
- data/examples/app/sourceview/public/sourceview.js +0 -52
- data/examples/app/sourceview/start.rb +0 -79
- data/examples/app/sourceview/view/index.haml +0 -59
- data/examples/helpers/httpdigest.rb +0 -107
- data/lib/proto/public/css/screen.css +0 -30
- data/lib/proto/public/js/jquery.js +0 -7179
- data/lib/ramaze/contrib/addressable_route.rb +0 -56
- data/lib/ramaze/contrib/app_graph.rb +0 -64
- data/lib/ramaze/contrib/email.rb +0 -88
- data/lib/ramaze/contrib/facebook.rb +0 -23
- data/lib/ramaze/contrib/facebook/facebook.rb +0 -171
- data/lib/ramaze/contrib/gettext.rb +0 -113
- data/lib/ramaze/contrib/gettext/mo.rb +0 -155
- data/lib/ramaze/contrib/gettext/parser.rb +0 -46
- data/lib/ramaze/contrib/gettext/po.rb +0 -109
- data/lib/ramaze/contrib/gzip_filter.rb +0 -1
- data/lib/ramaze/contrib/maruku_uv.rb +0 -59
- data/lib/ramaze/contrib/profiling.rb +0 -36
- data/lib/ramaze/contrib/rest.rb +0 -23
- data/lib/ramaze/contrib/sequel/create_join.rb +0 -26
- data/lib/ramaze/contrib/sequel/form_field.rb +0 -129
- data/lib/ramaze/contrib/sequel/image.rb +0 -196
- data/lib/ramaze/contrib/sequel/relation.rb +0 -98
- data/lib/ramaze/helper/httpdigest.rb +0 -96
- data/lib/ramaze/tool/bin.rb +0 -340
- data/lib/ramaze/tool/create.rb +0 -48
- data/lib/ramaze/tool/project_creator.rb +0 -120
- data/lib/ramaze/view/less.rb +0 -12
- data/lib/ramaze/view/maruku.rb +0 -15
- data/lib/ramaze/view/redcloth.rb +0 -21
- data/spec/contrib/addressable_route.rb +0 -30
- data/spec/examples/helpers/httpdigest.rb +0 -64
- data/spec/examples/templates/template_redcloth.rb +0 -13
- data/spec/ramaze/bin/ramaze.rb +0 -96
- data/spec/ramaze/helper/httpdigest.rb +0 -176
- data/spec/ramaze/view/less.rb +0 -60
- data/spec/ramaze/view/less/file.css.less +0 -8
- data/spec/ramaze/view/redcloth.rb +0 -66
- data/spec/ramaze/view/redcloth/external.redcloth +0 -8
- data/tasks/copyright.rake +0 -21
- data/tasks/gem_setup.rake +0 -112
- data/tasks/git.rake +0 -46
- data/tasks/grancher.rake +0 -12
- data/tasks/jquery.rake +0 -15
- data/tasks/manifest.rake +0 -4
- data/tasks/metric_changes.rake +0 -24
- data/tasks/reversion.rake +0 -8
- data/tasks/traits.rake +0 -21
@@ -5,14 +5,17 @@ module Ramaze
|
|
5
5
|
module Helper
|
6
6
|
##
|
7
7
|
# == Introduction
|
8
|
-
#
|
9
|
-
# The BlueForm helper tries to be an even better way to build forms programmatically.
|
10
|
-
# By using a simple block you can quickly create all the required elements for your form.
|
11
8
|
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
9
|
+
# The BlueForm helper tries to be an even better way to build forms
|
10
|
+
# programmatically. By using a simple block you can quickly create all the
|
11
|
+
# required elements for your form.
|
12
|
+
#
|
13
|
+
# Since November 2010 the BlueForm helper works different. You can now
|
14
|
+
# specify an object as the first parameter of the form_for() method. This
|
15
|
+
# object will be used to retrieve the values of each field. This means that
|
16
|
+
# you can directly pass a database result object to the form and no longer
|
17
|
+
# have to manually specify values. However, you can still specify your own
|
18
|
+
# values if you want.
|
16
19
|
#
|
17
20
|
# Old behaviour:
|
18
21
|
#
|
@@ -30,10 +33,12 @@ module Ramaze
|
|
30
33
|
#
|
31
34
|
# == Form Data
|
32
35
|
#
|
33
|
-
# As stated earlier it's possible to pass an object to the form_for()
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
36
|
+
# As stated earlier it's possible to pass an object to the form_for()
|
37
|
+
# method. What kind of object this is, a database result object or an
|
38
|
+
# OpenStruct object doesn't matter as long as the attributes can be accessed
|
39
|
+
# outside of the object (this can be done using attr_readers). This makes it
|
40
|
+
# extremely easy to directly pass a result object from your favourite ORM.
|
41
|
+
# Example:
|
37
42
|
#
|
38
43
|
# @data = User[1]
|
39
44
|
#
|
@@ -41,24 +46,27 @@ module Ramaze
|
|
41
46
|
# f.input_text 'Username', :username
|
42
47
|
# end
|
43
48
|
#
|
44
|
-
# If you don't want to use an object you can simply set the first parameter
|
49
|
+
# If you don't want to use an object you can simply set the first parameter
|
50
|
+
# to nil.
|
45
51
|
#
|
46
52
|
# == HTML Output
|
47
|
-
#
|
48
|
-
# The form helper uses Gestalt, Ramaze's custom HTML builder that works somewhat like Erector.
|
49
|
-
# The output is very minimalistic, elements such as legends and fieldsets have to be added manually.
|
50
|
-
# Each combination of a label and input element will be wrapped in <p> tags.
|
51
53
|
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
54
|
+
# The form helper uses Gestalt, Ramaze's custom HTML builder that works
|
55
|
+
# somewhat like Erector. The output is very minimalistic, elements such as
|
56
|
+
# legends and fieldsets have to be added manually. Each combination of a
|
57
|
+
# label and input element will be wrapped in <p> tags.
|
58
|
+
#
|
59
|
+
# When using the form helper as a block in your templates it's important to
|
60
|
+
# remember that the result is returned and not displayed in the browser
|
61
|
+
# directly. When using Etanni this would result in something like the
|
62
|
+
# following:
|
55
63
|
#
|
56
64
|
# #{
|
57
65
|
# form_for(@result, :method => :post) do |f| do
|
58
66
|
# f.input_text 'Text label', :textname, 'Chunky bacon!'
|
59
67
|
# end
|
60
68
|
# }
|
61
|
-
#
|
69
|
+
#
|
62
70
|
# @example
|
63
71
|
#
|
64
72
|
# form_for(@data, :method => :post) do |f|
|
@@ -67,12 +75,16 @@ module Ramaze
|
|
67
75
|
#
|
68
76
|
module BlueForm
|
69
77
|
##
|
70
|
-
# The form method generates the basic structure of the form. It should be
|
71
|
-
# using a block and it's return value should be manually sent to
|
78
|
+
# The form method generates the basic structure of the form. It should be
|
79
|
+
# called using a block and it's return value should be manually sent to
|
80
|
+
# the browser (since it does not echo the value).
|
72
81
|
#
|
73
|
-
# @param [Object] form_values Object containing the values for each form
|
74
|
-
#
|
75
|
-
# @param [
|
82
|
+
# @param [Object] form_values Object containing the values for each form
|
83
|
+
# field.
|
84
|
+
# @param [Hash] options Hash containing any additional form attributes
|
85
|
+
# such as the method, action, enctype and so on.
|
86
|
+
# @param [Block] block Block containing the elements of the form such as
|
87
|
+
# password fields, textareas and so on.
|
76
88
|
#
|
77
89
|
def form_for(form_values, options = {}, &block)
|
78
90
|
form = Form.new(form_values, options)
|
@@ -81,10 +93,12 @@ module Ramaze
|
|
81
93
|
end
|
82
94
|
|
83
95
|
##
|
84
|
-
# Manually add a new error to the form_errors key in the flash hash.
|
85
|
-
#
|
96
|
+
# Manually add a new error to the form_errors key in the flash hash. The
|
97
|
+
# first parameter is the name of the form field and the second parameter
|
98
|
+
# is the custom message.
|
86
99
|
#
|
87
|
-
# @param [String] name The name of the form field to which the error
|
100
|
+
# @param [String] name The name of the form field to which the error
|
101
|
+
# belongs.
|
88
102
|
# @param [String] message The custom error message to show.
|
89
103
|
#
|
90
104
|
def form_error(name, message)
|
@@ -97,8 +111,8 @@ module Ramaze
|
|
97
111
|
end
|
98
112
|
|
99
113
|
##
|
100
|
-
# Returns the hash containing all existing errors and allows other methods
|
101
|
-
# new errors by using this method as if it were a hash.
|
114
|
+
# Returns the hash containing all existing errors and allows other methods
|
115
|
+
# to set new errors by using this method as if it were a hash.
|
102
116
|
#
|
103
117
|
# @return [Array] All form errors.
|
104
118
|
#
|
@@ -111,7 +125,8 @@ module Ramaze
|
|
111
125
|
end
|
112
126
|
|
113
127
|
##
|
114
|
-
# Retrieve all the form errors for the specified model and add them to the
|
128
|
+
# Retrieve all the form errors for the specified model and add them to the
|
129
|
+
# flash hash.
|
115
130
|
#
|
116
131
|
# @param [Object] obj An object of a model that contains form errors.
|
117
132
|
#
|
@@ -121,16 +136,17 @@ module Ramaze
|
|
121
136
|
if value.respond_to?(:first)
|
122
137
|
value = value.first
|
123
138
|
end
|
124
|
-
|
139
|
+
|
125
140
|
form_error(key.to_s, value % key)
|
126
141
|
end
|
127
142
|
end
|
128
143
|
end
|
129
144
|
|
130
145
|
##
|
131
|
-
# Main form class that contains all the required methods to generate form
|
132
|
-
# such as textareas and select boxes. Do note that this
|
133
|
-
# modify it only within one thread
|
146
|
+
# Main form class that contains all the required methods to generate form
|
147
|
+
# specific tags, such as textareas and select boxes. Do note that this
|
148
|
+
# class is not thread-safe so you should modify it only within one thread
|
149
|
+
# of execution.
|
134
150
|
#
|
135
151
|
class Form
|
136
152
|
attr_reader :g
|
@@ -139,7 +155,8 @@ module Ramaze
|
|
139
155
|
##
|
140
156
|
# Constructor method that generates an instance of the Form class.
|
141
157
|
#
|
142
|
-
# @param [Object] form_values Object containing the values for each form
|
158
|
+
# @param [Object] form_values Object containing the values for each form
|
159
|
+
# field.
|
143
160
|
# @param [Hash] options A hash containing any additional form attributes.
|
144
161
|
# @return [Object] An instance of the Form class.
|
145
162
|
#
|
@@ -159,15 +176,15 @@ module Ramaze
|
|
159
176
|
# Convert all the keys in form_errors to strings and
|
160
177
|
# retrieve the correct values in case
|
161
178
|
@form_errors = {}
|
162
|
-
|
179
|
+
|
163
180
|
form_errors.each do |key, value|
|
164
181
|
if value.respond_to?(:first)
|
165
182
|
value = value.first
|
166
183
|
end
|
167
|
-
|
184
|
+
|
168
185
|
@form_errors[key.to_s] = value
|
169
186
|
end
|
170
|
-
|
187
|
+
|
171
188
|
@g.form(@form_args) do
|
172
189
|
if block_given?
|
173
190
|
yield self
|
@@ -180,7 +197,7 @@ module Ramaze
|
|
180
197
|
#
|
181
198
|
# @param [String] text The text to display inside the legend tag.
|
182
199
|
# @example
|
183
|
-
#
|
200
|
+
#
|
184
201
|
# form_for(@data, :method => :post) do |f|
|
185
202
|
# f.legend 'Ramaze rocks!'
|
186
203
|
# end
|
@@ -188,13 +205,13 @@ module Ramaze
|
|
188
205
|
def legend(text)
|
189
206
|
@g.legend(text)
|
190
207
|
end
|
191
|
-
|
208
|
+
|
192
209
|
##
|
193
210
|
# Generate a fieldset tag.
|
194
211
|
#
|
195
212
|
# @param [Block] &block The form elements to display inside the fieldset.
|
196
213
|
# @example
|
197
|
-
#
|
214
|
+
#
|
198
215
|
# form_for(@data, :method => :post) do |f|
|
199
216
|
# f.fieldset do
|
200
217
|
# f.legend 'Hello, world!'
|
@@ -202,16 +219,18 @@ module Ramaze
|
|
202
219
|
# end
|
203
220
|
#
|
204
221
|
def fieldset(&block)
|
205
|
-
@g.fieldset(block)
|
222
|
+
@g.fieldset(&block)
|
206
223
|
end
|
207
224
|
|
208
225
|
##
|
209
226
|
# Generate an input tag with a type of "text" along with a label tag.
|
210
|
-
# This method also has the alias "text" so feel free to use that one
|
211
|
-
#
|
227
|
+
# This method also has the alias "text" so feel free to use that one
|
228
|
+
# instead of input_text.
|
229
|
+
#
|
212
230
|
# @param [String] label The text to display inside the label tag.
|
213
231
|
# @param [String Symbol] name The name of the text field.
|
214
|
-
# @param [Hash] args Any additional HTML attributes along with their
|
232
|
+
# @param [Hash] args Any additional HTML attributes along with their
|
233
|
+
# values.
|
215
234
|
# @example
|
216
235
|
#
|
217
236
|
# form_for(@data, :method => :post) do |f|
|
@@ -236,14 +255,16 @@ module Ramaze
|
|
236
255
|
|
237
256
|
##
|
238
257
|
# Generate an input tag with a type of "password" along with a label.
|
239
|
-
# Password fields are pretty much the same as text fields except that
|
240
|
-
# This method has the
|
258
|
+
# Password fields are pretty much the same as text fields except that
|
259
|
+
# the content of these fields is replaced with dots. This method has the
|
260
|
+
# following alias: "password".
|
241
261
|
#
|
242
262
|
# @param [String] label The text to display inside the label tag.
|
243
263
|
# @param [String Symbol] name The name of the password field.
|
244
|
-
# @param [Hash] args Any additional HTML attributes along with their
|
264
|
+
# @param [Hash] args Any additional HTML attributes along with their
|
265
|
+
# values.
|
245
266
|
# @example
|
246
|
-
#
|
267
|
+
#
|
247
268
|
# form_for(@data, :method => :post) do |f|
|
248
269
|
# f.input_password 'My password', :password
|
249
270
|
# end
|
@@ -252,11 +273,11 @@ module Ramaze
|
|
252
273
|
# The ID can come from 2 places, id_for and the args hash
|
253
274
|
id = args[:id] ? args[:id] : id_for(name)
|
254
275
|
args = args.merge(:type => :password, :name => name, :id => id)
|
255
|
-
|
276
|
+
|
256
277
|
if !args[:value] and @form_values.respond_to?(name)
|
257
278
|
args[:value] = @form_values.send(name)
|
258
279
|
end
|
259
|
-
|
280
|
+
|
260
281
|
@g.p do
|
261
282
|
label_for(id, label, name)
|
262
283
|
@g.input(args)
|
@@ -265,11 +286,12 @@ module Ramaze
|
|
265
286
|
alias password input_password
|
266
287
|
|
267
288
|
##
|
268
|
-
# Generate a submit tag (without a label). A submit tag is a button that
|
269
|
-
# will send the form data to the server.
|
289
|
+
# Generate a submit tag (without a label). A submit tag is a button that
|
290
|
+
# once it's clicked will send the form data to the server.
|
270
291
|
#
|
271
292
|
# @param [String] value The text to display in the button.
|
272
|
-
# @param [Hash] args Any additional HTML attributes along with their
|
293
|
+
# @param [Hash] args Any additional HTML attributes along with their
|
294
|
+
# values.
|
273
295
|
# @example
|
274
296
|
#
|
275
297
|
# form_for(@data, :method => :post) do |f|
|
@@ -287,14 +309,12 @@ module Ramaze
|
|
287
309
|
alias submit input_submit
|
288
310
|
|
289
311
|
##
|
290
|
-
# Generate an input tag with a type of "checkbox".
|
291
|
-
# generate a hidden field with the same name as the checkbox to ensure
|
292
|
-
# that the data is always submitted.
|
312
|
+
# Generate an input tag with a type of "checkbox".
|
293
313
|
#
|
294
|
-
# If you want to have multiple checkboxes you can either use an array or
|
295
|
-
# In the case of an array the values will also be used as text
|
296
|
-
# When using a hash the key will be displayed and
|
297
|
-
# checkbox. Example:
|
314
|
+
# If you want to have multiple checkboxes you can either use an array or
|
315
|
+
# a hash. In the case of an array the values will also be used as text
|
316
|
+
# for each checkbox. When using a hash the key will be displayed and
|
317
|
+
# the value will be the value of the checkbox. Example:
|
298
318
|
#
|
299
319
|
# @data = Class.new
|
300
320
|
# attr_reader :gender_arr
|
@@ -311,25 +331,44 @@ module Ramaze
|
|
311
331
|
# f.input_checkbox "Gender", :gender_hash
|
312
332
|
# end
|
313
333
|
#
|
314
|
-
# @param [String] label The text to display inside the label tag.
|
315
|
-
# @param [String Symbol] name The name of the checkbox.
|
316
|
-
# @param [String] checked String that indicates if (and which) checkbox should be checked.
|
317
|
-
# @param [Hash] args Any additional HTML attributes along with their values.
|
318
334
|
# @example
|
319
|
-
#
|
320
335
|
# form_for(@data, :method => :post) do |f|
|
321
336
|
# f.input_checkbox 'Remember me', :remember_user
|
322
337
|
# end
|
323
338
|
#
|
339
|
+
# @param [String] label The text to display inside the label tag.
|
340
|
+
# @param [String Symbol] name The name of the checkbox.
|
341
|
+
# @param [String] checked String that indicates if (and which) checkbox
|
342
|
+
# should be checked.
|
343
|
+
# @param [Hash] args Any additional HTML attributes along with their
|
344
|
+
# values.
|
345
|
+
# @option args [String/Symbol] :id The value to use for the ID attribute.
|
346
|
+
# @option args [Array] :values An array containing the possible values
|
347
|
+
# for the checkboxes.
|
348
|
+
# @option args [String/Symbol] :span_class The class to use for the
|
349
|
+
# <span> element that's wrapped around the checkbox.
|
350
|
+
# @option args [TrueClass/FalseClass] :show_value When set to false the
|
351
|
+
# value of each checkbox won't be displayed to the right of the
|
352
|
+
# checkbox. This option is set to true by default.
|
353
|
+
# @option args [TrueClass/FalseClass] :show_label When set to true
|
354
|
+
# (default) the label for the checkbox will be displayed. Setting this
|
355
|
+
# to false will hide it.
|
356
|
+
#
|
324
357
|
def input_checkbox(label, name, checked = nil, args = {})
|
325
358
|
id = args[:id] ? args[:id] : "#{id_for(name)}_0"
|
326
359
|
|
327
|
-
#
|
328
|
-
if args
|
329
|
-
|
330
|
-
|
360
|
+
# Determine whether or not to show the value of the checkbox
|
361
|
+
if args.key?(:show_value)
|
362
|
+
show_value = args.delete(:show_value)
|
363
|
+
else
|
364
|
+
show_value = true
|
365
|
+
end
|
366
|
+
|
367
|
+
# Determine whether or not to show the label
|
368
|
+
if args.key?(:show_label)
|
369
|
+
show_label = args.delete(:show_label)
|
331
370
|
else
|
332
|
-
|
371
|
+
show_label = true
|
333
372
|
end
|
334
373
|
|
335
374
|
# Get the checkbox value from either the args hash or from
|
@@ -337,7 +376,7 @@ module Ramaze
|
|
337
376
|
if !args[:values] and @form_values.respond_to?(name)
|
338
377
|
args[:values] = @form_values.send(name)
|
339
378
|
end
|
340
|
-
|
379
|
+
|
341
380
|
# That class for each element wrapper (a span tag) can be customized
|
342
381
|
# using :span_class => "a_class".
|
343
382
|
if args[:span_class]
|
@@ -346,38 +385,40 @@ module Ramaze
|
|
346
385
|
else
|
347
386
|
span_class = "checkbox_wrap"
|
348
387
|
end
|
349
|
-
|
350
|
-
# Get the type from the args hash instead of pre-defining it. Doing so
|
351
|
-
# this method for the input_radio method.
|
352
|
-
if !args[:type]
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
# Convert the values to an array if it's something we can't use in a loop (e.g. a string).
|
388
|
+
|
389
|
+
# Get the type from the args hash instead of pre-defining it. Doing so
|
390
|
+
# means we can use this method for the input_radio method.
|
391
|
+
args[:type] = :checkbox if !args[:type]
|
392
|
+
|
393
|
+
# Convert the values to an array if it's something we can't use in a loop
|
394
|
+
# (e.g. a string).
|
357
395
|
if args[:values].class != Hash and args[:values].class != Array
|
358
396
|
args[:values] = [args[:values]]
|
359
397
|
end
|
360
|
-
|
398
|
+
|
361
399
|
# Create a checkbox for each value
|
362
400
|
if !args[:values].empty?
|
363
401
|
@g.p do
|
364
402
|
# Let's create the label and the hidden field
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
#
|
403
|
+
if show_label === true
|
404
|
+
label_for(id, label, name)
|
405
|
+
end
|
406
|
+
|
407
|
+
# Loop through all the values. Each checkbox will have an ID of
|
408
|
+
# "form-NAME-INDEX". Each name will be NAME followed by [] to
|
409
|
+
# indicate it's an array (since multiple values are possible).
|
370
410
|
args[:values].each_with_index do |value, index|
|
371
|
-
id
|
372
|
-
|
411
|
+
id = args[:id] ? args[:id] : "#{id_for(name)}_#{index}"
|
412
|
+
|
373
413
|
if args[:type] == :checkbox
|
374
414
|
checkbox_name = "#{name}[]"
|
375
415
|
else
|
376
416
|
checkbox_name = name
|
377
417
|
end
|
378
|
-
|
379
|
-
# Copy all additional attributes and their values except the
|
380
|
-
|
418
|
+
|
419
|
+
# Copy all additional attributes and their values except the
|
420
|
+
# values array.
|
421
|
+
opts = args.clone
|
381
422
|
opts.delete(:values)
|
382
423
|
|
383
424
|
# Get the value and text to display for each checkbox
|
@@ -394,17 +435,20 @@ module Ramaze
|
|
394
435
|
end
|
395
436
|
|
396
437
|
# And we're done, easy wasn't it?
|
397
|
-
opts = opts.merge(
|
438
|
+
opts = opts.merge(
|
439
|
+
:name => checkbox_name, :id => id, :value => checkbox_value
|
440
|
+
)
|
398
441
|
|
399
442
|
# Generate the following HTML:
|
400
443
|
#
|
401
444
|
# <span class="#{span_class}">
|
402
|
-
# <input type="checkbox" name="#{checkbox_name}" id="#{id}"
|
445
|
+
# <input type="checkbox" name="#{checkbox_name}" id="#{id}"
|
446
|
+
# value="#{value}" /> #{value}
|
403
447
|
# </span>
|
404
448
|
#
|
405
|
-
@g.span
|
449
|
+
@g.span(:class => span_class) do
|
406
450
|
@g.input(opts)
|
407
|
-
" #{checkbox_text}"
|
451
|
+
" #{checkbox_text}" if show_value === true
|
408
452
|
end
|
409
453
|
end
|
410
454
|
end
|
@@ -413,12 +457,10 @@ module Ramaze
|
|
413
457
|
alias checkbox input_checkbox
|
414
458
|
|
415
459
|
##
|
416
|
-
# Generate an input tag with a type of "radio".
|
417
|
-
# generate a hidden field with the same name as the radio button to ensure
|
418
|
-
# that the data is always submitted.
|
460
|
+
# Generate an input tag with a type of "radio".
|
419
461
|
#
|
420
|
-
# If you want to generate multiple radio buttons you can use an array
|
421
|
-
# you can with checkboxes. Example:
|
462
|
+
# If you want to generate multiple radio buttons you can use an array
|
463
|
+
# just like you can with checkboxes. Example:
|
422
464
|
#
|
423
465
|
# @data = Class.new
|
424
466
|
# attr_reader :gender_arr
|
@@ -435,13 +477,16 @@ module Ramaze
|
|
435
477
|
# f.input_radio "Gender", :gender_hash
|
436
478
|
# end
|
437
479
|
#
|
480
|
+
# For more information see the input_checkbox() method.
|
481
|
+
#
|
438
482
|
# @param [String] label The text to display inside the label tag.
|
439
483
|
# @param [String Symbol] name The name of the radio button.
|
440
|
-
# @param [String] checked String that indicates if (and which) radio
|
441
|
-
#
|
484
|
+
# @param [String] checked String that indicates if (and which) radio
|
485
|
+
# button should be checked.
|
486
|
+
# @param [Hash] args Any additional HTML attributes along with their
|
487
|
+
# values.
|
442
488
|
# @see input_checkbox()
|
443
489
|
# @example
|
444
|
-
#
|
445
490
|
# form_for(@data, :method => :post) do |f|
|
446
491
|
# f.input_radio 'Gender', :gender
|
447
492
|
# end
|
@@ -449,21 +494,22 @@ module Ramaze
|
|
449
494
|
def input_radio(label, name, checked = nil, args = {})
|
450
495
|
# Force a type of "radio"
|
451
496
|
args[:type] = :radio
|
452
|
-
|
497
|
+
|
453
498
|
if !args[:span_class]
|
454
499
|
args[:span_class] = "radio_wrap"
|
455
500
|
end
|
456
|
-
|
501
|
+
|
457
502
|
self.input_checkbox(label, name, checked, args)
|
458
503
|
end
|
459
504
|
alias radio input_radio
|
460
505
|
|
461
506
|
##
|
462
507
|
# Generate a field for uploading files.
|
463
|
-
#
|
508
|
+
#
|
464
509
|
# @param [String] label The text to display inside the label tag.
|
465
510
|
# @param [String Symbol] name The name of the radio tag.
|
466
|
-
# @param [Hash] args Any additional HTML attributes along with their
|
511
|
+
# @param [Hash] args Any additional HTML attributes along with their
|
512
|
+
# values.
|
467
513
|
# @example
|
468
514
|
#
|
469
515
|
# form_for(@data, :method => :post) do |f|
|
@@ -482,21 +528,22 @@ module Ramaze
|
|
482
528
|
alias file input_file
|
483
529
|
|
484
530
|
##
|
485
|
-
# Generate a hidden field. Hidden fields are essentially the same as
|
486
|
-
# except that they aren't displayed in the browser.
|
531
|
+
# Generate a hidden field. Hidden fields are essentially the same as
|
532
|
+
# text fields except that they aren't displayed in the browser.
|
487
533
|
#
|
488
534
|
# @param [String Symbol] name The name of the hidden field tag.
|
489
535
|
# @param [String] value The value of the hidden field
|
490
|
-
# @param [Hash] args Any additional HTML attributes along with their
|
536
|
+
# @param [Hash] args Any additional HTML attributes along with their
|
537
|
+
# values.
|
491
538
|
# @example
|
492
539
|
#
|
493
540
|
# form_for(@data, :method => :post) do |f|
|
494
541
|
# f.input_hidden :user_id
|
495
542
|
# end
|
496
|
-
#
|
543
|
+
#
|
497
544
|
def input_hidden(name, value = nil, args = {})
|
498
545
|
args = args.merge(:type => :hidden, :name => name)
|
499
|
-
|
546
|
+
|
500
547
|
if !value and @form_values.respond_to?(name)
|
501
548
|
args[:value] = @form_values.send(name)
|
502
549
|
else
|
@@ -512,7 +559,8 @@ module Ramaze
|
|
512
559
|
#
|
513
560
|
# @param [String] label The text to display inside the label tag.
|
514
561
|
# @param [String Symbol] name The name of the textarea.
|
515
|
-
# @param [Hash] args Any additional HTML attributes along with their
|
562
|
+
# @param [Hash] args Any additional HTML attributes along with their
|
563
|
+
# values.
|
516
564
|
# @example
|
517
565
|
#
|
518
566
|
# form_for(@data, :method => :post) do |f|
|
@@ -521,7 +569,7 @@ module Ramaze
|
|
521
569
|
#
|
522
570
|
def textarea(label, name, args = {})
|
523
571
|
id = args[:id] ? args[:id] : id_for(name)
|
524
|
-
|
572
|
+
|
525
573
|
# Get the value of the textarea
|
526
574
|
if !args[:value] and @form_values.respond_to?(name)
|
527
575
|
value = @form_values.send(name)
|
@@ -529,7 +577,7 @@ module Ramaze
|
|
529
577
|
value = args[:value]
|
530
578
|
args.delete(:value)
|
531
579
|
end
|
532
|
-
|
580
|
+
|
533
581
|
args = args.merge(:name => name, :id => id)
|
534
582
|
|
535
583
|
@g.p do
|
@@ -540,7 +588,7 @@ module Ramaze
|
|
540
588
|
|
541
589
|
##
|
542
590
|
# Generate a select tag along with the option tags and a label.
|
543
|
-
#
|
591
|
+
#
|
544
592
|
# @param [String] label The text to display inside the label tag.
|
545
593
|
# @param [String Symbol] name The name of the select tag.
|
546
594
|
# @param [Hash] args Hash containing additional HTML attributes.
|
@@ -553,7 +601,7 @@ module Ramaze
|
|
553
601
|
def select(label, name, args = {})
|
554
602
|
id = args[:id] ? args[:id] : id_for(name)
|
555
603
|
multiple, size = args.values_at(:multiple, :size)
|
556
|
-
|
604
|
+
|
557
605
|
# Get all the values
|
558
606
|
if !args[:values] and @form_values.respond_to?(name)
|
559
607
|
values = @form_values.send(name)
|
@@ -561,7 +609,7 @@ module Ramaze
|
|
561
609
|
values = args[:values]
|
562
610
|
args.delete(:values)
|
563
611
|
end
|
564
|
-
|
612
|
+
|
565
613
|
args[:multiple] = 'multiple' if multiple
|
566
614
|
args[:size] = (size || values.count || 1).to_i
|
567
615
|
args[:name] = multiple ? "#{name}[]" : name
|
@@ -578,11 +626,11 @@ module Ramaze
|
|
578
626
|
values.each do |value, o_name|
|
579
627
|
o_name ||= value
|
580
628
|
o_args = {:value => value}
|
581
|
-
|
629
|
+
|
582
630
|
if has_selected and selected.include?(value)
|
583
631
|
o_args[:selected] = 'selected'
|
584
632
|
end
|
585
|
-
|
633
|
+
|
586
634
|
@g.option(o_args){ o_name }
|
587
635
|
end
|
588
636
|
end
|
@@ -590,7 +638,8 @@ module Ramaze
|
|
590
638
|
end
|
591
639
|
|
592
640
|
##
|
593
|
-
# Method used for converting the results of the BlueForm helper to a
|
641
|
+
# Method used for converting the results of the BlueForm helper to a
|
642
|
+
# string
|
594
643
|
#
|
595
644
|
# @return [String] The form output
|
596
645
|
#
|
@@ -628,7 +677,7 @@ module Ramaze
|
|
628
677
|
"form_#{field_name}".downcase.gsub(/-/, '_')
|
629
678
|
end
|
630
679
|
end
|
631
|
-
end
|
632
|
-
end
|
633
|
-
end
|
634
|
-
end
|
680
|
+
end # Form
|
681
|
+
end # BlueForm
|
682
|
+
end # Helper
|
683
|
+
end # Ramaze
|