ShadowBelmolve-formtastic 0.2.1 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/README.textile +191 -176
  2. data/Rakefile +65 -22
  3. data/generators/form/USAGE +16 -0
  4. data/generators/form/form_generator.rb +120 -0
  5. data/generators/form/templates/view__form.html.erb +5 -0
  6. data/generators/form/templates/view__form.html.haml +4 -0
  7. data/generators/formtastic/formtastic_generator.rb +24 -0
  8. data/generators/{formtastic_stylesheets → formtastic}/templates/formtastic.css +2 -0
  9. data/generators/formtastic/templates/formtastic.rb +51 -0
  10. data/generators/{formtastic_stylesheets → formtastic}/templates/formtastic_changes.css +0 -0
  11. data/generators/formtastic_stylesheets/formtastic_stylesheets_generator.rb +5 -10
  12. data/lib/formtastic.rb +1234 -895
  13. data/lib/formtastic/i18n.rb +32 -0
  14. data/lib/locale/en.yml +2 -2
  15. data/rails/init.rb +1 -1
  16. data/spec/buttons_spec.rb +149 -0
  17. data/spec/commit_button_spec.rb +344 -0
  18. data/spec/custom_builder_spec.rb +62 -0
  19. data/spec/custom_macros.rb +561 -0
  20. data/spec/defaults_spec.rb +20 -0
  21. data/spec/error_proc_spec.rb +27 -0
  22. data/spec/errors_spec.rb +85 -0
  23. data/spec/form_helper_spec.rb +120 -0
  24. data/spec/i18n_spec.rb +131 -0
  25. data/spec/include_blank_spec.rb +70 -0
  26. data/spec/input_spec.rb +608 -0
  27. data/spec/inputs/boolean_input_spec.rb +93 -0
  28. data/spec/inputs/check_boxes_input_spec.rb +162 -0
  29. data/spec/inputs/country_input_spec.rb +80 -0
  30. data/spec/inputs/date_input_spec.rb +45 -0
  31. data/spec/inputs/datetime_input_spec.rb +155 -0
  32. data/spec/inputs/file_input_spec.rb +33 -0
  33. data/spec/inputs/hidden_input_spec.rb +52 -0
  34. data/spec/inputs/numeric_input_spec.rb +44 -0
  35. data/spec/inputs/password_input_spec.rb +46 -0
  36. data/spec/inputs/radio_input_spec.rb +149 -0
  37. data/spec/inputs/select_input_spec.rb +459 -0
  38. data/spec/inputs/string_input_spec.rb +47 -0
  39. data/spec/inputs/text_input_spec.rb +33 -0
  40. data/spec/inputs/time_input_spec.rb +44 -0
  41. data/spec/inputs/time_zone_input_spec.rb +102 -0
  42. data/spec/inputs_spec.rb +395 -0
  43. data/spec/label_spec.rb +48 -0
  44. data/spec/nested_forms_spec.rb +50 -0
  45. data/spec/semantic_fields_for_spec.rb +44 -0
  46. data/spec/spec.opts +2 -0
  47. data/spec/spec_helper.rb +212 -0
  48. metadata +121 -16
  49. data/lib/justin_french/formtastic.rb +0 -10
  50. data/spec/formtastic_spec.rb +0 -3072
  51. data/spec/test_helper.rb +0 -14
@@ -2,9 +2,6 @@ h1. Formtastic
2
2
 
3
3
  Formtastic is a Rails FormBuilder DSL (with some other goodies) to make it far easier to create beautiful, semantically rich, syntactically awesome, readily stylable and wonderfully accessible HTML forms in your Rails applications.
4
4
 
5
- * This fork: http://github.com/ShadowBelmolve/formtastic
6
- * Forked from: http://github.com/justinfrench/formtastic/tree/master
7
-
8
5
  h2. The Story
9
6
 
10
7
  One day, I finally had enough, so I opened up my text editor, and wrote a DSL for how I'd like to author forms:
@@ -45,34 +42,34 @@ I also wrote the accompanying HTML output I expected, favoring something very si
45
42
 
46
43
  h2. It's better than _SomeOtherFormBuilder_ because...
47
44
 
48
- * it can handle @belongs_to@ associations (like Post belongs_to :author), rendering a select or set of radio inputs with choices from the parent model
49
- * it can handle @has_many@ and @has_and_belongs_to_many@ associations (like Post has_many :tags), rendering a multi-select with choices from the child models
50
- * it's Rails 2.3-ready (including nested forms)
45
+ * it can handle @belongs_to@ associations (like Post belongs_to :author), rendering a select or set of radio inputs with choices from the parent model.
46
+ * it can handle @has_many@ and @has_and_belongs_to_many@ associations (like: Post has_many :tags), rendering a multi-select with choices from the child models.
47
+ * it's Rails 2.3-ready (including nested forms).
51
48
  * it has internationalization (I18n)!
52
- * it's _really_ quick to get started with a basic form in place (4 lines), then go back to add in more detail if you need it
53
- * there's heaps of elements, id and class attributes for you to hook in your CSS and JS
54
- * it handles real world stuff like inline hints, inline error messages & help text
55
- * it doesn't hijack or change any of the standard Rails form inputs, so you can still use them as expected (even mix and match)
56
- * it's got absolutely awesome spec coverage
57
- * there's a bunch of people using and working on it (it's not just one developer building half a solution)
49
+ * it's _really_ quick to get started with a basic form in place (4 lines), then go back to add in more detail if you need it.
50
+ * there's heaps of elements, id and class attributes for you to hook in your CSS and JS.
51
+ * it handles real world stuff like inline hints, inline error messages & help text.
52
+ * it doesn't hijack or change any of the standard Rails form inputs, so you can still use them as expected (even mix and match).
53
+ * it's got absolutely awesome spec coverage.
54
+ * there's a bunch of people using and working on it (it's not just one developer building half a solution).
58
55
 
59
56
 
60
57
  h2. Why?
61
58
 
62
- * web apps = lots of forms
63
- * forms are so friggin' boring to code
64
- * semantically rich & accessible forms really are possible
65
- * the "V" is way behind the "M" and "C" in Rails' MVC – it's the ugly sibling
66
- * best practices and common patterns have to start somewhere
67
- * i need a challenge
59
+ * web apps = lots of forms.
60
+ * forms are so friggin' boring to code.
61
+ * semantically rich & accessible forms really are possible.
62
+ * the "V" is way behind the "M" and "C" in Rails' MVC – it's the ugly sibling.
63
+ * best practices and common patterns have to start somewhere.
64
+ * i need a challenge.
68
65
 
69
66
 
70
67
  h2. Opinions
71
68
 
72
- * it should be easier to do things the right way than the wrong way
73
- * sometimes _more mark-up_ is better
74
- * elements and attribute hooks are _gold_ for stylesheet authors
75
- * make the common things we do easy, yet still ensure uncommon things are still possible
69
+ * it should be easier to do things the right way than the wrong way.
70
+ * sometimes _more mark-up_ is better.
71
+ * elements and attribute hooks are _gold_ for stylesheet authors.
72
+ * make the common things we do easy, yet still ensure uncommon things are still possible.
76
73
 
77
74
 
78
75
  h2. Documentation
@@ -82,24 +79,29 @@ RDoc documentation _should_ be automatically generated after each commit and mad
82
79
 
83
80
  h2. Installation
84
81
 
85
- You can (and should) get it as a gem:
82
+ The gem is hosted on gemcutter, so *if you haven't already*, add it as a gem source:
86
83
 
87
84
  <pre>
88
- gem install ShadowBelmolve-formtastic
85
+ sudo gem sources -a http://gemcutter.org/
89
86
  </pre>
90
87
 
91
- And then add it as a dependency in your environment.rb file:
88
+ Then install the Formtastic gem:
92
89
 
93
90
  <pre>
94
- config.gem "ShadowBelmolve-formtastic",
95
- :lib => 'formtastic',
96
- :source => 'http://gems.github.com'
91
+ sudo gem install formtastic
97
92
  </pre>
98
93
 
99
- If you're a little more old school, install it as a plugin:
94
+ Optionally, run @./script/generate formtastic@ to copy the following files into your app:
95
+
96
+ * @config/initializers/formtastic.rb@ - a commented out Formtastic config initializer
97
+ * @public/stylesheets/formtastic.css@
98
+ * @public/stylesheets/formtastic_changes.css@
99
+
100
+ A proof-of-concept stylesheet is provided which you can include in your layout. Customization is best achieved by overriding these styles in an additional stylesheet so that the Formtastic styles can be updated without clobbering your changes. If you want to use these stylesheets, add both to your layout:
100
101
 
101
102
  <pre>
102
- ./script/plugin install git://github.com/justinfrench/formtastic.git
103
+ <%= stylesheet_link_tag "formtastic" %>
104
+ <%= stylesheet_link_tag "formtastic_changes" %>
103
105
  </pre>
104
106
 
105
107
 
@@ -107,7 +109,7 @@ h2. Usage
107
109
 
108
110
  Forms are really boring to code... you want to get onto the good stuff as fast as possible.
109
111
 
110
- This renders a set of inputs (one for _most_ columns in the database table, and one for each ActiveRecord belongs_to association), followed by a submit button:
112
+ This renders a set of inputs (one for _most_ columns in the database table, and one for each ActiveRecord @belongs_to@-association), followed by a submit button:
111
113
 
112
114
  <pre>
113
115
  <% semantic_form_for @user do |form| %>
@@ -125,7 +127,7 @@ If you want to specify the order of the fields, skip some of the fields or even
125
127
  <% end %>
126
128
  </pre>
127
129
 
128
- If you want control over the input type Formtastic uses for each field, you can expand the @inputs@ and @buttons@ blocks. This specifies the :section input should be a set of radio buttons (rather than the default select box), and that the :created_at field should be a string (rather than the default datetime selects):
130
+ If you want control over the input type Formtastic uses for each field, you can expand the @inputs@ and @buttons@ blocks. This specifies the @:section@ input should be a set of radio buttons (rather than the default select box), and that the @:created_at@ field should be a string (rather than the default datetime selects):
129
131
 
130
132
  <pre>
131
133
  <% semantic_form_for @post do |form| %>
@@ -146,7 +148,7 @@ If you want to customize the label text, or render some hint text below the fiel
146
148
 
147
149
  <pre>
148
150
  <% semantic_form_for @post do |form| %>
149
- <% form.inputs :name => "Basic", :id => "basic" do %>
151
+ <% form.inputs "Basic", :id => "basic" do %>
150
152
  <%= form.input :title %>
151
153
  <%= form.input :body %>
152
154
  <% end %>
@@ -163,14 +165,13 @@ If you want to customize the label text, or render some hint text below the fiel
163
165
  <% end %>
164
166
  </pre>
165
167
 
166
-
167
168
  Nested forms (Rails 2.3) are also supported. You can do it in the Rails way:
168
169
 
169
170
  <pre>
170
171
  <% semantic_form_for @post do |form| %>
171
172
  <%= form.inputs :title, :body, :created_at %>
172
173
  <% form.semantic_fields_for :author do |author| %>
173
- <%= author.inputs :first_name, :last_name, :name => 'Author' %>
174
+ <%= author.inputs :first_name, :last_name, :name => "Author" %>
174
175
  <% end %>
175
176
  <%= form.buttons %>
176
177
  <% end %>
@@ -186,7 +187,7 @@ Or the Formtastic way with the @:for@ option:
186
187
  <% end %>
187
188
  </pre>
188
189
 
189
- When working in has many association, you can even supply "%i" in your fieldset name that it will be properly interpolated with the child index. For example:
190
+ When working in has many association, you can even supply @"%i"@ in your fieldset name that it will be properly interpolated with the child index. For example:
190
191
 
191
192
  <pre>
192
193
  <% semantic_form_for @post do |form| %>
@@ -197,7 +198,7 @@ When working in has many association, you can even supply "%i" in your fieldset
197
198
  </pre>
198
199
 
199
200
 
200
- Customize HTML attributes for any input using the @:input_html@ option. Typically his is used to disable the input, change the size of a text field, change the rows in a textarea, or even to add a special class to an input to attach special behavior like "autogrow":http://plugins.jquery.com/project/autogrow textareas:
201
+ Customize HTML attributes for any input using the @:input_html@ option. Typically his is used to disable the input, change the size of a text field, change the rows in a textarea, or even to add a special class to an input to attach special behavior like "autogrow":http://plugins.jquery.com/project/autogrow textareas:
201
202
 
202
203
  <pre>
203
204
  <% semantic_form_for @post do |form| %>
@@ -219,8 +220,8 @@ The same can be done for buttons with the @:button_html@ option:
219
220
  <% end %>
220
221
  </pre>
221
222
 
222
- Customize the HTML attributes for the @<li>@ wrapper around every input with the @:wrapper_html@ option hash. There's one special key in the hash (:class), which will actually _append_ your string of classes to the existing classes provided by Formtastic (like "required string error")
223
-
223
+ Customize the HTML attributes for the @<li>@ wrapper around every input with the @:wrapper_html@ option hash. There's one special key in the hash (@:class@), which will actually _append_ your string of classes to the existing classes provided by Formtastic (like @"required string error"@)
224
+
224
225
  <pre>
225
226
  <% semantic_form_for @post do |form| %>
226
227
  <%= form.input :title, :wrapper_html => { :class => "important" } %>
@@ -231,37 +232,35 @@ Customize the HTML attributes for the @<li>@ wrapper around every input with the
231
232
  </pre>
232
233
 
233
234
 
234
-
235
235
  h2. The Available Inputs
236
236
 
237
- * :select (a select menu) - default for ActiveRecord associations (belongs_to, has_many, has_and_belongs_to_many)
238
- * :check_boxes (a set of check_box inputs) - alternative to :select has_many and has_and_belongs_to_many associations
239
- * :radio (a set of radio inputs) - alternative to :select for ActiveRecord belongs_to associations
240
- * :time_zone (a select input) - default for :string column types with 'time_zone' in the method name
241
- * :password (a password input) - default for :string column types with 'password' in the method name
242
- * :text (a textarea) - default for :text column types
243
- * :date (a date select) - default for :date column types
244
- * :datetime (a date and time select) - default for :datetime and :timestamp column types
245
- * :time (a time select) - default for :time column types
246
- * :boolean (a checkbox) - default for :boolean column types
247
- * :string (a text field) - default for :string column types
248
- * :numeric (a text field, like string) - default for :integer, :float and :decimal column types
249
- * :file (a file field) - default for paperclip or attachment_fu attributes
250
- * :country (a select menu of country names) - default for :string columns named "country", requires a country_select plugin to be installed
251
- * :hidden (a hidden field) - creates a hidden field (added for compatibility)
252
-
253
-
254
- The documentation is pretty good for each of these (what it does, what the output is, what the options are, etc) so go check it out.
237
+ The Formtastic input types:
238
+
239
+ * @:select@ - a select menu. Default for ActiveRecord associations: @belongs_to@, @has_many@, and @has_and_belongs_to_many@.
240
+ * @:check_boxes@ - a set of check_box inputs. Alternative to @:select@ for ActiveRecord-associations: @has_many@, and @has_and_belongs_to_many@.
241
+ * @:radio@ - a set of radio inputs. Alternative to @:select@ for ActiveRecord-associations: @belongs_to@.
242
+ * @:time_zone@ - a select input. Default for column types: @:string@ with name matching @"time_zone"@.
243
+ * @:password@ - a password input. Default for column types: @:string@ with name matching @"password"@.
244
+ * @:text@ - a textarea. Default for column types: @:text@.
245
+ * @:date@ - a date select. Default for column types: @:date@.
246
+ * @:datetime@ - a date and time select. Default for column types: @:datetime@ and @:timestamp@.
247
+ * @:time@ - a time select. Default for column types: @:time@.
248
+ * @:boolean@ - a checkbox. Default for column types: @:boolean@.
249
+ * @:string@ - a text field. Default for column types: @:string@.
250
+ * @:numeric@ - a text field (just like string). Default for column types: @:integer@, @:float@, and @:decimal@.
251
+ * @:file@ - a file field. Default for file-attachment attributes matching: "paperclip":http://github.com/thoughtbot/paperclip or "attachment_fu":http://github.com/technoweenie/attachment_fu.
252
+ * @:country@ - a select menu of country names. Default for column types: :string with name @"country"@ - requires a *country_select* plugin to be installed.
253
+ * @:hidden@ - a hidden field. Creates a hidden field (added for compatibility).
254
+
255
+ The documentation is pretty good for each of these (what it does, what the output is, what the options are, etc.) so go check it out.
255
256
 
256
257
  h2. Internationalization (I18n)
257
258
 
258
- Formtastic got some neat I18n-features. ActiveRecord object names and attributes are, by default, taken from calling @object.human_name and @object.human_attribute_name(attr) respectively. There are a few words specific to Formtastic that can be translated. See lib/locale/en.yml for more information.
259
+ h3. Basic Localization
259
260
 
260
- h3. Label/Hint-localization
261
+ Formtastic got some neat I18n-features. ActiveRecord object names and attributes are, by default, taken from calling @@object.human_name@ and @@object.human_attribute_name(attr)@ respectively. There are a few words specific to Formtastic that can be translated. See @lib/locale/en.yml@ for more information.
261
262
 
262
- Formtastic supports localized *labels* and *hints* using the I18n API for more advanced usage. Your forms can now be DRYer and more flexible than ever, and still fully localized. This is how:
263
-
264
- Basic localization (labels only):
263
+ Basic localization (labels only, with ActiveRecord):
265
264
 
266
265
  <pre>
267
266
  <% semantic_form_for @post do |form| %>
@@ -271,50 +270,83 @@ Basic localization (labels only):
271
270
  <% end %>
272
271
  </pre>
273
272
 
274
- *Note:* This is perfectly fine if you just want your labels to be translated using *ActiveRecord I18n attribute translations*, and you don't use input hints. But what if you do? And what if you don't want same labels in all forms?
273
+ *Note:* This is perfectly fine if you just want your labels/attributes and/or models to be translated using *ActiveRecord I18n attribute translations*, and you don't use input hints and legends. But what if you do? And what if you don't want same labels in all forms?
274
+
275
+ h3. Enhanced Localization (Formtastic I18n API)
275
276
 
276
- Enhanced localization (labels and hints):
277
+ Formtastic supports localized *labels*, *hints*, *legends*, *actions* using the I18n API for more advanced usage. Your forms can now be DRYer and more flexible than ever, and still fully localized. This is how:
277
278
 
278
- 1. Enable I18n lookups by default (@config/initializers/formtastic.rb@):
279
+ *1. Enable I18n lookups by default (@config/initializers/formtastic.rb@):*
279
280
 
280
281
  <pre>
281
282
  Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
282
283
  </pre>
283
284
 
284
- 2. Add some cool label-translations/variants (@config/locale/en.yml@):
285
+ *2. Add some cool label-translations/variants (@config/locale/en.yml@):*
285
286
 
286
287
  <pre>
287
288
  en:
288
289
  formtastic:
290
+ titles:
291
+ post_details: "Post details"
289
292
  labels:
290
293
  post:
291
294
  title: "Choose a title..."
292
295
  body: "Write something..."
296
+ edit:
297
+ title: "Edit title"
293
298
  hints:
294
299
  post:
295
300
  title: "Choose a good title for you post."
296
301
  body: "Write something inspiring here."
302
+ actions:
303
+ create: "Create my {{model}}"
304
+ update: "Save changes"
305
+ dummie: "Launch!"
297
306
  </pre>
298
307
 
299
308
  *Note:* We are using English here still, but you get the point.
300
309
 
301
- 3. ...and now you'll get:
310
+ *3. ...and now you'll get:*
302
311
 
303
312
  <pre>
304
- <% semantic_form_for @post do |form| %>
305
- <%= form.input :title %> # => :label => "Choose a title...", :hint => "Choose a good title for you post."
306
- <%= form.input :body %> # => :label => "Write something...", :hint => "Write something inspiring here."
307
- <%= form.input :section %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
313
+ <% semantic_form_for Post.new do |form| %>
314
+ <% form.inputs do %>
315
+ <%= form.input :title %> # => :label => "Choose a title...", :hint => "Choose a good title for you post."
316
+ <%= form.input :body %> # => :label => "Write something...", :hint => "Write something inspiring here."
317
+ <%= form.input :section %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
318
+ <% end %>
319
+ <% form.buttons do %>
320
+ <%= form.commit_button %> # => "Create my {{model}}"
321
+ <% end %>
308
322
  <% end %>
309
323
  </pre>
310
324
 
311
- 4. Override I18n settings:
325
+ *4. Localized titles (a.k.a. legends):*
326
+
327
+ _Note: Slightly different because Formtastic can't guess how you group fields in a form. Legend text can be set with first (as in the sample below) specified value, or :name/:title options - depending on what flavor is preferred._
328
+
329
+ <pre>
330
+ <% semantic_form_for @post do |form| %>
331
+ <% form.inputs :post_details do %> # => :title => "Post details"
332
+ # ...
333
+ <% end %>
334
+ # ...
335
+ <% end %>
336
+ </pre>
337
+
338
+ *5. Override I18n settings:*
312
339
 
313
340
  <pre>
314
341
  <% semantic_form_for @post do |form| %>
315
- <%= form.input :title %> # => :label => "Choose a title...", :hint => "Choose a good title for you post."
316
- <%= form.input :body, :hint => false %> # => :label => "Write something..."
317
- <%= form.input :section %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
342
+ <% form.inputs do %>
343
+ <%= form.input :title %> # => :label => "Choose a title...", :hint => "Choose a good title for you post."
344
+ <%= form.input :body, :hint => false %> # => :label => "Write something..."
345
+ <%= form.input :section, :label => 'Some section' %> # => :label => 'Some section'
346
+ <% end %>
347
+ <% form.buttons do %>
348
+ <%= form.commit_button :dummie %> # => "Launch!"
349
+ <% end %>
318
350
  <% end %>
319
351
  </pre>
320
352
 
@@ -328,25 +360,30 @@ If I18n-lookups is disabled, i.e.:
328
360
 
329
361
  <pre>
330
362
  <% semantic_form_for @post do |form| %>
331
- <%= form.input :title, :label => true %> # => :label => "Choose a title..."
332
- <%= form.input :body, :label => true %> # => :label => "Write something..."
333
- <%= form.input :section, :label => true %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
363
+ <% form.inputs do %>
364
+ <%= form.input :title, :label => true %> # => :label => "Choose a title..."
365
+ <%= form.input :body, :label => true %> # => :label => "Write something..."
366
+ <%= form.input :section, :label => true %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
367
+ <% end %>
368
+ <% form.buttons do %>
369
+ <%= form.commit_button true %> # => "Save changes" (if we are in edit that is...)
370
+ <% end %>
334
371
  <% end %>
335
372
  </pre>
336
373
 
337
- 5. Advanced I18n lookups
374
+ *6. Advanced I18n lookups*
338
375
 
339
376
  For more flexible forms; Formtastic find translations using a bottom-up approach taking the following variables in account:
340
377
 
341
- * @model@, e.g. "post"
342
- * @action@, e.g. "edit"
343
- * @attribute@, e.g. "title"
378
+ * @MODEL@, e.g. "post"
379
+ * @ACTION@, e.g. "edit"
380
+ * @KEY/ATTRIBUTE@, e.g. "title", :my_custom_key, ...
344
381
 
345
382
  ...in the following order:
346
383
 
347
- 1. @formtastic.{labels,hints}.MODEL.ACTION.ATTRIBUTE@ # By model and action
348
- 2. @formtastic.{labels,hints}.MODEL.ATTRIBUTE@ # By model
349
- 3. @formtastic.{labels,hints}.ATTRIBUTE@ # Global default
384
+ 1. @formtastic.{titles,labels,hints,actions}.MODEL.ACTION.ATTRIBUTE@ - by model and action
385
+ 2. @formtastic.{titles,labels,hints,actions}.MODEL.ATTRIBUTE@ - by model
386
+ 3. @formtastic.{titles,labels,hints,actions}.ATTRIBUTE@ - global default
350
387
 
351
388
  ...which means that you can define translations like this:
352
389
 
@@ -364,139 +401,117 @@ For more flexible forms; Formtastic find translations using a bottom-up approach
364
401
  edit:
365
402
  title: "Edit title"
366
403
  body: "Edit body"
367
- ...
368
404
  </pre>
369
405
 
406
+ Values for @labels@/@hints@/@actions@ are can take values: @String@ (explicit value), @Symbol@ (i18n-lookup-key relative to the current "type", e.g. actions:), @true@ (force I18n lookup), @false@ (force no I18n lookup). Titles (legends) can only take: @String@ and @Symbol@ - true/false have no meaning.
407
+
408
+
370
409
  h2. ValidationReflection plugin
371
410
 
372
- If you have the "ValidationReflection":http://github.com/redinger/validation_reflection plugin installed, you won't have to specify the :required option (it checks the validations on the model instead).
411
+ If you have the "ValidationReflection":http://github.com/redinger/validation_reflection plugin installed, you won't have to specify the @:required@ option (it checks the validations on the model instead).
412
+
373
413
 
374
414
  h2. Configuration
375
415
 
376
- If you wish, put something like this in config/initializers/formtastic_config.rb:
416
+ Run @./script/generate formtastic@ to copy a commented out config file into @config/initializers/formtastic.rb@. You can "view the configuration file on GitHub":http://github.com/justinfrench/formtastic/blob/master/generators/formtastic/templates/formtastic.rb
417
+
418
+
419
+ h2. Form Generator
420
+
421
+ There's a Formtastic form code generator to make your transition to Formtastic easier. All you have to do is to *specify an existing model name*, and optionally specify view template framework (ERB/HAML), and you are good to go. *Note:* This won't overwrite any of you stuff. This is how you use it:
422
+
423
+ *Alt. 1: Generate in terminal:*
377
424
 
378
425
  <pre>
379
- # Set the default text field size when input is a string. Default is 50
380
- Formtastic::SemanticFormBuilder.default_text_field_size = 30
381
-
382
- # Should all fields be considered "required" by default
383
- # Defaults to true, see ValidationReflection notes below
384
- Formtastic::SemanticFormBuilder.all_fields_required_by_default = false
385
-
386
- # Set the string that will be appended to the labels/fieldsets which are required
387
- # It accepts string or procs and the default is a localized version of
388
- # '<abbr title="required">*</abbr>'. In other words, if you configure formtastic.required
389
- # in your locale, it will replace the abbr title properly. But if you don't want to use
390
- # abbr tag, you can simply give a string as below
391
- Formtastic::SemanticFormBuilder.required_string = "(required)"
392
-
393
- # Set the string that will be appended to the labels/fieldsets which are optional
394
- # Defaults to an empty string ("") and also accepts procs (see required_string above)
395
- Formtastic::SemanticFormBuilder.optional_string = "(optional)"
396
-
397
- # Set the way inline errors will be displayed.
398
- # Defaults to :sentence, valid options are :sentence, :list and :none
399
- Formtastic::SemanticFormBuilder.inline_errors = :list
400
-
401
- # Set the method to call on label text to transform or format it for human-friendly
402
- # reading when formtastic is user without object. Defaults to :humanize.
403
- Formtastic::SemanticFormBuilder.label_str_method = :titleize
404
-
405
- # Set the array of methods to try calling on parent objects in :select and :radio inputs
406
- # for the text inside each @<option>@ tag or alongside each radio @<input>@. The first method
407
- # that is found on the object will be used.
408
- # Defaults to ["to_label", "display_name", "full_name", "name", "title", "username", "login", "value", "to_s"]
409
- Formtastic::SemanticFormBuilder.collection_label_methods = ["title_and_author", "display_name", "login", "to_s"]
410
-
411
- # Formtastic by default renders inside li tags the input, hints and then
412
- # errors messages. Sometimes you want the hints to be rendered first than
413
- # the input, in the following order: hints, input and errors. You can
414
- # customize it doing just as below:
415
- Formtastic::SemanticFormBuilder.inline_order = [:hints, :input, :errors]
416
-
417
- # Set the default "priority countries" to suit your user base when using :as => :country
418
- Formtastic::SemanticFormBuilder.priority_countries = ["Australia", "New Zealand"]
419
-
420
- # Specifies if labels/hints for input fields automatically be looked up using I18n.
421
- # Default value: false. Overridden for specific fields by setting value to true,
422
- # i.e. :label => true, or :hint => true (or opposite depending on initialized value)
423
- # Formtastic::SemanticFormBuilder.i18n_lookups_by_default = false
426
+ $ ./script/generate form Post
427
+ # ---------------------------------------------------------
428
+ # GENERATED FORMTASTIC CODE
429
+ # ---------------------------------------------------------
430
+
431
+ <% form.inputs do %>
432
+ <%= form.input :title, :label => 'Title' %>
433
+ <%= form.input :body, :label => 'Body' %>
434
+ <%= form.input :published, :label => 'Published' %>
435
+ <% end %>
436
+
437
+ # ---------------------------------------------------------
438
+ Copied to clipboard - just paste it!
424
439
  </pre>
425
440
 
426
- h2. Status
441
+ *Alt. 2: Generate partial:*
427
442
 
428
- *THINGS ARE GOING TO CHANGE A BIT BEFORE WE HIT 1.0.*
443
+ <pre>
444
+ $ ./script/generate form Post --partial
445
+ exists app/views/posts
446
+ create app/views/posts/_form.html.erb
447
+ </pre>
429
448
 
430
- It's a work in progress and a bit rough around the edges still, but I hope you try it and offer some suggestions and improvements anyway.
449
+ To generate *HAML* markup, just add the @--haml@ as argument:
431
450
 
432
- On the plus side, it has a comprehensive spec suite and contributions from at least ten independent developers.
451
+ <pre>
452
+ $ ./script/generate form Post --haml
453
+ exists app/views/admin/posts
454
+ create app/views/admin/posts/_form.html.haml
455
+ </pre>
433
456
 
434
- "Wishlist":http://wiki.github.com/justinfrench/formtastic/wishlist on the wiki is serving as pretty good documentation for the roadmap to 1.0 and beyond right now, but I'll work on getting a real tracking system or something happening soon.
457
+ To specify the controller in a namespace (eg admin/posts instead of posts), use the --controller argument:
435
458
 
459
+ <pre>
460
+ $ ./script/generate form Post --partial --controller admin/posts
461
+ exists app/views/admin/posts
462
+ create app/views/admin/posts/_form.html.erb
463
+ </pre>
436
464
 
437
- h2. Dependencies
438
465
 
439
- There are none, but...
466
+ h2. Custom Inputs
440
467
 
441
- * if you have the "ValidationReflection":http://github.com/redinger/validation_reflection plugin is installed, you won't have to specify the :required option (it checks the validations on the model instead)
442
- * if you want to use the :country input, you'll need to install the "iso-3166-country-select plugin":http://github.com/rails/iso-3166-country-select (or any other country_select plugin with the same API)
443
- * rspec, rspec_hpricot_matchers and rcov gems (plus any of their own dependencies) are required for the test suite
468
+ If you want to add your own input types to encapsulate your own logic or interface patterns, you can do so by subclassing SemanticFormBuilder and configuring Formtastic to use your custom builder class.
444
469
 
470
+ @Formtastic::SemanticFormHelper.builder = MyCustomBuilder@
445
471
 
446
- h2. Compatibility
447
472
 
448
- I'm only testing Formtastic with the latest Rails 2.2.x stable release, and it should be fine under Rails 2.3 as well (including nested forms). Patches are welcome to allow backwards compatibility, but I don't have the energy!
449
473
 
450
474
 
475
+ h2. Status
451
476
 
452
- h2. What about Stylesheets?
477
+ Formtastic has been in active development for about a year. We've just recently jumped to an 0.9 version number, signaling that we consider this a 1.0 release candidate, and that the API won't change significantly for the 1.x series.
453
478
 
454
- A proof-of-concept (very much a work-in-progress) stylesheet is provided which you can include in your layout. Customization is best achieved by overriding these styles in an additional stylesheet so that the Formtastic styles can be updated without clobbering your changes.
455
479
 
456
- 1. Use the generator to copy the formtastic.css and formtastic_changes.css into your public directory
480
+ h2. Dependencies
457
481
 
458
- <pre>
459
- ./script/generate formtastic_stylesheets
460
- </pre>
482
+ There are none, but...
461
483
 
462
- 2. Add both formtastic.css and formtastic_changes.css to your layout:
484
+ * if you have the "ValidationReflection":http://github.com/redinger/validation_reflection plugin is installed, you won't have to specify the @:required@ option (it checks the validations on the model instead).
485
+ * if you want to use the @:country@ input, you'll need to install the "iso-3166-country-select plugin":http://github.com/rails/iso-3166-country-select (or any other country_select plugin with the same API).
486
+ * "rspec":http://github.com/dchelimsky/rspec/, "rspec_hpricot_matchers":http://rubyforge.org/projects/rspec-hpricot/ and "rcov":http://github.com/relevance/rcov gems (plus any of their own dependencies) are required for the test suite.
463
487
 
464
- <pre>
465
- <%= stylesheet_link_tag "formtastic" %>
466
- <%= stylesheet_link_tag "formtastic_changes" %>
467
- </pre>
488
+
489
+ h2. Compatibility
490
+
491
+ I'm only testing Formtastic with the latest Rails 2.4.x stable release, and it should be fine under Rails 2.3.x as well (including nested forms). Patches are welcome to allow backwards compatibility, but I don't have the energy!
492
+
493
+ h2. Got TextMate?
494
+
495
+ Well...there's a TextMate-bundle in town, dedicated to make usage of Formtastic in the "TextMate":http://macromates.com/ editor even more of a breeze:
496
+
497
+ "Formtastic.tmbundle":http://github.com/grimen/formtastic_tmbundle
468
498
 
469
499
 
470
500
  h2. Contributors
471
501
 
472
- Formtastic is maintained by "Justin French":http://justinfrench.com and "José Valim":http://github.com/josevalim, but it wouldn't be as awesome as it is today if it weren't for the wonderful contributions of these fine, fine coders.
502
+ Formtastic is maintained by "Justin French":http://justinfrench.com, "José Valim":http://github.com/josevalim and "Jonas Grimfelt":http://github.com/grimen, but it wouldn't be as awesome as it is today without help from over 30 contributors.
473
503
 
474
- * "Jeff Smick":http://github.com/sprsquish
475
- * "Tien Dung":http://github.com/tiendung
476
- * "Mark Mansour":http://stateofflux.com
477
- * "Andy Pearson":http://github.com/andypearson
478
- * "negonicrac":http://github.com/negonicrac
479
- * "Xavier Shay":http://rhnh.net
480
- * "Pat Allan":http://github.com/freelancing-god
481
- * "Gareth Townsend":http://github.com/quamen
482
- * "Sascha Hoellger":http://github.com/mitnal
483
- * "Andrew Carpenter":http://github.com/andrewcarpenter
484
- * "Jack Dempsey":http://github.com/jackdempsey/
485
- * "Greg Fitzgerald":http://github.com/gregf/
486
- * "Hector E. Gomez Morales":http://github.com/hectoregm
487
- * "Ben Hamill":http://blog.benhamill.com/
488
- * "Simon Chiu":http://github.com/tolatomeow
489
- * "Bin Dong":http://github.com/dongbin
504
+ @git shortlog -n -s --no-merges@
490
505
 
491
506
 
492
- h2. Hey, join the Google group!
507
+ h2. Google Group
493
508
 
494
509
  Please join the "Formtastic Google Group":http://groups.google.com.au/group/formtastic, especially if you'd like to talk about a new feature, or report a bug.
495
510
 
496
511
 
497
512
  h2. Project Info
498
513
 
499
- Formtastic is hosted on Github: http://github.com/justinfrench/formtastic/, where your contributions, forkings, comments and feedback are greatly welcomed.
514
+ Formtastic is hosted on Github: "http://github.com/justinfrench/formtastic":http://github.com/justinfrench/formtastic, where your contributions, forkings, comments and feedback are greatly welcomed.
500
515
 
501
516
 
502
517
  Copyright (c) 2007-2008 Justin French, released under the MIT license.