formtastic 1.2.0.beta → 1.2.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +48 -3
- data/lib/formtastic/i18n.rb +1 -7
- data/lib/formtastic.rb +8 -2
- data/lib/locale/en.yml +3 -4
- metadata +19 -3
data/README.textile
CHANGED
@@ -115,6 +115,30 @@ A proof-of-concept stylesheet is provided which you can include in your layout.
|
|
115
115
|
</pre>
|
116
116
|
|
117
117
|
|
118
|
+
h2. Syntax
|
119
|
+
|
120
|
+
*Please note:* Formtastic makes use of a lot of ERB blocks and currently supports both Rails 2 and Rails 3, which means the syntax in these examples will differ depending on which version of Rails you're using.
|
121
|
+
|
122
|
+
The difference is subtle, with most blocks in Rails 3 requiring the addition of an equals sign:
|
123
|
+
|
124
|
+
<pre>
|
125
|
+
<!-- Rails 2 -->
|
126
|
+
<% semantic_form_for @user do |form| %>
|
127
|
+
<% form.inputs do %>
|
128
|
+
...
|
129
|
+
<% end %>
|
130
|
+
<% end %>
|
131
|
+
|
132
|
+
<!-- Rails 3 -->
|
133
|
+
<%= semantic_form_for @user do |form| %>
|
134
|
+
<%= form.inputs do %>
|
135
|
+
...
|
136
|
+
<% end %>
|
137
|
+
<% end %>
|
138
|
+
|
139
|
+
This README is currently documenting the Rails 2 way only. If you're using Rails 3 and your forms aren't rendering everything as expected, try changing @<%@ to @<%=@.
|
140
|
+
|
141
|
+
|
118
142
|
h2. Usage
|
119
143
|
|
120
144
|
Forms are really boring to code... you want to get onto the good stuff as fast as possible.
|
@@ -128,7 +152,9 @@ This renders a set of inputs (one for _most_ columns in the database table, and
|
|
128
152
|
<% end %>
|
129
153
|
</pre>
|
130
154
|
|
131
|
-
|
155
|
+
This is a great way to get something up fast, but like scaffolding, it's not recommended for production.
|
156
|
+
|
157
|
+
You probably want to specify the order of the fields, skip some of the fields or even add in fields that Formtastic couldn't detect, you can pass in a list of field names to @inputs@ and list of button names to @buttons@:
|
132
158
|
|
133
159
|
<pre>
|
134
160
|
<% semantic_form_for @user do |form| %>
|
@@ -137,7 +163,7 @@ If you want to specify the order of the fields, skip some of the fields or even
|
|
137
163
|
<% end %>
|
138
164
|
</pre>
|
139
165
|
|
140
|
-
|
166
|
+
You probably 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):
|
141
167
|
|
142
168
|
<pre>
|
143
169
|
<% semantic_form_for @post do |form| %>
|
@@ -428,7 +454,7 @@ If I18n-lookups is disabled, i.e.:
|
|
428
454
|
<%= form.input :section, :label => true %> # => :label => I18n.t('activerecord.attributes.user.section') or 'Section'
|
429
455
|
<% end %>
|
430
456
|
<% form.buttons do %>
|
431
|
-
<%= form.commit_button true %> # => "
|
457
|
+
<%= form.commit_button true %> # => "Update %{model}" (if we are in edit that is...)
|
432
458
|
<% end %>
|
433
459
|
<% end %>
|
434
460
|
</pre>
|
@@ -558,6 +584,25 @@ If you want to add your own input types to encapsulate your own logic or interfa
|
|
558
584
|
|
559
585
|
@Formtastic::SemanticFormHelper.builder = MyCustomBuilder@
|
560
586
|
|
587
|
+
Be aware that you should either set the options on custom builder or require it after setting options on formtastic default builder.
|
588
|
+
|
589
|
+
<pre>
|
590
|
+
# OK
|
591
|
+
Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
|
592
|
+
require 'formtastic/my_custom_builder'
|
593
|
+
Formtastic::SemanticFormHelper.builder = Formtastic::MyCustomBuilder
|
594
|
+
|
595
|
+
# OK
|
596
|
+
require 'formtastic/my_custom_builder'
|
597
|
+
Formtastic::SemanticFormHelper.builder = Formtastic::MyCustomBuilder
|
598
|
+
Formtastic::MyCustomBuilder.i18n_lookups_by_default = true
|
599
|
+
|
600
|
+
# WRONG!
|
601
|
+
require 'formtastic/my_custom_builder'
|
602
|
+
Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
|
603
|
+
Formtastic::SemanticFormHelper.builder = Formtastic::MyCustomBuilder
|
604
|
+
</pre>
|
605
|
+
|
561
606
|
|
562
607
|
h2. Security
|
563
608
|
|
data/lib/formtastic/i18n.rb
CHANGED
@@ -4,13 +4,7 @@ module Formtastic
|
|
4
4
|
module I18n
|
5
5
|
|
6
6
|
DEFAULT_SCOPE = [:formtastic].freeze
|
7
|
-
DEFAULT_VALUES =
|
8
|
-
:required => 'required',
|
9
|
-
:yes => 'Yes',
|
10
|
-
:no => 'No',
|
11
|
-
:create => 'Create %{model}',
|
12
|
-
:update => 'Update %{model}'
|
13
|
-
}.freeze
|
7
|
+
DEFAULT_VALUES = YAML.load_file(File.expand_path("../../locale/en.yml", __FILE__))["en"]["formtastic"].freeze
|
14
8
|
SCOPES = [
|
15
9
|
'%{model}.%{nested_model}.%{action}.%{attribute}',
|
16
10
|
'%{model}.%{action}.%{attribute}',
|
data/lib/formtastic.rb
CHANGED
@@ -340,7 +340,9 @@ module Formtastic #:nodoc:
|
|
340
340
|
#
|
341
341
|
def commit_button(*args)
|
342
342
|
options = args.extract_options!
|
343
|
+
::ActiveSupport::Deprecation.warn(":class => 'whatever' is deprecated on commit button, use :wrapper_html => { :class => 'whatever' } instead.", caller) if options.key?(:class)
|
343
344
|
text = options.delete(:label) || args.shift
|
345
|
+
|
344
346
|
|
345
347
|
if @object && (@object.respond_to?(:persisted?) || @object.respond_to?(:new_record?))
|
346
348
|
if @object.respond_to?(:persisted?) # ActiveModel
|
@@ -371,10 +373,14 @@ module Formtastic #:nodoc:
|
|
371
373
|
|
372
374
|
button_html = options.delete(:button_html) || {}
|
373
375
|
button_html.merge!(:class => [button_html[:class], key].compact.join(' '))
|
374
|
-
|
376
|
+
|
377
|
+
wrapper_html_class = ['commit', options.delete(:class)].compact # TODO: Add class reflecting on form action.
|
378
|
+
wrapper_html = options.delete(:wrapper_html) || {}
|
379
|
+
wrapper_html[:class] = (wrapper_html_class << wrapper_html[:class] << button_html[:class]).flatten.compact.join(' ')
|
380
|
+
|
375
381
|
accesskey = (options.delete(:accesskey) || self.class.default_commit_button_accesskey) unless button_html.has_key?(:accesskey)
|
376
382
|
button_html = button_html.merge(:accesskey => accesskey) if accesskey
|
377
|
-
template.content_tag(:li, Formtastic::Util.html_safe(self.submit(text, button_html)),
|
383
|
+
template.content_tag(:li, Formtastic::Util.html_safe(self.submit(text, button_html)), wrapper_html)
|
378
384
|
end
|
379
385
|
|
380
386
|
# A thin wrapper around #fields_for to set :builder => Formtastic::SemanticFormBuilder
|
data/lib/locale/en.yml
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formtastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: -1848230070
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
9
|
- 0
|
10
|
-
-
|
11
|
-
version: 1.2.0.
|
10
|
+
- beta2
|
11
|
+
version: 1.2.0.beta2
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Justin French
|
@@ -115,6 +115,22 @@ dependencies:
|
|
115
115
|
version: 1.0.0
|
116
116
|
type: :development
|
117
117
|
version_requirements: *id006
|
118
|
+
- !ruby/object:Gem::Dependency
|
119
|
+
name: hpricot
|
120
|
+
prerelease: false
|
121
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ~>
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
hash: 57
|
127
|
+
segments:
|
128
|
+
- 0
|
129
|
+
- 8
|
130
|
+
- 3
|
131
|
+
version: 0.8.3
|
132
|
+
type: :development
|
133
|
+
version_requirements: *id007
|
118
134
|
description: A Rails form builder plugin/gem with semantically rich and accessible markup
|
119
135
|
email: justin@indent.com.au
|
120
136
|
executables: []
|