justinfrench-formtastic 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.textile +58 -41
- data/lib/formtastic.rb +319 -257
- data/lib/locale/en.yml +1 -6
- data/spec/formtastic_spec.rb +984 -1166
- metadata +2 -2
data/README.textile
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
h1. Formtastic 0.1.
|
|
1
|
+
h1. Formtastic 0.1.3
|
|
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
|
|
|
@@ -25,9 +25,9 @@ One day, I finally had enough, so I opened up my text editor, and wrote a DSL fo
|
|
|
25
25
|
<%= form.input :url_title, :required => false %>
|
|
26
26
|
<% end %>
|
|
27
27
|
|
|
28
|
-
<% form.inputs :for => :author do |author_form| %>
|
|
29
|
-
<%=
|
|
30
|
-
<%=
|
|
28
|
+
<% form.inputs :name => "Author", :for => :author do |author_form| %>
|
|
29
|
+
<%= author_form.input :first_name %>
|
|
30
|
+
<%= author_form.input :last_name %>
|
|
31
31
|
<% end %>
|
|
32
32
|
|
|
33
33
|
<% form.buttons do %>
|
|
@@ -86,13 +86,13 @@ And then add it as a dependency in your environment.rb file:
|
|
|
86
86
|
config.gem "justinfrench-formtastic",
|
|
87
87
|
:lib => 'formtastic',
|
|
88
88
|
:source => 'http://gems.github.com',
|
|
89
|
-
:version => '0.1.
|
|
89
|
+
:version => '0.1.3'
|
|
90
90
|
</pre>
|
|
91
91
|
|
|
92
92
|
If you're a little more old school, install it as a plugin:
|
|
93
93
|
|
|
94
94
|
<pre>
|
|
95
|
-
./script/install
|
|
95
|
+
./script/plugin install git://github.com/justinfrench/formtastic.git
|
|
96
96
|
</pre>
|
|
97
97
|
|
|
98
98
|
|
|
@@ -156,30 +156,57 @@ If you want to customize the label text, or render some hint text below the fiel
|
|
|
156
156
|
<% end %>
|
|
157
157
|
</pre>
|
|
158
158
|
|
|
159
|
+
If you want to customize html elements for any non button inputs you just need
|
|
160
|
+
to specify the :input_html options hash.
|
|
161
|
+
|
|
162
|
+
<pre>
|
|
163
|
+
<% semantic_form_for @post do |form| %>
|
|
164
|
+
<%= form.input :title, :input_html => {:size => 60} %>
|
|
165
|
+
<%= form.input :body %>
|
|
166
|
+
<%= form.input :created_at, :input_html => {:disabled => true} %>
|
|
167
|
+
<%= form.buttons %>
|
|
168
|
+
<% end %>
|
|
169
|
+
</pre>
|
|
170
|
+
|
|
159
171
|
Nested forms (Rails 2.3) are also supported. You can do it in the Rails way:
|
|
160
172
|
|
|
161
173
|
<pre>
|
|
162
|
-
<% semantic_form_for @post do |
|
|
163
|
-
<%=
|
|
174
|
+
<% semantic_form_for @post do |form| %>
|
|
175
|
+
<%= form.inputs :title, :body, :created_at %>
|
|
164
176
|
|
|
165
|
-
|
|
166
|
-
<%= author.inputs :first_name, :last_name %>
|
|
167
|
-
|
|
177
|
+
<% form.semantic_fields_for :author do |author| %>
|
|
178
|
+
<%= author.inputs :first_name, :last_name, :name => 'Author' %>
|
|
179
|
+
<% end %>
|
|
168
180
|
|
|
169
|
-
<%=
|
|
181
|
+
<%= form.buttons %>
|
|
170
182
|
<% end %>
|
|
171
183
|
</pre>
|
|
172
184
|
|
|
173
185
|
Or in the formtastic way:
|
|
174
186
|
|
|
175
187
|
<pre>
|
|
176
|
-
<% semantic_form_for @post do |
|
|
177
|
-
<%=
|
|
178
|
-
|
|
179
|
-
<%=
|
|
188
|
+
<% semantic_form_for @post do |form| %>
|
|
189
|
+
<%= form.inputs :title, :body, :created_at %>
|
|
190
|
+
|
|
191
|
+
<%= form.inputs :first_name, :last_name, :for => :author, :name => "Author" %>
|
|
192
|
+
|
|
193
|
+
<%= form.buttons %>
|
|
194
|
+
<% end %>
|
|
195
|
+
</pre>
|
|
196
|
+
|
|
197
|
+
When working in has many association, you can even supply "%i" in your fieldset
|
|
198
|
+
name that it will be properly interpolated with the child index. For example:
|
|
199
|
+
|
|
200
|
+
<pre>
|
|
201
|
+
<% semantic_form_for @post do |form| %>
|
|
202
|
+
<%= form.inputs %>
|
|
203
|
+
<%= form.inputs :name => 'Category #%i', :for => :categories %>
|
|
204
|
+
<%= form.buttons %>
|
|
180
205
|
<% end %>
|
|
181
206
|
</pre>
|
|
182
207
|
|
|
208
|
+
Each category will be wrapped in a fieldset with legend "Category #1",
|
|
209
|
+
"Category #2" and so on. But please notice that this works only with Rails 2.3.
|
|
183
210
|
|
|
184
211
|
h2. The Available Inputs
|
|
185
212
|
|
|
@@ -226,9 +253,8 @@ If you wish, put something like this in config/initializers/formtastic_config.rb
|
|
|
226
253
|
# Defaults to :sentence, valid options are :sentence, :list and :none
|
|
227
254
|
Formtastic::SemanticFormBuilder.inline_errors = :list
|
|
228
255
|
|
|
229
|
-
# Set the method to call on label text to transform or format it for human-friendly
|
|
230
|
-
#
|
|
231
|
-
# but you might want to change for :titleize or another string method
|
|
256
|
+
# Set the method to call on label text to transform or format it for human-friendly
|
|
257
|
+
# reading when formtastic is user without object. Defaults to :humanize.
|
|
232
258
|
Formtastic::SemanticFormBuilder.label_str_method = :titleize
|
|
233
259
|
|
|
234
260
|
# Set the array of methods to try calling on parent objects in :select and :radio inputs
|
|
@@ -247,25 +273,7 @@ If you wish, put something like this in config/initializers/formtastic_config.rb
|
|
|
247
273
|
|
|
248
274
|
h2. Internationalization (I18n)
|
|
249
275
|
|
|
250
|
-
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.
|
|
251
|
-
|
|
252
|
-
Here is an example locale file:
|
|
253
|
-
|
|
254
|
-
<pre>
|
|
255
|
-
en:
|
|
256
|
-
formtastic:
|
|
257
|
-
yes: 'Yes'
|
|
258
|
-
no: 'No'
|
|
259
|
-
create: 'Create'
|
|
260
|
-
save: 'Save'
|
|
261
|
-
year: 'Year'
|
|
262
|
-
month: 'Month'
|
|
263
|
-
day: 'Day'
|
|
264
|
-
hour: 'Hour'
|
|
265
|
-
minute: 'Minute'
|
|
266
|
-
second: 'Second'
|
|
267
|
-
required: 'required'
|
|
268
|
-
</pre>
|
|
276
|
+
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.
|
|
269
277
|
|
|
270
278
|
|
|
271
279
|
h2. ValidationReflection plugin
|
|
@@ -316,7 +324,9 @@ A proof-of-concept (very much a work-in-progress) stylesheet is provided which y
|
|
|
316
324
|
</pre>
|
|
317
325
|
|
|
318
326
|
|
|
319
|
-
h2.
|
|
327
|
+
h2. Contributors
|
|
328
|
+
|
|
329
|
+
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.
|
|
320
330
|
|
|
321
331
|
* "Justin French":http://justinfrench.com
|
|
322
332
|
* "Xavier Shay":http://rhnh.net
|
|
@@ -330,13 +340,20 @@ h2. Many thanks to Formtastic's contributors
|
|
|
330
340
|
* "Sascha Hoellger":http://github.com/mitnal
|
|
331
341
|
* "Jeff Smick":http://github.com/sprsquish
|
|
332
342
|
* "José Valim":http://github.com/josevalim
|
|
343
|
+
* "Greg Fitzgerald":http://github.com/gregf/
|
|
344
|
+
* "Gareth Townsend":http://github.com/quamen
|
|
345
|
+
* "Jack Dempsey":http://github.com/jackdempsey/
|
|
346
|
+
* "Simon Chiu":http://github.com/tolatomeow
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
h2. Hey, join the Google group!
|
|
350
|
+
|
|
351
|
+
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.
|
|
333
352
|
|
|
334
353
|
|
|
335
354
|
h2. Project Info
|
|
336
355
|
|
|
337
356
|
Formtastic is hosted on Github: http://github.com/justinfrench/formtastic/, where your contributions, forkings, comments and feedback are greatly welcomed.
|
|
338
357
|
|
|
339
|
-
There's also a newly created "Formtastic Google Group":http://groups.google.com.au/group/formtastic.
|
|
340
|
-
|
|
341
358
|
|
|
342
359
|
Copyright (c) 2007-2008 Justin French, released under the MIT license.
|