formtastic 1.2.5 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.yardopts +1 -0
- data/CHANGELOG +279 -0
- data/Gemfile +3 -0
- data/README.textile +155 -172
- data/RELEASE_PROCESS +7 -0
- data/Rakefile +52 -0
- data/app/assets/stylesheets/formtastic.css +275 -0
- data/app/assets/stylesheets/formtastic_ie6.css +27 -0
- data/app/assets/stylesheets/formtastic_ie7.css +17 -0
- data/formtastic.gemspec +51 -0
- data/lib/formtastic.rb +21 -1960
- data/lib/formtastic/engine.rb +7 -0
- data/lib/formtastic/form_builder.rb +83 -0
- data/lib/formtastic/helpers.rb +16 -0
- data/lib/formtastic/helpers/buttons_helper.rb +277 -0
- data/lib/formtastic/helpers/errors_helper.rb +113 -0
- data/lib/formtastic/helpers/fieldset_wrapper.rb +75 -0
- data/lib/formtastic/helpers/file_column_detection.rb +16 -0
- data/lib/formtastic/helpers/form_helper.rb +198 -0
- data/lib/formtastic/helpers/input_helper.rb +366 -0
- data/lib/formtastic/helpers/inputs_helper.rb +392 -0
- data/lib/formtastic/helpers/reflection.rb +33 -0
- data/lib/formtastic/helpers/semantic_form_helper.rb +11 -0
- data/lib/formtastic/html_attributes.rb +21 -0
- data/lib/formtastic/i18n.rb +1 -0
- data/lib/formtastic/inputs.rb +31 -0
- data/lib/formtastic/inputs/base.rb +61 -0
- data/lib/formtastic/inputs/base/associations.rb +31 -0
- data/lib/formtastic/inputs/base/choices.rb +103 -0
- data/lib/formtastic/inputs/base/collections.rb +94 -0
- data/lib/formtastic/inputs/base/database.rb +17 -0
- data/lib/formtastic/inputs/base/errors.rb +58 -0
- data/lib/formtastic/inputs/base/fileish.rb +23 -0
- data/lib/formtastic/inputs/base/grouped_collections.rb +77 -0
- data/lib/formtastic/inputs/base/hints.rb +31 -0
- data/lib/formtastic/inputs/base/html.rb +52 -0
- data/lib/formtastic/inputs/base/labelling.rb +55 -0
- data/lib/formtastic/inputs/base/naming.rb +42 -0
- data/lib/formtastic/inputs/base/options.rb +18 -0
- data/lib/formtastic/inputs/base/stringish.rb +35 -0
- data/lib/formtastic/inputs/base/timeish.rb +128 -0
- data/lib/formtastic/inputs/base/validations.rb +166 -0
- data/lib/formtastic/inputs/base/wrapping.rb +40 -0
- data/lib/formtastic/inputs/boolean_input.rb +96 -0
- data/lib/formtastic/inputs/check_boxes_input.rb +179 -0
- data/lib/formtastic/inputs/country_input.rb +66 -0
- data/lib/formtastic/inputs/date_input.rb +14 -0
- data/lib/formtastic/inputs/datetime_input.rb +9 -0
- data/lib/formtastic/inputs/email_input.rb +40 -0
- data/lib/formtastic/inputs/file_input.rb +42 -0
- data/lib/formtastic/inputs/hidden_input.rb +66 -0
- data/lib/formtastic/inputs/number_input.rb +118 -0
- data/lib/formtastic/inputs/numeric_input.rb +21 -0
- data/lib/formtastic/inputs/password_input.rb +40 -0
- data/lib/formtastic/inputs/phone_input.rb +41 -0
- data/lib/formtastic/inputs/radio_input.rb +157 -0
- data/lib/formtastic/inputs/range_input.rb +119 -0
- data/lib/formtastic/inputs/search_input.rb +40 -0
- data/lib/formtastic/inputs/select_input.rb +210 -0
- data/lib/formtastic/inputs/string_input.rb +34 -0
- data/lib/formtastic/inputs/text_input.rb +47 -0
- data/lib/formtastic/inputs/time_input.rb +14 -0
- data/lib/formtastic/inputs/time_zone_input.rb +48 -0
- data/lib/formtastic/inputs/url_input.rb +40 -0
- data/lib/formtastic/localized_string.rb +105 -0
- data/lib/formtastic/railtie.rb +5 -7
- data/lib/formtastic/semantic_form_builder.rb +11 -0
- data/lib/formtastic/util.rb +6 -19
- data/lib/formtastic/version.rb +3 -0
- data/lib/generators/formtastic/install/install_generator.rb +28 -6
- data/lib/generators/templates/_form.html.erb +10 -4
- data/lib/generators/templates/_form.html.haml +8 -4
- data/lib/generators/templates/formtastic.rb +25 -32
- data/lib/locale/en.yml +1 -0
- data/lib/tasks/verify_rcov.rb +44 -0
- data/sample/basic_inputs.html +182 -0
- data/sample/config.ru +69 -0
- data/sample/index.html +14 -0
- data/spec/builder/custom_builder_spec.rb +109 -0
- data/spec/builder/error_proc_spec.rb +27 -0
- data/spec/builder/errors_spec.rb +193 -0
- data/spec/builder/semantic_fields_for_spec.rb +88 -0
- data/spec/helpers/buttons_helper_spec.rb +150 -0
- data/spec/helpers/commit_button_helper_spec.rb +470 -0
- data/spec/helpers/form_helper_spec.rb +135 -0
- data/spec/helpers/input_helper_spec.rb +837 -0
- data/spec/helpers/inputs_helper_spec.rb +562 -0
- data/spec/helpers/semantic_errors_helper_spec.rb +112 -0
- data/spec/i18n_spec.rb +199 -0
- data/spec/inputs/boolean_input_spec.rb +184 -0
- data/spec/inputs/check_boxes_input_spec.rb +375 -0
- data/spec/inputs/country_input_spec.rb +133 -0
- data/spec/inputs/custom_input_spec.rb +52 -0
- data/spec/inputs/date_input_spec.rb +110 -0
- data/spec/inputs/datetime_input_spec.rb +115 -0
- data/spec/inputs/email_input_spec.rb +55 -0
- data/spec/inputs/file_input_spec.rb +59 -0
- data/spec/inputs/hidden_input_spec.rb +120 -0
- data/spec/inputs/include_blank_spec.rb +70 -0
- data/spec/inputs/label_spec.rb +104 -0
- data/spec/inputs/number_input_spec.rb +487 -0
- data/spec/inputs/numeric_input_spec.rb +41 -0
- data/spec/inputs/password_input_spec.rb +69 -0
- data/spec/inputs/phone_input_spec.rb +55 -0
- data/spec/inputs/placeholder_spec.rb +71 -0
- data/spec/inputs/radio_input_spec.rb +234 -0
- data/spec/inputs/range_input_spec.rb +477 -0
- data/spec/inputs/search_input_spec.rb +55 -0
- data/spec/inputs/select_input_spec.rb +545 -0
- data/spec/inputs/string_input_spec.rb +163 -0
- data/spec/inputs/text_input_spec.rb +158 -0
- data/spec/inputs/time_input_spec.rb +155 -0
- data/spec/inputs/time_zone_input_spec.rb +87 -0
- data/spec/inputs/url_input_spec.rb +55 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +361 -0
- data/spec/support/custom_macros.rb +656 -0
- data/spec/support/deferred_garbage_collection.rb +21 -0
- data/spec/support/deprecation.rb +6 -0
- data/spec/support/test_environment.rb +30 -0
- metadata +306 -88
- data/generators/form/USAGE +0 -16
- data/generators/form/form_generator.rb +0 -111
- data/generators/formtastic/formtastic_generator.rb +0 -26
- data/init.rb +0 -5
- data/lib/formtastic/layout_helper.rb +0 -12
- data/lib/generators/formtastic/form/form_generator.rb +0 -84
- data/lib/generators/templates/formtastic.css +0 -145
- data/lib/generators/templates/formtastic_changes.css +0 -14
- data/lib/generators/templates/rails2/_form.html.erb +0 -5
- data/lib/generators/templates/rails2/_form.html.haml +0 -4
- data/rails/init.rb +0 -2
@@ -0,0 +1,14 @@
|
|
1
|
+
module Formtastic
|
2
|
+
module Inputs
|
3
|
+
# @see Formtastic::Inputs::Timeish Timeish module for documetation of date, time and datetime input options.
|
4
|
+
class TimeInput
|
5
|
+
include Base
|
6
|
+
include Base::Timeish
|
7
|
+
|
8
|
+
# we don't want year / month / day fragments in a time select
|
9
|
+
def date_fragments
|
10
|
+
[]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Formtastic
|
2
|
+
module Inputs
|
3
|
+
|
4
|
+
# Outputs a `<label>` with a `<select>` containing a series of time zones (using Rails' own
|
5
|
+
# `time_zone_select` helper), wrapped in the standard `<li>` wrapper.
|
6
|
+
|
7
|
+
# This is the default input choice for attributes matching /time_zone/, but can be applied to
|
8
|
+
# any text-like input with `:as => :time_zone`.
|
9
|
+
#
|
10
|
+
# @example Full form context and output
|
11
|
+
#
|
12
|
+
# <%= semantic_form_for(@user) do |f| %>
|
13
|
+
# <%= f.inputs do %>
|
14
|
+
# <%= f.input :time_zone, :as => :time_zone %>
|
15
|
+
# <% end %>
|
16
|
+
# <% end %>
|
17
|
+
#
|
18
|
+
# <form...>
|
19
|
+
# <fieldset>
|
20
|
+
# <ol>
|
21
|
+
# <li class="time_zone">
|
22
|
+
# <label for="user_time_zone">Time zone</label>
|
23
|
+
# <input type="text" id="user_time_zone" name="user[time_zone]">
|
24
|
+
# </li>
|
25
|
+
# </ol>
|
26
|
+
# </fieldset>
|
27
|
+
# </form>
|
28
|
+
#
|
29
|
+
# @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documetation of all possible options.
|
30
|
+
#
|
31
|
+
# @todo document :priority_zones option
|
32
|
+
# @todo configurable default :priority_zones?
|
33
|
+
class TimeZoneInput
|
34
|
+
include Base
|
35
|
+
|
36
|
+
def to_html
|
37
|
+
input_wrapping do
|
38
|
+
label_html <<
|
39
|
+
builder.time_zone_select(method, priority_zones, input_options, input_html_options)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def priority_zones
|
44
|
+
options[:priority_zones] || [] # TODO config?
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Formtastic
|
2
|
+
module Inputs
|
3
|
+
|
4
|
+
# Outputs a simple `<label>` with a HTML5 `<input type="url">` wrapped in the standard
|
5
|
+
# `<li>` wrapper. This is the default input choice for all attributes matching
|
6
|
+
# `/^url$|^website$|_url$/`, but can be applied to any text-like input with `:as => :url`.
|
7
|
+
#
|
8
|
+
# @example Full form context and output
|
9
|
+
#
|
10
|
+
# <%= semantic_form_for(@user) do |f| %>
|
11
|
+
# <%= f.inputs do %>
|
12
|
+
# <%= f.input :home_page, :as => :url %>
|
13
|
+
# <% end %>
|
14
|
+
# <% end %>
|
15
|
+
#
|
16
|
+
# <form...>
|
17
|
+
# <fieldset>
|
18
|
+
# <ol>
|
19
|
+
# <li class="url">
|
20
|
+
# <label for="user_home_page">Home page</label>
|
21
|
+
# <input type="number" id="user_home_page" name="user[home_page]">
|
22
|
+
# </li>
|
23
|
+
# </ol>
|
24
|
+
# </fieldset>
|
25
|
+
# </form>
|
26
|
+
#
|
27
|
+
# @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documetation of all possible options.
|
28
|
+
class UrlInput
|
29
|
+
include Base
|
30
|
+
include Base::Stringish
|
31
|
+
|
32
|
+
def to_html
|
33
|
+
input_wrapping do
|
34
|
+
label_html <<
|
35
|
+
builder.url_field(method, input_html_options)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module Formtastic
|
2
|
+
# @private
|
3
|
+
module LocalizedString
|
4
|
+
|
5
|
+
protected
|
6
|
+
|
7
|
+
# Internal generic method for looking up localized values within Formtastic
|
8
|
+
# using I18n, if no explicit value is set and I18n-lookups are enabled.
|
9
|
+
#
|
10
|
+
# Enabled/Disable this by setting:
|
11
|
+
#
|
12
|
+
# Formtastic::FormBuilder.i18n_lookups_by_default = true/false
|
13
|
+
#
|
14
|
+
# Lookup priority:
|
15
|
+
#
|
16
|
+
# 'formtastic.%{type}.%{model}.%{action}.%{attribute}'
|
17
|
+
# 'formtastic.%{type}.%{model}.%{attribute}'
|
18
|
+
# 'formtastic.%{type}.%{attribute}'
|
19
|
+
#
|
20
|
+
# Example:
|
21
|
+
#
|
22
|
+
# 'formtastic.labels.post.edit.title'
|
23
|
+
# 'formtastic.labels.post.title'
|
24
|
+
# 'formtastic.labels.title'
|
25
|
+
#
|
26
|
+
# NOTE: Generic, but only used for form input titles/labels/hints/actions (titles = legends, actions = buttons).
|
27
|
+
#
|
28
|
+
def localized_string(key, value, type, options = {}) #:nodoc:
|
29
|
+
key = value if value.is_a?(::Symbol)
|
30
|
+
|
31
|
+
if value.is_a?(::String)
|
32
|
+
escape_html_entities(value)
|
33
|
+
else
|
34
|
+
use_i18n = value.nil? ? i18n_lookups_by_default : (value != false)
|
35
|
+
|
36
|
+
if use_i18n
|
37
|
+
model_name, nested_model_name = normalize_model_name(self.model_name.underscore)
|
38
|
+
|
39
|
+
action_name = template.params[:action].to_s rescue ''
|
40
|
+
attribute_name = key.to_s
|
41
|
+
|
42
|
+
defaults = Formtastic::I18n::SCOPES.reject do |i18n_scope|
|
43
|
+
nested_model_name.nil? && i18n_scope.match(/nested_model/)
|
44
|
+
end.collect do |i18n_scope|
|
45
|
+
i18n_path = i18n_scope.dup
|
46
|
+
i18n_path.gsub!('%{action}', action_name)
|
47
|
+
i18n_path.gsub!('%{model}', model_name)
|
48
|
+
i18n_path.gsub!('%{nested_model}', nested_model_name) unless nested_model_name.nil?
|
49
|
+
i18n_path.gsub!('%{attribute}', attribute_name)
|
50
|
+
i18n_path.gsub!('..', '.')
|
51
|
+
i18n_path.to_sym
|
52
|
+
end
|
53
|
+
defaults << ''
|
54
|
+
|
55
|
+
defaults.uniq!
|
56
|
+
|
57
|
+
default_key = defaults.shift
|
58
|
+
i18n_value = Formtastic::I18n.t(default_key,
|
59
|
+
options.merge(:default => defaults, :scope => type.to_s.pluralize.to_sym))
|
60
|
+
i18n_value = i18n_value.is_a?(::String) ? i18n_value : nil
|
61
|
+
if i18n_value.blank? && type == :label
|
62
|
+
# This is effectively what Rails label helper does for i18n lookup
|
63
|
+
options[:scope] = [:helpers, type]
|
64
|
+
options[:default] = defaults
|
65
|
+
i18n_value = ::I18n.t(default_key, options)
|
66
|
+
end
|
67
|
+
(i18n_value.is_a?(::String) && i18n_value.present?) ? escape_html_entities(i18n_value) : nil
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def model_name
|
73
|
+
@object.present? ? @object.class.name : @object_name.to_s.classify
|
74
|
+
end
|
75
|
+
|
76
|
+
def normalize_model_name(name)
|
77
|
+
if !name =~ /\[/ && self.respond_to?(:builder) && builder.respond_to?(:parent_builder) && builder.parent_builder.object_name
|
78
|
+
# Rails 3.1 nested builder case
|
79
|
+
[builder.parent_builder.object_name.to_s, name]
|
80
|
+
elsif name =~ /(.+)\[(.+)\]/
|
81
|
+
# Rails 3 (and 3.1?) nested builder case with :post rather than @post
|
82
|
+
[$1, $2]
|
83
|
+
elsif self.respond_to?(:builder) && builder.respond_to?(:options) && builder.options.key?(:parent_builder)
|
84
|
+
# Rails 3.0 nested builder work-around case, where :parent_builder is provided by f.semantic_form_for
|
85
|
+
[builder.options[:parent_builder].object_name.to_s, name]
|
86
|
+
else
|
87
|
+
# Non-nested case
|
88
|
+
[name]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def escape_html_entities(string) #:nodoc:
|
93
|
+
if (respond_to?(:builder) && builder.escape_html_entities_in_hints_and_labels) ||
|
94
|
+
(self.respond_to?(:escape_html_entities_in_hints_and_labels) && escape_html_entities_in_hints_and_labels)
|
95
|
+
string = template.escape_once(string) unless string.respond_to?(:html_safe?) && string.html_safe? == true # Acceppt html_safe flag as indicator to skip escaping
|
96
|
+
end
|
97
|
+
string
|
98
|
+
end
|
99
|
+
|
100
|
+
def i18n_lookups_by_default
|
101
|
+
respond_to?(:builder) ? builder.i18n_lookups_by_default : i18n_lookups_by_default
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
end
|
data/lib/formtastic/railtie.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'formtastic'
|
4
|
-
require 'formtastic/layout_helper'
|
5
|
-
require 'rails'
|
6
|
-
|
7
3
|
module Formtastic
|
4
|
+
# @private
|
8
5
|
class Railtie < Rails::Railtie
|
9
|
-
initializer 'formtastic.initialize'
|
10
|
-
|
11
|
-
|
6
|
+
initializer 'formtastic.initialize' do
|
7
|
+
ActiveSupport.on_load(:action_view) do
|
8
|
+
include Formtastic::Helpers::FormHelper
|
9
|
+
end
|
12
10
|
end
|
13
11
|
end
|
14
12
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Formtastic
|
2
|
+
# Quick hack/shim so that any code expecting the old SemanticFormBuilder class still works.
|
3
|
+
# TODO remove from 2.0 with a helpful upgrade path/warning.
|
4
|
+
# @private
|
5
|
+
class SemanticFormBuilder < Formtastic::FormBuilder
|
6
|
+
def initialize(*args)
|
7
|
+
ActiveSupport::Deprecation.warn('Formtastic::SemanticFormBuilder has been deprecated in favor of Formtastic::FormBuilder.', caller)
|
8
|
+
super
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/formtastic/util.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
# Adapted from the rails3 compatibility shim in Haml 2.2
|
4
4
|
module Formtastic
|
5
|
+
# @private
|
5
6
|
module Util
|
6
7
|
extend self
|
7
8
|
## Rails XSS Safety
|
@@ -13,26 +14,12 @@ module Formtastic
|
|
13
14
|
# @param text [String]
|
14
15
|
# @return [String] `text`, marked as HTML-safe
|
15
16
|
def html_safe(text)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
if text.respond_to?(:html_safe)
|
18
|
+
text.html_safe
|
19
|
+
else
|
20
|
+
text
|
21
|
+
end
|
20
22
|
end
|
21
23
|
|
22
|
-
def rails_safe_buffer_class
|
23
|
-
# It's important that we check ActiveSupport first,
|
24
|
-
# because in Rails 2.3.6 ActionView::SafeBuffer exists
|
25
|
-
# but is a deprecated proxy object.
|
26
|
-
return ActiveSupport::SafeBuffer if defined?(ActiveSupport::SafeBuffer)
|
27
|
-
return ActionView::SafeBuffer
|
28
|
-
end
|
29
|
-
|
30
|
-
def rails3?
|
31
|
-
version=
|
32
|
-
if defined?(ActionPack::VERSION::MAJOR)
|
33
|
-
ActionPack::VERSION::MAJOR
|
34
|
-
end
|
35
|
-
!version.blank? && version >= 3
|
36
|
-
end
|
37
24
|
end
|
38
25
|
end
|
@@ -1,15 +1,37 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
|
2
3
|
module Formtastic
|
4
|
+
# Copies formtastic.css to public/stylesheets/ (Rails 3.0.x only) and a config initializer
|
5
|
+
# to config/initializers/formtastic.rb (all Rails versions).
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# $ rails generate formtastic:install
|
9
|
+
#
|
10
|
+
# @todo Test with Rails 3.0
|
3
11
|
class InstallGenerator < Rails::Generators::Base
|
4
|
-
desc "Copies formtastic.css and formtastic_changes.css to public/stylesheets/ and a config initializer to config/initializers/formtastic_config.rb"
|
5
|
-
|
6
12
|
source_root File.expand_path('../../../templates', __FILE__)
|
13
|
+
class_option :template_engine
|
7
14
|
|
8
|
-
|
9
|
-
|
15
|
+
if ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR >= 1
|
16
|
+
# Rails 3.1 has the asset pipeline, no need to copy CSS files any more
|
17
|
+
desc "Copies a config initializer to config/initializers/formtastic.rb"
|
18
|
+
def copy_files
|
19
|
+
copy_file 'formtastic.rb', 'config/initializers/formtastic.rb'
|
20
|
+
end
|
21
|
+
else
|
22
|
+
# Rails 3.0 doesn't have an asset pipeline, so we copy in CSS too
|
23
|
+
desc "Copies some CSS files to public/stylesheets/ and a config initializer to config/initializers/formtastic.rb"
|
24
|
+
def copy_files
|
25
|
+
template 'formtastic.rb', 'config/initializers/formtastic.rb'
|
26
|
+
template '../../../app/assets/stylesheets/formtastic.css', 'public/stylesheets/formtastic.css'
|
27
|
+
template '../../../app/assets/stylesheets/formtastic_ie6.css', 'public/stylesheets/formtastic_ie6.css'
|
28
|
+
template '../../../app/assets/stylesheets/formtastic_ie7.css', 'public/stylesheets/formtastic_ie7.css'
|
29
|
+
end
|
30
|
+
end
|
10
31
|
|
11
|
-
|
12
|
-
|
32
|
+
def copy_scaffold_template
|
33
|
+
engine = options[:template_engine]
|
34
|
+
copy_file "_form.html.#{engine}", "lib/templates/#{engine}/scaffold/_form.html.#{engine}"
|
13
35
|
end
|
14
36
|
end
|
15
37
|
end
|
@@ -1,5 +1,11 @@
|
|
1
|
-
<%%=
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
<%%= semantic_form_for @<%= singular_name %> do |f| %>
|
2
|
+
<%%= f.inputs do %>
|
3
|
+
<%- attributes.each do |attribute| -%>
|
4
|
+
<%%= f.input :<%= attribute.name %> %>
|
5
|
+
<%- end -%>
|
6
|
+
<%% end %>
|
7
|
+
|
8
|
+
<%%= f.buttons do %>
|
9
|
+
<%%= f.commit_button %>
|
10
|
+
<%% end %>
|
5
11
|
<%% end %>
|
@@ -1,4 +1,8 @@
|
|
1
|
-
=
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
= semantic_form_for @<%= singular_name %> do |f|
|
2
|
+
= f.inputs do
|
3
|
+
<% attributes.each do |attribute| -%>
|
4
|
+
= f.input :<%= attribute.name %>
|
5
|
+
<% end -%>
|
6
|
+
|
7
|
+
= f.buttons do
|
8
|
+
= f.commit_button
|
@@ -1,80 +1,73 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
# --------------------------------------------------------------------------------------------------
|
4
|
-
# Please note: If you're subclassing Formtastic::
|
5
|
-
#
|
6
|
-
# class_inheritable_attribute. The behaviour is slightly different with subclasses (especially
|
7
|
-
# around attributes with Hash or Array) values, so make sure you understand what's happening.
|
4
|
+
# Please note: If you're subclassing Formtastic::FormBuilder, Formtastic uses
|
5
|
+
# class_attribute for these configuration attributes instead of the deprecated
|
6
|
+
# class_inheritable_attribute. The behaviour is slightly different with subclasses (especially
|
7
|
+
# around attributes with Hash or Array) values, so make sure you understand what's happening.
|
8
8
|
# See the documentation for class_attribute in ActiveSupport for more information.
|
9
9
|
# --------------------------------------------------------------------------------------------------
|
10
10
|
|
11
11
|
# Set the default text field size when input is a string. Default is nil.
|
12
|
-
# Formtastic::
|
12
|
+
# Formtastic::FormBuilder.default_text_field_size = 50
|
13
13
|
|
14
14
|
# Set the default text area height when input is a text. Default is 20.
|
15
|
-
# Formtastic::
|
15
|
+
# Formtastic::FormBuilder.default_text_area_height = 5
|
16
16
|
|
17
17
|
# Set the default text area width when input is a text. Default is nil.
|
18
|
-
# Formtastic::
|
18
|
+
# Formtastic::FormBuilder.default_text_area_width = 50
|
19
19
|
|
20
20
|
# Should all fields be considered "required" by default?
|
21
|
-
# Rails 2 only, ignored by Rails 3 because it will never fall back to this default.
|
22
21
|
# Defaults to true.
|
23
|
-
# Formtastic::
|
22
|
+
# Formtastic::FormBuilder.all_fields_required_by_default = true
|
24
23
|
|
25
24
|
# Should select fields have a blank option/prompt by default?
|
26
25
|
# Defaults to true.
|
27
|
-
# Formtastic::
|
26
|
+
# Formtastic::FormBuilder.include_blank_for_select_by_default = true
|
28
27
|
|
29
28
|
# Set the string that will be appended to the labels/fieldsets which are required
|
30
29
|
# It accepts string or procs and the default is a localized version of
|
31
30
|
# '<abbr title="required">*</abbr>'. In other words, if you configure formtastic.required
|
32
31
|
# in your locale, it will replace the abbr title properly. But if you don't want to use
|
33
32
|
# abbr tag, you can simply give a string as below
|
34
|
-
# Formtastic::
|
33
|
+
# Formtastic::FormBuilder.required_string = "(required)"
|
35
34
|
|
36
35
|
# Set the string that will be appended to the labels/fieldsets which are optional
|
37
36
|
# Defaults to an empty string ("") and also accepts procs (see required_string above)
|
38
|
-
# Formtastic::
|
37
|
+
# Formtastic::FormBuilder.optional_string = "(optional)"
|
39
38
|
|
40
39
|
# Set the way inline errors will be displayed.
|
41
40
|
# Defaults to :sentence, valid options are :sentence, :list, :first and :none
|
42
|
-
# Formtastic::
|
41
|
+
# Formtastic::FormBuilder.inline_errors = :sentence
|
43
42
|
# Formtastic uses the following classes as default for hints, inline_errors and error list
|
44
43
|
|
45
|
-
# If you override the class here, please ensure to override it in your
|
46
|
-
# Formtastic::
|
47
|
-
# Formtastic::
|
48
|
-
# Formtastic::
|
44
|
+
# If you override the class here, please ensure to override it in your stylesheets as well
|
45
|
+
# Formtastic::FormBuilder.default_hint_class = "inline-hints"
|
46
|
+
# Formtastic::FormBuilder.default_inline_error_class = "inline-errors"
|
47
|
+
# Formtastic::FormBuilder.default_error_list_class = "errors"
|
49
48
|
|
50
49
|
# Set the method to call on label text to transform or format it for human-friendly
|
51
50
|
# reading when formtastic is used without object. Defaults to :humanize.
|
52
|
-
# Formtastic::
|
51
|
+
# Formtastic::FormBuilder.label_str_method = :humanize
|
53
52
|
|
54
53
|
# Set the array of methods to try calling on parent objects in :select and :radio inputs
|
55
54
|
# for the text inside each @<option>@ tag or alongside each radio @<input>@. The first method
|
56
55
|
# that is found on the object will be used.
|
57
56
|
# Defaults to ["to_label", "display_name", "full_name", "name", "title", "username", "login", "value", "to_s"]
|
58
|
-
# Formtastic::
|
57
|
+
# Formtastic::FormBuilder.collection_label_methods = [
|
59
58
|
# "to_label", "display_name", "full_name", "name", "title", "username", "login", "value", "to_s"]
|
60
59
|
|
61
|
-
# Formtastic by default renders inside li tags the input, hints and then
|
62
|
-
# errors messages. Sometimes you want the hints to be rendered first than
|
63
|
-
# the input, in the following order: hints, input and errors. You can
|
64
|
-
# customize it doing just as below:
|
65
|
-
# Formtastic::SemanticFormBuilder.inline_order = [:input, :hints, :errors]
|
66
|
-
|
67
60
|
# Additionally, you can customize the order for specific types of inputs.
|
68
61
|
# This is configured on a type basis and if a type is not found it will
|
69
62
|
# fall back to the default order as defined by #inline_order
|
70
|
-
# Formtastic::
|
71
|
-
# Formtastic::
|
63
|
+
# Formtastic::FormBuilder.custom_inline_order[:checkbox] = [:errors, :hints, :input]
|
64
|
+
# Formtastic::FormBuilder.custom_inline_order[:select] = [:hints, :input, :errors]
|
72
65
|
|
73
66
|
# Specifies if labels/hints for input fields automatically be looked up using I18n.
|
74
|
-
# Default value:
|
67
|
+
# Default value: true. Overridden for specific fields by setting value to true,
|
75
68
|
# i.e. :label => true, or :hint => true (or opposite depending on initialized value)
|
76
|
-
# Formtastic::
|
69
|
+
# Formtastic::FormBuilder_lookups_by_default = false
|
77
70
|
|
78
|
-
# You can add custom inputs or override parts of Formtastic by subclassing
|
79
|
-
# specifying that class here. Defaults to
|
80
|
-
# Formtastic::
|
71
|
+
# You can add custom inputs or override parts of Formtastic by subclassing Formtastic::FormBuilder and
|
72
|
+
# specifying that class here. Defaults to Formtastic::FormBuilder.
|
73
|
+
# Formtastic::Helpers::FormHelper.builder = MyCustomBuilder
|