formtastic-bootstrap 2.1.0 → 2.1.1
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/VERSION +1 -1
- data/lib/action_view/helpers/text_field_date_helper.rb +166 -0
- data/lib/formtastic-bootstrap/actions.rb +10 -0
- data/lib/formtastic-bootstrap/actions/base.rb +22 -0
- data/lib/formtastic-bootstrap/actions/button_action.rb +13 -0
- data/lib/formtastic-bootstrap/actions/input_action.rb +13 -0
- data/lib/formtastic-bootstrap/actions/link_action.rb +12 -0
- data/lib/formtastic-bootstrap/engine.rb +4 -0
- data/lib/formtastic-bootstrap/form_builder.rb +41 -0
- data/lib/formtastic-bootstrap/helpers.rb +17 -0
- data/lib/formtastic-bootstrap/helpers/action_helper.rb +12 -0
- data/lib/formtastic-bootstrap/helpers/actions_helper.rb +24 -0
- data/lib/formtastic-bootstrap/helpers/errors_helper.rb +70 -0
- data/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb +35 -0
- data/lib/formtastic-bootstrap/helpers/input_helper.rb +12 -0
- data/lib/formtastic-bootstrap/helpers/inputs_helper.rb +34 -0
- data/lib/formtastic-bootstrap/inputs.rb +36 -0
- data/lib/formtastic-bootstrap/inputs/base.rb +45 -0
- data/lib/formtastic-bootstrap/inputs/base/choices.rb +20 -0
- data/lib/formtastic-bootstrap/inputs/base/collections.rb +9 -0
- data/lib/formtastic-bootstrap/inputs/base/datetime_pickerish.rb +10 -0
- data/lib/formtastic-bootstrap/inputs/base/errors.rb +48 -0
- data/lib/formtastic-bootstrap/inputs/base/grouped_collections.rb +9 -0
- data/lib/formtastic-bootstrap/inputs/base/hints.rb +27 -0
- data/lib/formtastic-bootstrap/inputs/base/html.rb +21 -0
- data/lib/formtastic-bootstrap/inputs/base/labelling.rb +29 -0
- data/lib/formtastic-bootstrap/inputs/base/numeric.rb +9 -0
- data/lib/formtastic-bootstrap/inputs/base/placeholder.rb +9 -0
- data/lib/formtastic-bootstrap/inputs/base/stringish.rb +17 -0
- data/lib/formtastic-bootstrap/inputs/base/timeish.rb +55 -0
- data/lib/formtastic-bootstrap/inputs/base/wrapping.rb +83 -0
- data/lib/formtastic-bootstrap/inputs/boolean_input.rb +29 -0
- data/lib/formtastic-bootstrap/inputs/check_boxes_input.rb +40 -0
- data/lib/formtastic-bootstrap/inputs/country_input.rb +14 -0
- data/lib/formtastic-bootstrap/inputs/date_input.rb +10 -0
- data/lib/formtastic-bootstrap/inputs/date_picker_input.rb +9 -0
- data/lib/formtastic-bootstrap/inputs/date_select_input.rb +8 -0
- data/lib/formtastic-bootstrap/inputs/datetime_input.rb +10 -0
- data/lib/formtastic-bootstrap/inputs/datetime_picker_input.rb +9 -0
- data/lib/formtastic-bootstrap/inputs/datetime_select_input.rb +8 -0
- data/lib/formtastic-bootstrap/inputs/email_input.rb +15 -0
- data/lib/formtastic-bootstrap/inputs/file_input.rb +14 -0
- data/lib/formtastic-bootstrap/inputs/hidden_input.rb +12 -0
- data/lib/formtastic-bootstrap/inputs/number_input.rb +15 -0
- data/lib/formtastic-bootstrap/inputs/password_input.rb +15 -0
- data/lib/formtastic-bootstrap/inputs/phone_input.rb +15 -0
- data/lib/formtastic-bootstrap/inputs/radio_input.rb +46 -0
- data/lib/formtastic-bootstrap/inputs/range_input.rb +15 -0
- data/lib/formtastic-bootstrap/inputs/search_input.rb +15 -0
- data/lib/formtastic-bootstrap/inputs/select_input.rb +16 -0
- data/lib/formtastic-bootstrap/inputs/string_input.rb +8 -0
- data/lib/formtastic-bootstrap/inputs/text_input.rb +14 -0
- data/lib/formtastic-bootstrap/inputs/time_input.rb +10 -0
- data/lib/formtastic-bootstrap/inputs/time_select_input.rb +8 -0
- data/lib/formtastic-bootstrap/inputs/time_zone_input.rb +14 -0
- data/lib/formtastic-bootstrap/inputs/url_input.rb +14 -0
- data/lib/formtastic-bootstrap/version.rb +3 -0
- metadata +62 -3
@@ -0,0 +1,34 @@
|
|
1
|
+
module FormtasticBootstrap
|
2
|
+
module Helpers
|
3
|
+
module InputsHelper
|
4
|
+
|
5
|
+
def inputs(*args, &block)
|
6
|
+
wrap_it = @already_in_an_inputs_block ? true : false
|
7
|
+
@already_in_an_inputs_block = true
|
8
|
+
|
9
|
+
title = field_set_title_from_args(*args)
|
10
|
+
html_options = args.extract_options!
|
11
|
+
html_options[:class] ||= "inputs"
|
12
|
+
html_options[:name] = title
|
13
|
+
|
14
|
+
out = begin
|
15
|
+
if html_options[:for] # Nested form
|
16
|
+
inputs_for_nested_attributes(*(args << html_options), &block)
|
17
|
+
elsif block_given?
|
18
|
+
field_set_and_list_wrapping(*(args << html_options), &block)
|
19
|
+
else
|
20
|
+
legend = args.shift if args.first.is_a?(::String)
|
21
|
+
args = default_columns_for_object if @object && args.empty?
|
22
|
+
contents = fieldset_contents_from_column_list(args)
|
23
|
+
args.unshift(legend) if legend.present?
|
24
|
+
field_set_and_list_wrapping(*((args << html_options) << contents))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
@already_in_an_inputs_block = false
|
29
|
+
out
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module FormtasticBootstrap
|
2
|
+
module Inputs
|
3
|
+
|
4
|
+
autoload :Base, "formtastic-bootstrap/inputs/base"
|
5
|
+
# autoload :Basic
|
6
|
+
autoload :BooleanInput, "formtastic-bootstrap/inputs/boolean_input"
|
7
|
+
autoload :CheckBoxesInput, "formtastic-bootstrap/inputs/check_boxes_input"
|
8
|
+
autoload :CountryInput, "formtastic-bootstrap/inputs/country_input"
|
9
|
+
autoload :DateInput, "formtastic-bootstrap/inputs/date_input"
|
10
|
+
autoload :DatePickerInput, "formtastic-bootstrap/inputs/date_picker_input"
|
11
|
+
autoload :DatetimePickerInput, "formtastic-bootstrap/inputs/datetime_picker_input"
|
12
|
+
autoload :DateSelectInput, "formtastic-bootstrap/inputs/date_select_input"
|
13
|
+
autoload :DatetimeInput, "formtastic-bootstrap/inputs/datetime_input"
|
14
|
+
autoload :DatetimeSelectInput, "formtastic-bootstrap/inputs/datetime_select_input"
|
15
|
+
autoload :EmailInput, "formtastic-bootstrap/inputs/email_input"
|
16
|
+
autoload :FileInput, "formtastic-bootstrap/inputs/file_input"
|
17
|
+
autoload :HiddenInput, "formtastic-bootstrap/inputs/hidden_input"
|
18
|
+
autoload :NumberInput, "formtastic-bootstrap/inputs/number_input"
|
19
|
+
# autoload :NumericInput # TODO Where does Formtastic actually define this?
|
20
|
+
autoload :PasswordInput, "formtastic-bootstrap/inputs/password_input"
|
21
|
+
autoload :PhoneInput, "formtastic-bootstrap/inputs/phone_input"
|
22
|
+
autoload :RadioInput, "formtastic-bootstrap/inputs/radio_input"
|
23
|
+
autoload :RangeInput, "formtastic-bootstrap/inputs/range_input"
|
24
|
+
autoload :SearchInput, "formtastic-bootstrap/inputs/search_input"
|
25
|
+
autoload :SelectInput, "formtastic-bootstrap/inputs/select_input"
|
26
|
+
autoload :StringInput, "formtastic-bootstrap/inputs/string_input"
|
27
|
+
autoload :TextInput, "formtastic-bootstrap/inputs/text_input"
|
28
|
+
autoload :TimeInput, "formtastic-bootstrap/inputs/time_input"
|
29
|
+
# autoload :TimePickerInput # TODO Come back to this.
|
30
|
+
autoload :TimeSelectInput, "formtastic-bootstrap/inputs/time_select_input"
|
31
|
+
autoload :TimeZoneInput, "formtastic-bootstrap/inputs/time_zone_input"
|
32
|
+
# autoload :Timeish # This seems like a mistake.
|
33
|
+
autoload :UrlInput, "formtastic-bootstrap/inputs/url_input"
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "formtastic-bootstrap/inputs/base/errors"
|
2
|
+
require "formtastic-bootstrap/inputs/base/hints"
|
3
|
+
require "formtastic-bootstrap/inputs/base/html"
|
4
|
+
require "formtastic-bootstrap/inputs/base/labelling"
|
5
|
+
|
6
|
+
module FormtasticBootstrap
|
7
|
+
module Inputs
|
8
|
+
module Base
|
9
|
+
|
10
|
+
autoload :DatetimePickerish, "formtastic-bootstrap/inputs/base/datetime_pickerish"
|
11
|
+
# autoload :Associations
|
12
|
+
autoload :Collections, "formtastic-bootstrap/inputs/base/collections"
|
13
|
+
autoload :Choices, "formtastic-bootstrap/inputs/base/choices"
|
14
|
+
# autoload :Database
|
15
|
+
# autoload :Errors
|
16
|
+
# autoload :Fileish
|
17
|
+
autoload :GroupedCollections, "formtastic-bootstrap/inputs/base/grouped_collections"
|
18
|
+
# autoload :Hints
|
19
|
+
# autoload :Html
|
20
|
+
# autoload :Labelling
|
21
|
+
# autoload :Naming
|
22
|
+
autoload :Numeric, "formtastic-bootstrap/inputs/base/numeric"
|
23
|
+
# autoload :Options
|
24
|
+
autoload :Placeholder, "formtastic-bootstrap/inputs/base/placeholder"
|
25
|
+
autoload :Stringish, "formtastic-bootstrap/inputs/base/stringish"
|
26
|
+
autoload :Timeish, "formtastic-bootstrap/inputs/base/timeish"
|
27
|
+
# autoload :Validations
|
28
|
+
autoload :Wrapping, "formtastic-bootstrap/inputs/base/wrapping"
|
29
|
+
|
30
|
+
include Html
|
31
|
+
# include Options
|
32
|
+
# include Database
|
33
|
+
# include Database
|
34
|
+
include Errors
|
35
|
+
include Hints
|
36
|
+
# include Naming
|
37
|
+
# include Validations
|
38
|
+
# include Fileish
|
39
|
+
# include Associations
|
40
|
+
include Labelling
|
41
|
+
include Wrapping
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module FormtasticBootstrap
|
2
|
+
module Inputs
|
3
|
+
module Base
|
4
|
+
module Choices
|
5
|
+
include Formtastic::Inputs::Base::Choices
|
6
|
+
|
7
|
+
def choice_wrapping_html_options(choice)
|
8
|
+
super(choice).tap do |options|
|
9
|
+
options[:for] = choice_input_dom_id(choice)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def choice_label_html_options(choice)
|
14
|
+
choice_wrapping_html_options(choice)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module FormtasticBootstrap
|
2
|
+
module Inputs
|
3
|
+
module Base
|
4
|
+
module Errors
|
5
|
+
|
6
|
+
include Formtastic::Inputs::Base::Errors
|
7
|
+
|
8
|
+
def error_html(inline_or_block = :inline)
|
9
|
+
errors? ? send(:"error_#{builder.inline_errors}_html", inline_or_block) : ""
|
10
|
+
end
|
11
|
+
|
12
|
+
def error_sentence_html(inline_or_block)
|
13
|
+
error_class = if inline_or_block == :inline
|
14
|
+
options[:error_class] || builder.default_inline_error_class
|
15
|
+
else
|
16
|
+
options[:error_class] || builder.default_block_error_class
|
17
|
+
end
|
18
|
+
template.content_tag(:span, Formtastic::Util.html_safe(errors.to_sentence.html_safe), :class => error_class)
|
19
|
+
end
|
20
|
+
|
21
|
+
def error_list_html(ignore)
|
22
|
+
super()
|
23
|
+
# error_class = options[:error_class] || builder.default_error_list_class
|
24
|
+
# list_elements = []
|
25
|
+
# errors.each do |error|
|
26
|
+
# list_elements << template.content_tag(:li, Formtastic::Util.html_safe(error.html_safe))
|
27
|
+
# end
|
28
|
+
# template.content_tag(:ul, Formtastic::Util.html_safe(list_elements.join("\n")), :class => error_class)
|
29
|
+
end
|
30
|
+
|
31
|
+
def error_first_html(inline_or_block = :inline)
|
32
|
+
error_class = if inline_or_block == :inline
|
33
|
+
options[:error_class] || builder.default_inline_error_class
|
34
|
+
else
|
35
|
+
options[:error_class] || builder.default_block_error_class
|
36
|
+
end
|
37
|
+
template.content_tag(:span, Formtastic::Util.html_safe(errors.first.untaint), :class => error_class)
|
38
|
+
end
|
39
|
+
|
40
|
+
def error_none_html(ignore)
|
41
|
+
# super
|
42
|
+
""
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module FormtasticBootstrap
|
2
|
+
module Inputs
|
3
|
+
module Base
|
4
|
+
module Hints
|
5
|
+
|
6
|
+
include Formtastic::Inputs::Base::Hints
|
7
|
+
|
8
|
+
def hint_html(inline_or_block = :block)
|
9
|
+
if hint?
|
10
|
+
hint_class = if inline_or_block == :inline
|
11
|
+
options[:hint_class] || builder.default_inline_hint_class
|
12
|
+
else
|
13
|
+
options[:hint_class] || builder.default_block_hint_class
|
14
|
+
end
|
15
|
+
template.content_tag(
|
16
|
+
:span,
|
17
|
+
Formtastic::Util.html_safe(hint_text),
|
18
|
+
:class => hint_class
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module FormtasticBootstrap
|
2
|
+
module Inputs
|
3
|
+
module Base
|
4
|
+
module Html
|
5
|
+
|
6
|
+
include Formtastic::Inputs::Base::Html
|
7
|
+
|
8
|
+
def input_html_options
|
9
|
+
if errors?
|
10
|
+
{
|
11
|
+
:class => "error"
|
12
|
+
}.merge(super)
|
13
|
+
else
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module FormtasticBootstrap
|
2
|
+
module Inputs
|
3
|
+
module Base
|
4
|
+
module Labelling
|
5
|
+
|
6
|
+
include Formtastic::Inputs::Base::Labelling
|
7
|
+
|
8
|
+
def label_html_options
|
9
|
+
super.tap do |options|
|
10
|
+
# Bootstrap defines class 'label'
|
11
|
+
options[:class] = options[:class].reject { |c| c == 'label' }
|
12
|
+
# options[:class] << "control-label"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def control_label_html_options
|
17
|
+
label_html_options.tap do |options|
|
18
|
+
options[:class] << "control-label"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def control_label_html
|
23
|
+
render_label? ? builder.label(input_name, label_text, control_label_html_options) : "".html_safe
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module FormtasticBootstrap
|
2
|
+
module Inputs
|
3
|
+
module Base
|
4
|
+
module Stringish
|
5
|
+
|
6
|
+
include Formtastic::Inputs::Base::Stringish
|
7
|
+
|
8
|
+
def to_html
|
9
|
+
bootstrap_wrapping do
|
10
|
+
builder.text_field(method, input_html_options)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module FormtasticBootstrap
|
2
|
+
module Inputs
|
3
|
+
module Base
|
4
|
+
module Timeish
|
5
|
+
|
6
|
+
def to_html
|
7
|
+
control_group_wrapping do
|
8
|
+
control_label_html <<
|
9
|
+
controls_wrapping do
|
10
|
+
hidden_fragments <<
|
11
|
+
fragments.map do |fragment|
|
12
|
+
fragment_input_html(fragment)
|
13
|
+
end.join.html_safe
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def controls_wrapper_html_options
|
19
|
+
super.tap do |options|
|
20
|
+
options[:class] = (options[:class].split << "controls-row").join(" ")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def fragment_input_html(fragment)
|
25
|
+
opts = input_options.merge(:prefix => fragment_prefix, :field_name => fragment_name(fragment), :default => value, :include_blank => include_blank?)
|
26
|
+
template.send(:"select_#{fragment}", value, opts, fragment_input_html_options(fragment))
|
27
|
+
end
|
28
|
+
|
29
|
+
def fragment_input_html_options(fragment)
|
30
|
+
input_html_options.tap do |options|
|
31
|
+
options[:id] = fragment_id(fragment)
|
32
|
+
options[:class] = ((options[:class] || "").split << fragment_class(fragment)).join(" ")
|
33
|
+
options[:placeholder] = fragment_placeholder(fragment)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def fragment_class(fragment)
|
38
|
+
{
|
39
|
+
:year => "span1",
|
40
|
+
:month => "span2",
|
41
|
+
:day => "span1",
|
42
|
+
:hour => "span1",
|
43
|
+
:minute => "span1",
|
44
|
+
:second => "span1"
|
45
|
+
}[fragment]
|
46
|
+
end
|
47
|
+
|
48
|
+
def fragment_placeholder(fragment)
|
49
|
+
"." + fragment_class(fragment)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module FormtasticBootstrap
|
2
|
+
module Inputs
|
3
|
+
module Base
|
4
|
+
module Wrapping
|
5
|
+
|
6
|
+
include Formtastic::Inputs::Base::Wrapping
|
7
|
+
|
8
|
+
def bootstrap_wrapping(&block)
|
9
|
+
control_group_wrapping do
|
10
|
+
control_label_html <<
|
11
|
+
controls_wrapping do
|
12
|
+
if options[:prepend] || options[:append]
|
13
|
+
if options[:prepend] && options[:append]
|
14
|
+
prepended_and_appended_input_wrapping do
|
15
|
+
[template.content_tag(:span, options[:prepend], :class => 'add-on'), yield, template.content_tag(:span, options[:append], :class => 'add-on'), hint_html].join("\n").html_safe
|
16
|
+
end
|
17
|
+
elsif options[:prepend]
|
18
|
+
prepended_input_wrapping do
|
19
|
+
[template.content_tag(:span, options[:prepend], :class => 'add-on'), yield, hint_html].join("\n").html_safe
|
20
|
+
end
|
21
|
+
elsif options[:append]
|
22
|
+
appended_input_wrapping do
|
23
|
+
[yield, template.content_tag(:span, options[:append], :class => 'add-on'), hint_html].join("\n").html_safe
|
24
|
+
end
|
25
|
+
end
|
26
|
+
else
|
27
|
+
[yield, hint_html].join("\n").html_safe
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def control_group_wrapping(&block)
|
34
|
+
template.content_tag(:div,
|
35
|
+
template.capture(&block).html_safe,
|
36
|
+
wrapper_html_options
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def controls_wrapping(&block)
|
41
|
+
template.content_tag(:div,
|
42
|
+
[template.capture(&block), error_html].join("\n").html_safe,
|
43
|
+
controls_wrapper_html_options
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
def controls_wrapper_html_options
|
48
|
+
{
|
49
|
+
:class => "controls"
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def wrapper_html_options
|
54
|
+
super.tap do |options|
|
55
|
+
options[:class] << " control-group"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Bootstrap prepend feature
|
60
|
+
def prepended_input_wrapping(&block)
|
61
|
+
template.content_tag(:div, :class => 'input-prepend') do
|
62
|
+
yield
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Bootstrap append feature
|
67
|
+
def appended_input_wrapping(&block)
|
68
|
+
template.content_tag(:div, :class => 'input-append') do
|
69
|
+
yield
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Bootstrap prepend and append feature
|
74
|
+
def prepended_and_appended_input_wrapping(&block)
|
75
|
+
template.content_tag(:div, :class => 'input-prepend input-append') do
|
76
|
+
yield
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|