ShadowBelmolve-formtastic 0.1.6 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -1,7 +1,10 @@
1
- h1. Formtastic 0.1.3
1
+ 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
+
5
8
  h2. The Story
6
9
 
7
10
  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:
@@ -72,6 +75,11 @@ h2. Opinions
72
75
  * make the common things we do easy, yet still ensure uncommon things are still possible
73
76
 
74
77
 
78
+ h2. Documentation
79
+
80
+ RDoc documentation _should_ be automatically generated after each commit and made available on the "rdoc.info website":http://rdoc.info/projects/justinfrench/formtastic.
81
+
82
+
75
83
  h2. Installation
76
84
 
77
85
  You can (and should) get it as a gem:
@@ -91,7 +99,7 @@ And then add it as a dependency in your environment.rb file:
91
99
  If you're a little more old school, install it as a plugin:
92
100
 
93
101
  <pre>
94
- ./script/plugin install git://github.com/ShadowBelmolve/formtastic.git
102
+ ./script/plugin install git://github.com/justinfrench/formtastic.git
95
103
  </pre>
96
104
 
97
105
 
@@ -155,48 +163,30 @@ If you want to customize the label text, or render some hint text below the fiel
155
163
  <% end %>
156
164
  </pre>
157
165
 
158
- If you want to customize html elements for any non button inputs you just need
159
- to specify the :input_html options hash.
160
-
161
- <pre>
162
- <% semantic_form_for @post do |form| %>
163
- <%= form.input :title, :input_html => {:size => 60} %>
164
- <%= form.input :body %>
165
- <%= form.input :created_at, :input_html => {:disabled => true} %>
166
- <%= form.buttons %>
167
- <% end %>
168
- </pre>
169
-
170
- To customize buttons, :button_html is available.
171
166
 
172
167
  Nested forms (Rails 2.3) are also supported. You can do it in the Rails way:
173
168
 
174
169
  <pre>
175
170
  <% semantic_form_for @post do |form| %>
176
171
  <%= form.inputs :title, :body, :created_at %>
177
-
178
172
  <% form.semantic_fields_for :author do |author| %>
179
173
  <%= author.inputs :first_name, :last_name, :name => 'Author' %>
180
174
  <% end %>
181
-
182
175
  <%= form.buttons %>
183
176
  <% end %>
184
177
  </pre>
185
178
 
186
- Or in the formtastic way:
179
+ Or the Formtastic way with the @:for@ option:
187
180
 
188
181
  <pre>
189
182
  <% semantic_form_for @post do |form| %>
190
183
  <%= form.inputs :title, :body, :created_at %>
191
-
192
184
  <%= form.inputs :first_name, :last_name, :for => :author, :name => "Author" %>
193
-
194
185
  <%= form.buttons %>
195
186
  <% end %>
196
187
  </pre>
197
188
 
198
- When working in has many association, you can even supply "%i" in your fieldset
199
- name that it will be properly interpolated with the child index. For example:
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:
200
190
 
201
191
  <pre>
202
192
  <% semantic_form_for @post do |form| %>
@@ -206,27 +196,180 @@ name that it will be properly interpolated with the child index. For example:
206
196
  <% end %>
207
197
  </pre>
208
198
 
209
- Each category will be wrapped in a fieldset with legend "Category #1",
210
- "Category #2" and so on. But please notice that this works only with Rails 2.3.
199
+
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
+
202
+ <pre>
203
+ <% semantic_form_for @post do |form| %>
204
+ <%= form.input :title, :input_html => { :size => 60 } %>
205
+ <%= form.input :body, :input_html => { :class => 'autogrow' } %>
206
+ <%= form.input :created_at, :input_html => { :disabled => true } %>
207
+ <%= form.buttons %>
208
+ <% end %>
209
+ </pre>
210
+
211
+ The same can be done for buttons with the @:button_html@ option:
212
+
213
+ <pre>
214
+ <% semantic_form_for @post do |form| %>
215
+ ...
216
+ <% form.buttons do %>
217
+ <%= form.commit_button :button_html => { :class => "primary" } %>
218
+ <% end %>
219
+ <% end %>
220
+ </pre>
221
+
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
+
224
+ <pre>
225
+ <% semantic_form_for @post do |form| %>
226
+ <%= form.input :title, :wrapper_html => { :class => "important" } %>
227
+ <%= form.input :body %>
228
+ <%= form.input :description, :wrapper_html => { :style => "display:none;" } %>
229
+ ...
230
+ <% end %>
231
+ </pre>
232
+
233
+
211
234
 
212
235
  h2. The Available Inputs
213
236
 
214
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
215
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
216
241
  * :password (a password input) - default for :string column types with 'password' in the method name
217
242
  * :text (a textarea) - default for :text column types
218
243
  * :date (a date select) - default for :date column types
219
244
  * :datetime (a date and time select) - default for :datetime and :timestamp column types
220
245
  * :time (a time select) - default for :time column types
221
246
  * :boolean (a checkbox) - default for :boolean column types
222
- * :boolean_select (a yes/no select box)
223
247
  * :string (a text field) - default for :string column types
224
248
  * :numeric (a text field, like string) - default for :integer, :float and :decimal column types
225
249
  * :file (a file field) - default for paperclip or attachment_fu attributes
226
- * :check_boxes - alternative to :select when a model has_many :through other
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
+
227
253
 
228
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.
229
255
 
256
+ h2. Internationalization (I18n)
257
+
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
+
260
+ h3. Label/Hint-localization
261
+
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):
265
+
266
+ <pre>
267
+ <% semantic_form_for @post do |form| %>
268
+ <%= form.input :title %> # => :label => I18n.t('activerecord.attributes.user.title') or 'Title'
269
+ <%= form.input :body %> # => :label => I18n.t('activerecord.attributes.user.body') or 'Body'
270
+ <%= form.input :section %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
271
+ <% end %>
272
+ </pre>
273
+
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?
275
+
276
+ Enhanced localization (labels and hints):
277
+
278
+ 1. Enable I18n lookups by default (@config/initializers/formtastic.rb@):
279
+
280
+ <pre>
281
+ Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
282
+ </pre>
283
+
284
+ 2. Add some cool label-translations/variants (@config/locale/en.yml@):
285
+
286
+ <pre>
287
+ en:
288
+ formtastic:
289
+ labels:
290
+ post:
291
+ title: "Choose a title..."
292
+ body: "Write something..."
293
+ hints:
294
+ post:
295
+ title: "Choose a good title for you post."
296
+ body: "Write something inspiring here."
297
+ </pre>
298
+
299
+ *Note:* We are using English here still, but you get the point.
300
+
301
+ 3. ...and now you'll get:
302
+
303
+ <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'
308
+ <% end %>
309
+ </pre>
310
+
311
+ 4. Override I18n settings:
312
+
313
+ <pre>
314
+ <% 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'
318
+ <% end %>
319
+ </pre>
320
+
321
+ If I18n-lookups is disabled, i.e.:
322
+
323
+ <pre>
324
+ Formtastic::SemanticFormBuilder.i18n_lookups_by_default = false
325
+ </pre>
326
+
327
+ ...then you can enable I18n within the forms instead:
328
+
329
+ <pre>
330
+ <% 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'
334
+ <% end %>
335
+ </pre>
336
+
337
+ 5. Advanced I18n lookups
338
+
339
+ For more flexible forms; Formtastic find translations using a bottom-up approach taking the following variables in account:
340
+
341
+ * @model@, e.g. "post"
342
+ * @action@, e.g. "edit"
343
+ * @attribute@, e.g. "title"
344
+
345
+ ...in the following order:
346
+
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
350
+
351
+ ...which means that you can define translations like this:
352
+
353
+ <pre>
354
+ en:
355
+ formtastic:
356
+ labels:
357
+ title: "Title" # Default global value
358
+ article:
359
+ body: "Article content"
360
+ post:
361
+ new:
362
+ title: "Choose a title..."
363
+ body: "Write something..."
364
+ edit:
365
+ title: "Edit title"
366
+ body: "Edit body"
367
+ ...
368
+ </pre>
369
+
370
+ h2. ValidationReflection plugin
371
+
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).
230
373
 
231
374
  h2. Configuration
232
375
 
@@ -270,19 +413,16 @@ If you wish, put something like this in config/initializers/formtastic_config.rb
270
413
  # the input, in the following order: hints, input and errors. You can
271
414
  # customize it doing just as below:
272
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
273
424
  </pre>
274
425
 
275
-
276
- h2. Internationalization (I18n)
277
-
278
- Supports I18n! 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.
279
-
280
-
281
- h2. ValidationReflection plugin
282
-
283
- 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).
284
-
285
-
286
426
  h2. Status
287
427
 
288
428
  *THINGS ARE GOING TO CHANGE A BIT BEFORE WE HIT 1.0.*
@@ -299,6 +439,7 @@ h2. Dependencies
299
439
  There are none, but...
300
440
 
301
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)
302
443
  * rspec, rspec_hpricot_matchers and rcov gems (plus any of their own dependencies) are required for the test suite
303
444
 
304
445
 
@@ -328,10 +469,8 @@ A proof-of-concept (very much a work-in-progress) stylesheet is provided which y
328
469
 
329
470
  h2. Contributors
330
471
 
331
- Formtastic wouldn't be as awesome as it is today if it weren't for the wonderful contributions of these fine, fine coders. An extra huge thanks goes out to "José Valim":http://github.com/josevalim for nearly 50 patches.
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.
332
473
 
333
- * "Justin French":http://justinfrench.com
334
- * "José Valim":http://github.com/josevalim
335
474
  * "Jeff Smick":http://github.com/sprsquish
336
475
  * "Tien Dung":http://github.com/tiendung
337
476
  * "Mark Mansour":http://stateofflux.com
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ begin
20
20
 
21
21
  s.require_path = 'lib'
22
22
  s.autorequire = GEM
23
- s.files = %w(MIT-LICENSE README.textile Rakefile) + Dir.glob("{rails,lib,spec}/**/*")
23
+ s.files = %w(MIT-LICENSE README.textile Rakefile) + Dir.glob("{rails,lib,generators,spec}/**/*")
24
24
  end
25
25
  rescue LoadError
26
26
  puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
@@ -0,0 +1,21 @@
1
+ class FormtasticStylesheetsGenerator < Rails::Generator::Base
2
+
3
+ def initialize(*runtime_args)
4
+ super
5
+ end
6
+
7
+ def manifest
8
+ record do |m|
9
+ m.directory File.join('public', 'stylesheets')
10
+ m.template 'formtastic.css', File.join('public', 'stylesheets', 'formtastic.css')
11
+ m.template 'formtastic_changes.css', File.join('public', 'stylesheets', 'formtastic_changes.css')
12
+ end
13
+ end
14
+
15
+ protected
16
+
17
+ def banner
18
+ %{Usage: #{$0} #{spec.name}\nCopies formtastic.css and formtastic_changes.css to public/}
19
+ end
20
+
21
+ end
@@ -0,0 +1,136 @@
1
+ /* -------------------------------------------------------------------------------------------------
2
+
3
+ It's *strongly* suggested that you don't modify this file. Instead, load a new stylesheet after
4
+ this one in your layouts (eg formtastic_changes.css) and override the styles to suit your needs.
5
+ This will allow you to update formtastic.css with new releases without clobbering your own changes.
6
+
7
+ This stylesheet forms part of the Formtastic Rails Plugin
8
+ (c) 2008 Justin French
9
+
10
+ --------------------------------------------------------------------------------------------------*/
11
+
12
+
13
+ /* NORMALIZE AND RESET - obviously inspired by Yahoo's reset.css, but scoped to just form.formtastic
14
+ --------------------------------------------------------------------------------------------------*/
15
+ form.formtastic, form.formtastic ul, form.formtastic ol, form.formtastic li, form.formtastic fieldset, form.formtastic legend, form.formtastic input, form.formtastic textarea, form.formtastic select, form.formtastic p { margin:0; padding:0; }
16
+ form.formtastic fieldset { border:0; }
17
+ form.formtastic em, form.formtastic strong { font-style:normal; font-weight:normal; }
18
+ form.formtastic ol, form.formtastic ul { list-style:none; }
19
+ form.formtastic abbr, form.formtastic acronym { border:0; font-variant:normal; }
20
+ form.formtastic input, form.formtastic textarea, form.formtastic select { font-family:inherit; font-size:inherit; font-weight:inherit; }
21
+ form.formtastic input, form.formtastic textarea, form.formtastic select { font-size:100%; }
22
+ form.formtastic legend { color:#000; }
23
+
24
+
25
+ /* FIELDSETS & LISTS
26
+ --------------------------------------------------------------------------------------------------*/
27
+ form.formtastic fieldset { }
28
+ form.formtastic fieldset.inputs { }
29
+ form.formtastic fieldset.buttons { padding-left:25%; }
30
+ form.formtastic fieldset ol { }
31
+ form.formtastic fieldset.buttons li { float:left; padding-right:0.5em; }
32
+
33
+ /* clearfixing the fieldsets */
34
+ form.formtastic fieldset { display: inline-block; }
35
+ form.formtastic fieldset:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
36
+ html[xmlns] form.formtastic fieldset { display: block; }
37
+ * html form.formtastic fieldset { height: 1%; }
38
+
39
+
40
+ /* INPUT LIs
41
+ --------------------------------------------------------------------------------------------------*/
42
+ form.formtastic fieldset ol li { margin-bottom:1.5em; }
43
+
44
+ /* clearfixing the li's */
45
+ form.formtastic fieldset ol li { display: inline-block; }
46
+ form.formtastic fieldset ol li:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
47
+ html[xmlns] form.formtastic fieldset ol li { display: block; }
48
+ * html form.formtastic fieldset ol li { height: 1%; }
49
+
50
+ form.formtastic fieldset ol li.required { }
51
+ form.formtastic fieldset ol li.optional { }
52
+ form.formtastic fieldset ol li.error { }
53
+
54
+
55
+ /* LABELS
56
+ --------------------------------------------------------------------------------------------------*/
57
+ form.formtastic fieldset ol li label { display:block; width:25%; float:left; padding-top:.2em; }
58
+ form.formtastic fieldset ol li li label { line-height:100%; padding-top:0; }
59
+ form.formtastic fieldset ol li li label input { line-height:100%; vertical-align:middle; margin-top:-0.1em;}
60
+
61
+
62
+ /* NESTED FIELDSETS AND LEGENDS (radio, check boxes and date/time inputs use nested fieldsets)
63
+ --------------------------------------------------------------------------------------------------*/
64
+ form.formtastic fieldset ol li fieldset { position:relative; }
65
+ form.formtastic fieldset ol li fieldset legend { position:absolute; width:25%; padding-top:0.1em; }
66
+ form.formtastic fieldset ol li fieldset legend span { position:absolute; }
67
+ form.formtastic fieldset ol li fieldset ol { float:left; width:74%; margin:0; padding:0 0 0 25%; }
68
+ form.formtastic fieldset ol li fieldset ol li { padding:0; border:0; }
69
+
70
+
71
+ /* INLINE HINTS
72
+ --------------------------------------------------------------------------------------------------*/
73
+ form.formtastic fieldset ol li p.inline-hints { color:#666; margin:0.5em 0 0 25%; }
74
+
75
+
76
+ /* INLINE ERRORS
77
+ --------------------------------------------------------------------------------------------------*/
78
+ form.formtastic fieldset ol li p.inline-errors { color:#cc0000; margin:0.5em 0 0 25%; }
79
+ form.formtastic fieldset ol li ul.errors { color:#cc0000; margin:0.5em 0 0 25%; list-style:square; }
80
+ form.formtastic fieldset ol li ul.errors li { padding:0; border:none; display:list-item; }
81
+
82
+
83
+ /* STRING & NUMERIC OVERRIDES
84
+ --------------------------------------------------------------------------------------------------*/
85
+ form.formtastic fieldset ol li.string input { width:74%; }
86
+ form.formtastic fieldset ol li.numeric input { width:74%; }
87
+
88
+
89
+ /* TEXTAREA OVERRIDES
90
+ --------------------------------------------------------------------------------------------------*/
91
+ form.formtastic fieldset ol li.text textarea { width:74%; }
92
+
93
+
94
+ /* HIDDEN OVERRIDES
95
+ --------------------------------------------------------------------------------------------------*/
96
+ form.formtastic fieldset ol li.hidden { display:none; }
97
+
98
+
99
+ /* BOOLEAN OVERRIDES
100
+ --------------------------------------------------------------------------------------------------*/
101
+ form.formtastic fieldset ol li.boolean label { padding-left:25%; width:auto; }
102
+ form.formtastic fieldset ol li.boolean label input { margin:0 0.5em 0 0.2em; }
103
+
104
+
105
+ /* RADIO OVERRIDES
106
+ --------------------------------------------------------------------------------------------------*/
107
+ form.formtastic fieldset ol li.radio { }
108
+ form.formtastic fieldset ol li.radio fieldset ol { margin-bottom:-0.6em; }
109
+ form.formtastic fieldset ol li.radio fieldset ol li { margin:0.1em 0 0.5em 0; }
110
+ form.formtastic fieldset ol li.radio fieldset ol li label { float:none; width:100%; }
111
+ form.formtastic fieldset ol li.radio fieldset ol li label input { margin-right:0.2em; }
112
+
113
+
114
+ /* CHECK BOXES (COLLECTION) OVERRIDES
115
+ --------------------------------------------------------------------------------------------------*/
116
+ form.formtastic fieldset ol li.check_boxes { }
117
+ form.formtastic fieldset ol li.check_boxes fieldset ol { margin-bottom:-0.6em; }
118
+ form.formtastic fieldset ol li.check_boxes fieldset ol li { margin:0.1em 0 0.5em 0; }
119
+ form.formtastic fieldset ol li.check_boxes fieldset ol li label { float:none; width:100%; }
120
+ form.formtastic fieldset ol li.check_boxes fieldset ol li label input { margin-right:0.2em; }
121
+
122
+
123
+
124
+ /* DATE & TIME OVERRIDES
125
+ --------------------------------------------------------------------------------------------------*/
126
+ form.formtastic fieldset ol li.date fieldset ol li,
127
+ form.formtastic fieldset ol li.time fieldset ol li,
128
+ form.formtastic fieldset ol li.datetime fieldset ol li { float:left; width:auto; margin:0 .3em 0 0; }
129
+
130
+ form.formtastic fieldset ol li.date fieldset ol li label,
131
+ form.formtastic fieldset ol li.time fieldset ol li label,
132
+ form.formtastic fieldset ol li.datetime fieldset ol li label { display:none; }
133
+
134
+ form.formtastic fieldset ol li.date fieldset ol li label input,
135
+ form.formtastic fieldset ol li.time fieldset ol li label input,
136
+ form.formtastic fieldset ol li.datetime fieldset ol li label input { display:inline; margin:0; padding:0; }