formtastic 1.2.4 → 3.1.5
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +46 -0
- data/.yardopts +1 -0
- data/Appraisals +43 -0
- data/CHANGELOG +54 -0
- data/DEPRECATIONS +52 -0
- data/Gemfile +3 -0
- data/README.md +629 -0
- data/RELEASE_PROCESS +6 -0
- data/Rakefile +35 -0
- data/app/assets/stylesheets/formtastic.css +289 -0
- data/app/assets/stylesheets/formtastic_ie6.css +33 -0
- data/app/assets/stylesheets/formtastic_ie7.css +23 -0
- data/formtastic.gemspec +42 -0
- data/gemfiles/rails_3.2.gemfile +9 -0
- data/gemfiles/rails_4.0.4.gemfile +8 -0
- data/gemfiles/rails_4.1.gemfile +8 -0
- data/gemfiles/rails_4.2.gemfile +8 -0
- data/gemfiles/rails_4.gemfile +8 -0
- data/gemfiles/rails_5.0.gemfile +8 -0
- data/gemfiles/rails_edge.gemfile +15 -0
- data/lib/formtastic.rb +40 -1945
- data/lib/formtastic/action_class_finder.rb +18 -0
- data/lib/formtastic/actions.rb +11 -0
- data/lib/formtastic/actions/base.rb +156 -0
- data/lib/formtastic/actions/button_action.rb +67 -0
- data/lib/formtastic/actions/buttonish.rb +17 -0
- data/lib/formtastic/actions/input_action.rb +70 -0
- data/lib/formtastic/actions/link_action.rb +88 -0
- data/lib/formtastic/deprecation.rb +42 -0
- data/lib/formtastic/engine.rb +11 -0
- data/lib/formtastic/form_builder.rb +124 -0
- data/lib/formtastic/helpers.rb +16 -0
- data/lib/formtastic/helpers/action_helper.rb +162 -0
- data/lib/formtastic/helpers/actions_helper.rb +168 -0
- data/lib/formtastic/helpers/enum.rb +13 -0
- data/lib/formtastic/helpers/errors_helper.rb +81 -0
- data/lib/formtastic/helpers/fieldset_wrapper.rb +80 -0
- data/lib/formtastic/helpers/file_column_detection.rb +16 -0
- data/lib/formtastic/helpers/form_helper.rb +203 -0
- data/lib/formtastic/helpers/input_helper.rb +407 -0
- data/lib/formtastic/helpers/inputs_helper.rb +411 -0
- data/lib/formtastic/helpers/reflection.rb +37 -0
- data/lib/formtastic/html_attributes.rb +32 -0
- data/lib/formtastic/i18n.rb +4 -2
- data/lib/formtastic/input_class_finder.rb +18 -0
- data/lib/formtastic/inputs.rb +39 -0
- data/lib/formtastic/inputs/base.rb +76 -0
- data/lib/formtastic/inputs/base/associations.rb +31 -0
- data/lib/formtastic/inputs/base/choices.rb +108 -0
- data/lib/formtastic/inputs/base/collections.rb +159 -0
- data/lib/formtastic/inputs/base/database.rb +22 -0
- data/lib/formtastic/inputs/base/datetime_pickerish.rb +85 -0
- data/lib/formtastic/inputs/base/errors.rb +58 -0
- data/lib/formtastic/inputs/base/fileish.rb +23 -0
- data/lib/formtastic/inputs/base/hints.rb +31 -0
- data/lib/formtastic/inputs/base/html.rb +53 -0
- data/lib/formtastic/inputs/base/labelling.rb +52 -0
- data/lib/formtastic/inputs/base/naming.rb +42 -0
- data/lib/formtastic/inputs/base/numeric.rb +50 -0
- data/lib/formtastic/inputs/base/options.rb +17 -0
- data/lib/formtastic/inputs/base/placeholder.rb +17 -0
- data/lib/formtastic/inputs/base/stringish.rb +38 -0
- data/lib/formtastic/inputs/base/timeish.rb +241 -0
- data/lib/formtastic/inputs/base/validations.rb +215 -0
- data/lib/formtastic/inputs/base/wrapping.rb +50 -0
- data/lib/formtastic/inputs/boolean_input.rb +118 -0
- data/lib/formtastic/inputs/check_boxes_input.rb +197 -0
- data/lib/formtastic/inputs/color_input.rb +42 -0
- data/lib/formtastic/inputs/country_input.rb +86 -0
- data/lib/formtastic/inputs/datalist_input.rb +41 -0
- data/lib/formtastic/inputs/date_picker_input.rb +93 -0
- data/lib/formtastic/inputs/date_select_input.rb +34 -0
- data/lib/formtastic/inputs/datetime_picker_input.rb +103 -0
- data/lib/formtastic/inputs/datetime_select_input.rb +12 -0
- data/lib/formtastic/inputs/email_input.rb +41 -0
- data/lib/formtastic/inputs/file_input.rb +42 -0
- data/lib/formtastic/inputs/hidden_input.rb +62 -0
- data/lib/formtastic/inputs/number_input.rb +88 -0
- data/lib/formtastic/inputs/password_input.rb +41 -0
- data/lib/formtastic/inputs/phone_input.rb +42 -0
- data/lib/formtastic/inputs/radio_input.rb +163 -0
- data/lib/formtastic/inputs/range_input.rb +95 -0
- data/lib/formtastic/inputs/search_input.rb +41 -0
- data/lib/formtastic/inputs/select_input.rb +235 -0
- data/lib/formtastic/inputs/string_input.rb +36 -0
- data/lib/formtastic/inputs/text_input.rb +48 -0
- data/lib/formtastic/inputs/time_picker_input.rb +99 -0
- data/lib/formtastic/inputs/time_select_input.rb +38 -0
- data/lib/formtastic/inputs/time_zone_input.rb +58 -0
- data/lib/formtastic/inputs/url_input.rb +41 -0
- data/lib/formtastic/localized_string.rb +17 -0
- data/lib/formtastic/localizer.rb +152 -0
- data/lib/formtastic/namespaced_class_finder.rb +99 -0
- data/lib/formtastic/util.rb +35 -16
- data/lib/formtastic/version.rb +3 -0
- data/lib/generators/formtastic/form/form_generator.rb +64 -37
- data/lib/generators/formtastic/input/input_generator.rb +46 -0
- data/lib/generators/formtastic/install/install_generator.rb +13 -5
- data/lib/generators/templates/_form.html.erb +10 -4
- data/lib/generators/templates/_form.html.haml +8 -4
- data/lib/generators/templates/_form.html.slim +8 -0
- data/lib/generators/templates/formtastic.rb +77 -44
- data/lib/generators/templates/input.rb +19 -0
- data/lib/locale/en.yml +3 -0
- data/sample/basic_inputs.html +224 -0
- data/sample/config.ru +69 -0
- data/sample/index.html +14 -0
- data/spec/action_class_finder_spec.rb +12 -0
- data/spec/actions/button_action_spec.rb +63 -0
- data/spec/actions/generic_action_spec.rb +521 -0
- data/spec/actions/input_action_spec.rb +59 -0
- data/spec/actions/link_action_spec.rb +92 -0
- data/spec/builder/custom_builder_spec.rb +116 -0
- data/spec/builder/error_proc_spec.rb +27 -0
- data/spec/builder/semantic_fields_for_spec.rb +142 -0
- data/spec/fast_spec_helper.rb +12 -0
- data/spec/generators/formtastic/form/form_generator_spec.rb +131 -0
- data/spec/generators/formtastic/input/input_generator_spec.rb +124 -0
- data/spec/generators/formtastic/install/install_generator_spec.rb +47 -0
- data/spec/helpers/action_helper_spec.rb +19 -0
- data/spec/helpers/actions_helper_spec.rb +143 -0
- data/spec/helpers/form_helper_spec.rb +218 -0
- data/spec/helpers/input_helper_spec.rb +6 -0
- data/spec/helpers/inputs_helper_spec.rb +655 -0
- data/spec/helpers/namespaced_action_helper_spec.rb +43 -0
- data/spec/helpers/namespaced_input_helper_spec.rb +36 -0
- data/spec/helpers/reflection_helper_spec.rb +32 -0
- data/spec/helpers/semantic_errors_helper_spec.rb +112 -0
- data/spec/i18n_spec.rb +210 -0
- data/spec/input_class_finder_spec.rb +10 -0
- data/spec/inputs/base/collections_spec.rb +76 -0
- data/spec/inputs/base/validations_spec.rb +342 -0
- data/spec/inputs/boolean_input_spec.rb +254 -0
- data/spec/inputs/check_boxes_input_spec.rb +546 -0
- data/spec/inputs/color_input_spec.rb +97 -0
- data/spec/inputs/country_input_spec.rb +133 -0
- data/spec/inputs/custom_input_spec.rb +55 -0
- data/spec/inputs/datalist_input_spec.rb +61 -0
- data/spec/inputs/date_picker_input_spec.rb +449 -0
- data/spec/inputs/date_select_input_spec.rb +235 -0
- data/spec/inputs/datetime_picker_input_spec.rb +490 -0
- data/spec/inputs/datetime_select_input_spec.rb +193 -0
- data/spec/inputs/email_input_spec.rb +85 -0
- data/spec/inputs/file_input_spec.rb +89 -0
- data/spec/inputs/hidden_input_spec.rb +135 -0
- data/spec/inputs/include_blank_spec.rb +78 -0
- data/spec/inputs/label_spec.rb +149 -0
- data/spec/inputs/number_input_spec.rb +815 -0
- data/spec/inputs/password_input_spec.rb +99 -0
- data/spec/inputs/phone_input_spec.rb +85 -0
- data/spec/inputs/placeholder_spec.rb +71 -0
- data/spec/inputs/radio_input_spec.rb +328 -0
- data/spec/inputs/range_input_spec.rb +505 -0
- data/spec/inputs/readonly_spec.rb +50 -0
- data/spec/inputs/search_input_spec.rb +84 -0
- data/spec/inputs/select_input_spec.rb +615 -0
- data/spec/inputs/string_input_spec.rb +260 -0
- data/spec/inputs/text_input_spec.rb +187 -0
- data/spec/inputs/time_picker_input_spec.rb +455 -0
- data/spec/inputs/time_select_input_spec.rb +248 -0
- data/spec/inputs/time_zone_input_spec.rb +143 -0
- data/spec/inputs/url_input_spec.rb +85 -0
- data/spec/inputs/with_options_spec.rb +43 -0
- data/spec/localizer_spec.rb +130 -0
- data/spec/namespaced_class_finder_spec.rb +79 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +525 -0
- data/spec/support/custom_macros.rb +564 -0
- data/spec/support/deprecation.rb +6 -0
- data/spec/support/shared_examples.rb +1313 -0
- data/spec/support/specialized_class_finder_shared_example.rb +27 -0
- data/spec/support/test_environment.rb +31 -0
- data/spec/util_spec.rb +66 -0
- metadata +434 -161
- data/README.textile +0 -682
- 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/formtastic/railtie.rb +0 -14
- 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,22 @@
|
|
|
1
|
+
module Formtastic
|
|
2
|
+
module Inputs
|
|
3
|
+
module Base
|
|
4
|
+
module Database
|
|
5
|
+
|
|
6
|
+
def column
|
|
7
|
+
if object.respond_to?(:column_for_attribute)
|
|
8
|
+
# Remove deprecation wrapper & review after Rails 5.0 ships
|
|
9
|
+
ActiveSupport::Deprecation.silence do
|
|
10
|
+
object.column_for_attribute(method)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def column?
|
|
16
|
+
!column.nil?
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
module Formtastic
|
|
2
|
+
module Inputs
|
|
3
|
+
module Base
|
|
4
|
+
module DatetimePickerish
|
|
5
|
+
include Base::Placeholder
|
|
6
|
+
|
|
7
|
+
def html_input_type
|
|
8
|
+
raise NotImplementedError
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def default_size
|
|
12
|
+
raise NotImplementedError
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def value
|
|
16
|
+
raise NotImplementedError
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def input_html_options
|
|
20
|
+
super.merge(extra_input_html_options)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def extra_input_html_options
|
|
24
|
+
{
|
|
25
|
+
:type => html_input_type,
|
|
26
|
+
:size => size,
|
|
27
|
+
:maxlength => maxlength,
|
|
28
|
+
:step => step,
|
|
29
|
+
:value => value
|
|
30
|
+
}
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def size
|
|
34
|
+
return options[:size] if options.key?(:size)
|
|
35
|
+
return options[:input_html][:size] if options[:input_html] && options[:input_html].key?(:size)
|
|
36
|
+
default_size
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def step
|
|
40
|
+
return step_from_macro(options[:input_html][:step]) if options[:input_html] && options[:input_html][:step] && options[:input_html][:step].is_a?(Symbol)
|
|
41
|
+
return options[:input_html][:step] if options[:input_html] && options[:input_html].key?(:step)
|
|
42
|
+
default_step
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def maxlength
|
|
46
|
+
return options[:maxlength] if options.key?(:maxlength)
|
|
47
|
+
return options[:input_html][:maxlength] if options[:input_html] && options[:input_html].key?(:maxlength)
|
|
48
|
+
default_size
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def default_maxlength
|
|
52
|
+
default_size
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def default_step
|
|
56
|
+
1
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
protected
|
|
60
|
+
|
|
61
|
+
def step_from_macro(sym)
|
|
62
|
+
case sym
|
|
63
|
+
|
|
64
|
+
# date
|
|
65
|
+
when :day then "1"
|
|
66
|
+
when :seven_days, :week then "7"
|
|
67
|
+
when :two_weeks, :fortnight then "14"
|
|
68
|
+
when :four_weeks then "28"
|
|
69
|
+
when :thirty_days then "30"
|
|
70
|
+
|
|
71
|
+
# time
|
|
72
|
+
when :second then "1"
|
|
73
|
+
when :minute then "60"
|
|
74
|
+
when :fifteen_minutes, :quarter_hour then "900"
|
|
75
|
+
when :thirty_minutes, :half_hour then "1800"
|
|
76
|
+
when :sixty_minutes, :hour then "3600"
|
|
77
|
+
|
|
78
|
+
else sym
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
module Formtastic
|
|
2
|
+
module Inputs
|
|
3
|
+
module Base
|
|
4
|
+
module Errors
|
|
5
|
+
|
|
6
|
+
def error_html
|
|
7
|
+
errors? ? send(:"error_#{builder.inline_errors}_html") : ""
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def error_sentence_html
|
|
11
|
+
error_class = builder.default_inline_error_class
|
|
12
|
+
template.content_tag(:p, Formtastic::Util.html_safe(errors.to_sentence.html_safe), :class => error_class)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def error_list_html
|
|
16
|
+
error_class = builder.default_error_list_class
|
|
17
|
+
list_elements = []
|
|
18
|
+
errors.each do |error|
|
|
19
|
+
list_elements << template.content_tag(:li, Formtastic::Util.html_safe(error.html_safe))
|
|
20
|
+
end
|
|
21
|
+
template.content_tag(:ul, Formtastic::Util.html_safe(list_elements.join("\n")), :class => error_class)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def error_first_html
|
|
25
|
+
error_class = builder.default_inline_error_class
|
|
26
|
+
template.content_tag(:p, Formtastic::Util.html_safe(errors.first.untaint), :class => error_class)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def error_none_html
|
|
30
|
+
""
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def errors?
|
|
34
|
+
!errors.blank?
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def errors
|
|
38
|
+
errors = []
|
|
39
|
+
if object && object.respond_to?(:errors)
|
|
40
|
+
error_keys.each do |key|
|
|
41
|
+
errors << object.errors[key] unless object.errors[key].blank?
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
errors.flatten.compact.uniq
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def error_keys
|
|
48
|
+
keys = [method.to_sym]
|
|
49
|
+
keys << builder.file_metadata_suffixes.map{|suffix| "#{method}_#{suffix}".to_sym} if file?
|
|
50
|
+
keys << association_primary_key if belongs_to? || has_many?
|
|
51
|
+
keys.flatten.compact.uniq
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Formtastic
|
|
2
|
+
module Inputs
|
|
3
|
+
module Base
|
|
4
|
+
module Fileish
|
|
5
|
+
|
|
6
|
+
def file?
|
|
7
|
+
@file ||= begin
|
|
8
|
+
# TODO return true if self.is_a?(Formtastic::Inputs::FileInput::Woo)
|
|
9
|
+
object && object.respond_to?(method) && builder.file_methods.any? { |m| object.send(method).respond_to?(m) }
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module Formtastic
|
|
2
|
+
module Inputs
|
|
3
|
+
module Base
|
|
4
|
+
module Hints
|
|
5
|
+
|
|
6
|
+
def hint_html
|
|
7
|
+
if hint?
|
|
8
|
+
template.content_tag(
|
|
9
|
+
:p,
|
|
10
|
+
Formtastic::Util.html_safe(hint_text),
|
|
11
|
+
:class => builder.default_hint_class
|
|
12
|
+
)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def hint?
|
|
17
|
+
!hint_text.blank? && !hint_text.kind_of?(Hash)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def hint_text
|
|
21
|
+
localized_string(method, options[:hint], :hint)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def hint_text_from_options
|
|
25
|
+
options[:hint]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module Formtastic
|
|
2
|
+
module Inputs
|
|
3
|
+
module Base
|
|
4
|
+
module Html
|
|
5
|
+
|
|
6
|
+
# Defines how the instance of an input should be rendered to a HTML string.
|
|
7
|
+
#
|
|
8
|
+
# @abstract Implement this method in your input class to describe how the input should render itself.
|
|
9
|
+
#
|
|
10
|
+
# @example A basic label and text field input inside a standard wrapping might look like this:
|
|
11
|
+
# def to_html
|
|
12
|
+
# input_wrapping do
|
|
13
|
+
# label_html <<
|
|
14
|
+
# builder.text_field(method, input_html_options)
|
|
15
|
+
# end
|
|
16
|
+
# end
|
|
17
|
+
def to_html
|
|
18
|
+
raise NotImplementedError
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def input_html_options
|
|
22
|
+
{
|
|
23
|
+
:id => dom_id,
|
|
24
|
+
:required => required_attribute?,
|
|
25
|
+
:autofocus => autofocus?,
|
|
26
|
+
:readonly => readonly?
|
|
27
|
+
}.merge(options[:input_html] || {})
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def dom_id
|
|
31
|
+
[
|
|
32
|
+
builder.dom_id_namespace,
|
|
33
|
+
sanitized_object_name,
|
|
34
|
+
dom_index,
|
|
35
|
+
association_primary_key || sanitized_method_name
|
|
36
|
+
].reject { |x| x.blank? }.join('_')
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def dom_index
|
|
40
|
+
if builder.options.has_key?(:index)
|
|
41
|
+
builder.options[:index]
|
|
42
|
+
elsif !builder.auto_index.blank?
|
|
43
|
+
# TODO there's no coverage for this case, not sure how to create a scenario for it
|
|
44
|
+
builder.auto_index
|
|
45
|
+
else
|
|
46
|
+
""
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module Formtastic
|
|
2
|
+
module Inputs
|
|
3
|
+
module Base
|
|
4
|
+
module Labelling
|
|
5
|
+
|
|
6
|
+
include Formtastic::LocalizedString
|
|
7
|
+
|
|
8
|
+
def label_html
|
|
9
|
+
render_label? ? builder.label(input_name, label_text, label_html_options) : "".html_safe
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def label_html_options
|
|
13
|
+
{
|
|
14
|
+
:for => input_html_options[:id],
|
|
15
|
+
:class => ['label'],
|
|
16
|
+
}
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def label_text
|
|
20
|
+
((localized_label || humanized_method_name) + requirement_text).html_safe
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# TODO: why does this need to be memoized in order to make the inputs_spec tests pass?
|
|
24
|
+
def requirement_text_or_proc
|
|
25
|
+
@requirement_text_or_proc ||= required? ? builder.required_string : builder.optional_string
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def requirement_text
|
|
29
|
+
if requirement_text_or_proc.respond_to?(:call)
|
|
30
|
+
requirement_text_or_proc.call
|
|
31
|
+
else
|
|
32
|
+
requirement_text_or_proc
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def label_from_options
|
|
37
|
+
options[:label]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def localized_label
|
|
41
|
+
localized_string(method, label_from_options || method, :label)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def render_label?
|
|
45
|
+
return false if options[:label] == false
|
|
46
|
+
true
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module Formtastic
|
|
2
|
+
module Inputs
|
|
3
|
+
module Base
|
|
4
|
+
module Naming
|
|
5
|
+
|
|
6
|
+
def as
|
|
7
|
+
self.class.name.split("::")[-1].underscore.gsub(/_input$/, '')
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def sanitized_object_name
|
|
11
|
+
object_name.to_s.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def sanitized_method_name
|
|
15
|
+
@sanitized_method_name ||= method.to_s.gsub(/[\?\/\-]$/, '')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def attributized_method_name
|
|
19
|
+
method.to_s.gsub(/_id$/, '').to_sym
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def humanized_method_name
|
|
23
|
+
if builder.label_str_method != :humanize
|
|
24
|
+
# Special case where label_str_method should trump the human_attribute_name
|
|
25
|
+
# TODO: is this actually a desired bheavior, or should we ditch label_str_method and
|
|
26
|
+
# rely purely on :human_attribute_name.
|
|
27
|
+
method.to_s.send(builder.label_str_method)
|
|
28
|
+
elsif object && object.class.respond_to?(:human_attribute_name)
|
|
29
|
+
object.class.human_attribute_name(method.to_s)
|
|
30
|
+
else
|
|
31
|
+
method.to_s.send(builder.label_str_method)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def input_name
|
|
36
|
+
association_primary_key
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
module Formtastic
|
|
2
|
+
module Inputs
|
|
3
|
+
module Base
|
|
4
|
+
module Numeric
|
|
5
|
+
def input_html_options
|
|
6
|
+
defaults = super
|
|
7
|
+
|
|
8
|
+
# override rails default size - does not apply to numeric inputs
|
|
9
|
+
#@todo document/spec
|
|
10
|
+
defaults[:size] = nil
|
|
11
|
+
|
|
12
|
+
if in_option
|
|
13
|
+
defaults[:min] = in_option.to_a.min
|
|
14
|
+
defaults[:max] = in_option.to_a.max
|
|
15
|
+
else
|
|
16
|
+
defaults[:min] ||= min_option
|
|
17
|
+
defaults[:max] ||= max_option
|
|
18
|
+
end
|
|
19
|
+
defaults[:step] ||= step_option
|
|
20
|
+
defaults
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def step_option
|
|
24
|
+
return options[:step] if options.key?(:step)
|
|
25
|
+
validation_step
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def min_option
|
|
29
|
+
return options[:min] if options.key?(:min)
|
|
30
|
+
validation_min
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def max_option
|
|
34
|
+
return options[:max] if options.key?(:max)
|
|
35
|
+
validation_max
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def in_option
|
|
39
|
+
options[:in]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def wrapper_html_options
|
|
43
|
+
new_class = [super[:class], "numeric", "stringish"].compact.join(" ")
|
|
44
|
+
super.merge(:class => new_class)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Formtastic
|
|
2
|
+
module Inputs
|
|
3
|
+
module Base
|
|
4
|
+
module Options
|
|
5
|
+
|
|
6
|
+
def input_options
|
|
7
|
+
options.except(*formtastic_options)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def formtastic_options
|
|
11
|
+
[:priority_countries, :priority_zones, :member_label, :member_value, :collection, :required, :label, :as, :hint, :input_html, :value_as_class, :class]
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|