ramaze 2011.01.30 → 2011.07.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (229) hide show
  1. data/.gitignore +2 -1
  2. data/.mailmap +2 -0
  3. data/.rvmrc +1 -0
  4. data/README.md +119 -197
  5. data/Rakefile +14 -97
  6. data/bin/ramaze +6 -14
  7. data/doc/AUTHORS +8 -4
  8. data/doc/CHANGELOG +3784 -3339
  9. data/examples/app/chat/start.rb +2 -2
  10. data/lib/proto/app.rb +2 -3
  11. data/lib/proto/config.ru +4 -5
  12. data/lib/proto/controller/init.rb +11 -4
  13. data/lib/proto/controller/main.rb +12 -7
  14. data/lib/proto/layout/default.xhtml +56 -23
  15. data/lib/proto/model/init.rb +3 -1
  16. data/lib/proto/public/css/grid.css +107 -0
  17. data/lib/proto/public/css/layout.css +81 -0
  18. data/lib/proto/public/css/reset.css +123 -0
  19. data/lib/proto/public/css/text.css +109 -0
  20. data/lib/proto/public/images/bg.png +0 -0
  21. data/lib/proto/spec/main.rb +2 -2
  22. data/lib/proto/start.rb +11 -1
  23. data/lib/proto/view/index.xhtml +27 -23
  24. data/lib/ramaze.rb +0 -1
  25. data/lib/ramaze/app.rb +85 -12
  26. data/lib/ramaze/app_graph.rb +107 -0
  27. data/lib/ramaze/bin/console.rb +87 -0
  28. data/lib/ramaze/bin/create.rb +94 -0
  29. data/lib/ramaze/bin/helper.rb +107 -0
  30. data/lib/ramaze/bin/restart.rb +95 -0
  31. data/lib/ramaze/bin/runner.rb +141 -0
  32. data/lib/ramaze/bin/start.rb +206 -0
  33. data/lib/ramaze/bin/status.rb +152 -0
  34. data/lib/ramaze/bin/stop.rb +112 -0
  35. data/lib/ramaze/cache.rb +9 -4
  36. data/lib/ramaze/cache/localmemcache.rb +10 -13
  37. data/lib/ramaze/cache/lru.rb +49 -7
  38. data/lib/ramaze/cache/memcache.rb +170 -92
  39. data/lib/ramaze/cache/sequel.rb +301 -118
  40. data/lib/ramaze/controller.rb +108 -9
  41. data/lib/ramaze/controller/default.rb +15 -2
  42. data/lib/ramaze/current.rb +14 -2
  43. data/lib/ramaze/dependencies.rb +46 -0
  44. data/lib/ramaze/files.rb +38 -3
  45. data/lib/ramaze/gestalt.rb +12 -12
  46. data/lib/ramaze/helper.rb +0 -2
  47. data/lib/ramaze/helper/auth.rb +30 -23
  48. data/lib/ramaze/helper/blue_form.rb +175 -126
  49. data/lib/ramaze/helper/csrf.rb +76 -91
  50. data/lib/ramaze/helper/email.rb +105 -0
  51. data/lib/ramaze/helper/erector.rb +16 -15
  52. data/lib/ramaze/helper/gestalt.rb +2 -2
  53. data/lib/ramaze/helper/layout.rb +89 -73
  54. data/lib/ramaze/helper/link.rb +7 -6
  55. data/lib/ramaze/helper/localize.rb +6 -5
  56. data/lib/ramaze/helper/markaby.rb +25 -23
  57. data/lib/ramaze/helper/maruku.rb +3 -3
  58. data/lib/ramaze/helper/paginate.rb +19 -27
  59. data/lib/ramaze/helper/remarkably.rb +3 -3
  60. data/lib/ramaze/helper/request_accessor.rb +3 -3
  61. data/lib/ramaze/helper/send_file.rb +12 -8
  62. data/lib/ramaze/helper/simple_captcha.rb +5 -6
  63. data/lib/ramaze/helper/stack.rb +7 -4
  64. data/lib/ramaze/helper/tagz.rb +10 -11
  65. data/lib/ramaze/helper/thread.rb +19 -16
  66. data/lib/ramaze/helper/ultraviolet.rb +7 -4
  67. data/lib/ramaze/helper/user.rb +40 -21
  68. data/lib/ramaze/helper/xhtml.rb +29 -20
  69. data/lib/ramaze/log.rb +3 -11
  70. data/lib/ramaze/log/analogger.rb +5 -4
  71. data/lib/ramaze/log/growl.rb +9 -7
  72. data/lib/ramaze/log/hub.rb +3 -5
  73. data/lib/ramaze/log/informer.rb +15 -12
  74. data/lib/ramaze/log/knotify.rb +3 -5
  75. data/lib/ramaze/log/logger.rb +3 -5
  76. data/lib/ramaze/log/logging.rb +6 -8
  77. data/lib/ramaze/log/rotatinginformer.rb +27 -17
  78. data/lib/ramaze/log/syslog.rb +7 -7
  79. data/lib/ramaze/log/xosd.rb +3 -5
  80. data/lib/ramaze/middleware_compiler.rb +27 -4
  81. data/lib/ramaze/reloader.rb +50 -12
  82. data/lib/ramaze/reloader/watch_inotify.rb +4 -5
  83. data/lib/ramaze/reloader/watch_stat.rb +3 -3
  84. data/lib/ramaze/request.rb +18 -8
  85. data/lib/ramaze/response.rb +38 -7
  86. data/lib/ramaze/rest.rb +36 -0
  87. data/lib/ramaze/setup.rb +101 -31
  88. data/lib/ramaze/spec.rb +1 -1
  89. data/lib/ramaze/spec/bacon.rb +6 -3
  90. data/lib/ramaze/spec/helper/bacon.rb +0 -1
  91. data/lib/ramaze/version.rb +1 -1
  92. data/lib/ramaze/view.rb +2 -11
  93. data/lib/ramaze/view/erector.rb +46 -31
  94. data/lib/ramaze/view/erubis.rb +7 -3
  95. data/lib/ramaze/view/ezamar.rb +7 -3
  96. data/lib/ramaze/view/gestalt.rb +9 -3
  97. data/lib/ramaze/view/haml.rb +7 -3
  98. data/lib/ramaze/view/liquid.rb +3 -3
  99. data/lib/ramaze/view/lokar.rb +7 -3
  100. data/lib/ramaze/view/mustache.rb +11 -5
  101. data/lib/ramaze/view/nagoro.rb +3 -3
  102. data/lib/ramaze/view/sass.rb +1 -1
  103. data/lib/ramaze/view/slippers.rb +40 -13
  104. data/lib/ramaze/view/tagz.rb +9 -5
  105. data/ramaze.gemspec +23 -128
  106. data/spec/helper.rb +5 -0
  107. data/spec/ramaze/bin/app/config.ru +11 -0
  108. data/spec/ramaze/bin/create.rb +28 -0
  109. data/spec/ramaze/bin/runner.rb +30 -0
  110. data/spec/ramaze/bin/start.rb +38 -0
  111. data/spec/ramaze/cache/memcache.rb +10 -3
  112. data/spec/ramaze/cache/sequel.rb +7 -0
  113. data/spec/ramaze/controller/provide_inheritance.rb +0 -10
  114. data/spec/ramaze/dispatcher/file.rb +19 -15
  115. data/spec/ramaze/helper/auth.rb +10 -9
  116. data/spec/ramaze/helper/blue_form.rb +121 -68
  117. data/spec/ramaze/helper/email.rb +69 -0
  118. data/spec/ramaze/helper/layout.rb +12 -15
  119. data/spec/ramaze/helper/layout/alternative.xhtml +5 -0
  120. data/spec/ramaze/helper/user.rb +2 -0
  121. data/spec/ramaze/log/growl.rb +14 -1
  122. data/spec/{contrib → ramaze}/rest.rb +1 -1
  123. data/spec/ramaze/session/memcache.rb +2 -2
  124. data/spec/ramaze/view/sass.rb +1 -1
  125. data/tasks/bacon.rake +3 -3
  126. data/tasks/gem.rake +17 -18
  127. data/tasks/rcov.rake +2 -3
  128. data/tasks/release.rake +8 -65
  129. data/tasks/setup.rake +10 -8
  130. data/tasks/todo.rake +9 -5
  131. data/tasks/yard.rake +3 -2
  132. metadata +105 -397
  133. data/MANIFEST +0 -532
  134. data/TODO.md +0 -19
  135. data/benchmark/bench_templates/bench.rb +0 -67
  136. data/benchmark/bench_templates/view/large.erb +0 -79
  137. data/benchmark/bench_templates/view/large.haml +0 -41
  138. data/benchmark/bench_templates/view/large.lok +0 -79
  139. data/benchmark/bench_templates/view/large.xhtml +0 -79
  140. data/benchmark/bench_templates/view/small.erb +0 -21
  141. data/benchmark/bench_templates/view/small.haml +0 -12
  142. data/benchmark/bench_templates/view/small.lok +0 -21
  143. data/benchmark/bench_templates/view/small.xhtml +0 -21
  144. data/benchmark/results.txt +0 -131
  145. data/benchmark/run.rb +0 -355
  146. data/benchmark/suite/minimal.rb +0 -11
  147. data/benchmark/suite/no_informer.rb +0 -7
  148. data/benchmark/suite/no_sessions.rb +0 -9
  149. data/benchmark/suite/no_template.rb +0 -7
  150. data/benchmark/suite/simple.rb +0 -5
  151. data/benchmark/suite/template_erubis.rb +0 -8
  152. data/benchmark/suite/template_etanni.rb +0 -8
  153. data/benchmark/suite/template_ezamar.rb +0 -8
  154. data/benchmark/suite/template_haml.rb +0 -13
  155. data/benchmark/suite/template_liquid.rb +0 -11
  156. data/benchmark/suite/template_markaby.rb +0 -9
  157. data/benchmark/suite/template_nagoro.rb +0 -8
  158. data/benchmark/suite/template_redcloth.rb +0 -13
  159. data/benchmark/suite/template_tenjin.rb +0 -8
  160. data/benchmark/test.rb +0 -35
  161. data/doc/FAQ +0 -92
  162. data/doc/INSTALL +0 -92
  163. data/doc/TODO +0 -29
  164. data/doc/meta/announcement.txt +0 -119
  165. data/doc/meta/configuration.txt +0 -163
  166. data/doc/meta/internals.txt +0 -278
  167. data/doc/meta/users.kml +0 -64
  168. data/doc/tutorial/todolist.html +0 -1512
  169. data/doc/tutorial/todolist.txt +0 -920
  170. data/examples/app/sourceview/public/coderay.css +0 -104
  171. data/examples/app/sourceview/public/images/file.gif +0 -0
  172. data/examples/app/sourceview/public/images/folder.gif +0 -0
  173. data/examples/app/sourceview/public/images/tv-collapsable-last.gif +0 -0
  174. data/examples/app/sourceview/public/images/tv-collapsable.gif +0 -0
  175. data/examples/app/sourceview/public/images/tv-expandable-last.gif +0 -0
  176. data/examples/app/sourceview/public/images/tv-expandable.gif +0 -0
  177. data/examples/app/sourceview/public/images/tv-item-last.gif +0 -0
  178. data/examples/app/sourceview/public/images/tv-item.gif +0 -0
  179. data/examples/app/sourceview/public/jquery.js +0 -11
  180. data/examples/app/sourceview/public/jquery.treeview.css +0 -48
  181. data/examples/app/sourceview/public/jquery.treeview.js +0 -223
  182. data/examples/app/sourceview/public/sourceview.js +0 -52
  183. data/examples/app/sourceview/start.rb +0 -79
  184. data/examples/app/sourceview/view/index.haml +0 -59
  185. data/examples/helpers/httpdigest.rb +0 -107
  186. data/lib/proto/public/css/screen.css +0 -30
  187. data/lib/proto/public/js/jquery.js +0 -7179
  188. data/lib/ramaze/contrib/addressable_route.rb +0 -56
  189. data/lib/ramaze/contrib/app_graph.rb +0 -64
  190. data/lib/ramaze/contrib/email.rb +0 -88
  191. data/lib/ramaze/contrib/facebook.rb +0 -23
  192. data/lib/ramaze/contrib/facebook/facebook.rb +0 -171
  193. data/lib/ramaze/contrib/gettext.rb +0 -113
  194. data/lib/ramaze/contrib/gettext/mo.rb +0 -155
  195. data/lib/ramaze/contrib/gettext/parser.rb +0 -46
  196. data/lib/ramaze/contrib/gettext/po.rb +0 -109
  197. data/lib/ramaze/contrib/gzip_filter.rb +0 -1
  198. data/lib/ramaze/contrib/maruku_uv.rb +0 -59
  199. data/lib/ramaze/contrib/profiling.rb +0 -36
  200. data/lib/ramaze/contrib/rest.rb +0 -23
  201. data/lib/ramaze/contrib/sequel/create_join.rb +0 -26
  202. data/lib/ramaze/contrib/sequel/form_field.rb +0 -129
  203. data/lib/ramaze/contrib/sequel/image.rb +0 -196
  204. data/lib/ramaze/contrib/sequel/relation.rb +0 -98
  205. data/lib/ramaze/helper/httpdigest.rb +0 -96
  206. data/lib/ramaze/tool/bin.rb +0 -340
  207. data/lib/ramaze/tool/create.rb +0 -48
  208. data/lib/ramaze/tool/project_creator.rb +0 -120
  209. data/lib/ramaze/view/less.rb +0 -12
  210. data/lib/ramaze/view/maruku.rb +0 -15
  211. data/lib/ramaze/view/redcloth.rb +0 -21
  212. data/spec/contrib/addressable_route.rb +0 -30
  213. data/spec/examples/helpers/httpdigest.rb +0 -64
  214. data/spec/examples/templates/template_redcloth.rb +0 -13
  215. data/spec/ramaze/bin/ramaze.rb +0 -96
  216. data/spec/ramaze/helper/httpdigest.rb +0 -176
  217. data/spec/ramaze/view/less.rb +0 -60
  218. data/spec/ramaze/view/less/file.css.less +0 -8
  219. data/spec/ramaze/view/redcloth.rb +0 -66
  220. data/spec/ramaze/view/redcloth/external.redcloth +0 -8
  221. data/tasks/copyright.rake +0 -21
  222. data/tasks/gem_setup.rake +0 -112
  223. data/tasks/git.rake +0 -46
  224. data/tasks/grancher.rake +0 -12
  225. data/tasks/jquery.rake +0 -15
  226. data/tasks/manifest.rake +0 -4
  227. data/tasks/metric_changes.rake +0 -24
  228. data/tasks/reversion.rake +0 -8
  229. 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
- # Since November 2010 the BlueForm helper works different. You can now specify an object as the first
13
- # parameter of the form_for() method. This object will be used to retrieve the values of each field.
14
- # This means that you can directly pass a database result object to the form and no longer have
15
- # to manually specify values. However, you can still specify your own values if you want.
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() method. What kind of object this is,
34
- # a database result object or an OpenStruct object doesn't matter as long as the attributes can be accessed
35
- # outside of the object (this can be done using attr_readers). This makes it extremely easy to directly pass
36
- # a result object from your favourite ORM. Example:
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 to nil.
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
- # When using the form helper as a block in your templates it's important to remember that the
53
- # result is returned and not displayed in the browser directly. When using Etanni this would result in
54
- # something like the following:
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 called
71
- # using a block and it's return value should be manually sent to the browser (since it does not echo the value).
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 field.
74
- # @param [Hash] options Hash containing any additional form attributes such as the method, action, enctype and so on.
75
- # @param [Block] block Block containing the elements of the form such as password fields, textareas and so on.
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
- # The first parameter is the name of the form field and the second parameter is the custom message.
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 belongs.
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 to set
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 flash hash.
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 specific tags,
132
- # such as textareas and select boxes. Do note that this class is not thread-safe so you should
133
- # modify it only within one thread of execution.
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 field.
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 instead of input_text.
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 values.
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 the content of these fields is replaced with dots.
240
- # This method has the following alias: "password".
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 values.
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 once it's clicked
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 values.
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". This method will also
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 a hash.
295
- # In the case of an array the values will also be used as text for each checkbox.
296
- # When using a hash the key will be displayed and the value will be the value of the
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
- # Get the default value for the checkbox used for the hidden field.
328
- if args[:default]
329
- default = args[:default]
330
- args.delete(:default)
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
- default = 0
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 means we can use
351
- # this method for the input_radio method.
352
- if !args[:type]
353
- args[:type] = :checkbox
354
- end
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
- label_for(id, label, name)
366
- self.input_hidden(name, default)
367
-
368
- # Loop through all the values. Each checkbox will have an ID of "form-NAME-INDEX".
369
- # Each name will be NAME followed by [] to indicate it's an array (since multiple values are possible).
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 = args[:id] ? args[:id] : "#{id_for(name)}_#{index}"
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 values array.
380
- opts = args.clone
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(:name => checkbox_name, :id => id, :value => checkbox_value)
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}" value="#{value}" /> #{value}
445
+ # <input type="checkbox" name="#{checkbox_name}" id="#{id}"
446
+ # value="#{value}" /> #{value}
403
447
  # </span>
404
448
  #
405
- @g.span :class => span_class do
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". This method will also
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 just like
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 button should be checked.
441
- # @param [Hash] args Any additional HTML attributes along with their values.
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 values.
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 text fields
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 values.
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 values.
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 string
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