formtastic-bootstrap 1.0.0
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/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +123 -0
- data/LICENSE.txt +20 -0
- data/README.md +159 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/formtastic-bootstrap.gemspec +128 -0
- data/lib/action_view/helpers/text_field_date_helper.rb +166 -0
- data/lib/formtastic-bootstrap.rb +5 -0
- data/lib/formtastic-bootstrap/form_builder.rb +38 -0
- data/lib/formtastic-bootstrap/helpers.rb +19 -0
- data/lib/formtastic-bootstrap/helpers/buttons_helper.rb +47 -0
- data/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb +37 -0
- data/lib/formtastic-bootstrap/helpers/input_helper.rb +12 -0
- data/lib/formtastic-bootstrap/helpers/inputs_helper.rb +36 -0
- data/lib/formtastic-bootstrap/inputs.rb +28 -0
- data/lib/formtastic-bootstrap/inputs/base.rb +22 -0
- data/lib/formtastic-bootstrap/inputs/base/choices.rb +49 -0
- data/lib/formtastic-bootstrap/inputs/base/errors.rb +48 -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 +18 -0
- data/lib/formtastic-bootstrap/inputs/base/stringish.rb +18 -0
- data/lib/formtastic-bootstrap/inputs/base/timeish.rb +35 -0
- data/lib/formtastic-bootstrap/inputs/base/wrapping.rb +56 -0
- data/lib/formtastic-bootstrap/inputs/boolean_input.rb +33 -0
- data/lib/formtastic-bootstrap/inputs/check_boxes_input.rb +35 -0
- data/lib/formtastic-bootstrap/inputs/date_input.rb +16 -0
- data/lib/formtastic-bootstrap/inputs/datetime_input.rb +19 -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 +32 -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 +14 -0
- data/lib/formtastic-bootstrap/inputs/string_input.rb +15 -0
- data/lib/formtastic-bootstrap/inputs/text_input.rb +14 -0
- data/lib/formtastic-bootstrap/inputs/time_input.rb +16 -0
- data/lib/formtastic-bootstrap/inputs/url_input.rb +14 -0
- data/spec/builder/errors_spec.rb +214 -0
- data/spec/builder/semantic_fields_for_spec.rb +130 -0
- data/spec/helpers/input_helper_spec.rb +956 -0
- data/spec/helpers/inputs_helper_spec.rb +577 -0
- data/spec/inputs/boolean_input_spec.rb +193 -0
- data/spec/inputs/check_boxes_input_spec.rb +439 -0
- data/spec/inputs/date_input_spec.rb +147 -0
- data/spec/inputs/datetime_input_spec.rb +101 -0
- data/spec/inputs/email_input_spec.rb +59 -0
- data/spec/inputs/file_input_spec.rb +63 -0
- data/spec/inputs/hidden_input_spec.rb +122 -0
- data/spec/inputs/number_input_spec.rb +787 -0
- data/spec/inputs/password_input_spec.rb +73 -0
- data/spec/inputs/phone_input_spec.rb +59 -0
- data/spec/inputs/radio_input_spec.rb +240 -0
- data/spec/inputs/range_input_spec.rb +479 -0
- data/spec/inputs/search_input_spec.rb +59 -0
- data/spec/inputs/select_input_spec.rb +567 -0
- data/spec/inputs/string_input_spec.rb +182 -0
- data/spec/inputs/text_input_spec.rb +163 -0
- data/spec/inputs/time_input_spec.rb +206 -0
- data/spec/inputs/url_input_spec.rb +59 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/support/custom_macros.rb +704 -0
- data/spec/support/depracation.rb +6 -0
- data/spec/support/formtastic_spec_helper.rb +382 -0
- metadata +204 -0
@@ -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 = :inline)
|
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,18 @@
|
|
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
|
+
{}.tap do |opts|
|
10
|
+
opts[:for] ||= input_html_options[:id]
|
11
|
+
opts[:class] = [opts[:class]]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Alas, I need to duplicate code from Formtastic::Inputs::Base::Stringish because
|
2
|
+
# there's no way to re-import that module.
|
3
|
+
module FormtasticBootstrap
|
4
|
+
module Inputs
|
5
|
+
module Base
|
6
|
+
module Stringish
|
7
|
+
|
8
|
+
include Formtastic::Inputs::Base::Stringish
|
9
|
+
|
10
|
+
def wrapper_html_options
|
11
|
+
new_class = [super[:class], "stringish"].compact.join(" ")
|
12
|
+
super.merge(:class => new_class)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module FormtasticBootstrap
|
2
|
+
module Inputs
|
3
|
+
module Base
|
4
|
+
module Timeish
|
5
|
+
|
6
|
+
def label_html
|
7
|
+
# TODO Supress the "for" field?
|
8
|
+
template.content_tag(:label, label_html_options) do
|
9
|
+
render_label? ? label_text : "".html_safe
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def date_input_html
|
14
|
+
fragment_input_html(:date, "small")
|
15
|
+
end
|
16
|
+
|
17
|
+
def time_input_html
|
18
|
+
fragment_input_html(:time, "mini")
|
19
|
+
end
|
20
|
+
|
21
|
+
def fragment_id(fragment)
|
22
|
+
# TODO is this right?
|
23
|
+
# "#{input_html_options[:id]}_#{position(fragment)}i"
|
24
|
+
"#{input_html_options[:id]}[#{fragment}]"
|
25
|
+
end
|
26
|
+
|
27
|
+
def fragment_input_html(fragment, klass)
|
28
|
+
opts = input_options.merge(:prefix => object_name, :field_name => fragment_name(fragment), :default => value, :include_blank => include_blank?)
|
29
|
+
template.send(:"text_field_#{fragment}", value, opts, input_html_options.merge(:id => fragment_id(fragment), :class => klass))
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module FormtasticBootstrap
|
2
|
+
module Inputs
|
3
|
+
module Base
|
4
|
+
module Wrapping
|
5
|
+
|
6
|
+
include Formtastic::Inputs::Base::Wrapping
|
7
|
+
|
8
|
+
def generic_input_wrapping(&block)
|
9
|
+
clearfix_div_wrapping do
|
10
|
+
label_html <<
|
11
|
+
input_div_wrapping do
|
12
|
+
yield
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def clearfix_div_wrapping(&block)
|
18
|
+
template.content_tag(:div, wrapper_html_options) do
|
19
|
+
yield
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def input_div_wrapping(inline_or_block_errors = :inline)
|
24
|
+
template.content_tag(:div, :class => "input") do
|
25
|
+
[yield, error_html(inline_or_block_errors), hint_html(inline_or_block_errors)].join("\n").html_safe
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def inline_inputs_div_wrapping(&block)
|
30
|
+
template.content_tag(:div, :class => "inline-inputs") do
|
31
|
+
yield
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def wrapper_html_options
|
36
|
+
opts = options[:wrapper_html] || {}
|
37
|
+
opts[:class] ||= []
|
38
|
+
opts[:class] = [opts[:class].to_s] unless opts[:class].is_a?(Array)
|
39
|
+
opts[:class] << as
|
40
|
+
opts[:class] << "clearfix"
|
41
|
+
# opts[:class] << "input"
|
42
|
+
opts[:class] << "error" if errors?
|
43
|
+
opts[:class] << "optional" if optional?
|
44
|
+
opts[:class] << "required" if required?
|
45
|
+
opts[:class] << "autofocus" if autofocus?
|
46
|
+
opts[:class] = opts[:class].join(' ')
|
47
|
+
|
48
|
+
opts[:id] ||= wrapper_dom_id
|
49
|
+
|
50
|
+
opts
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# TODO See if this can be refactored to make use of some of the Choices code.
|
2
|
+
module FormtasticBootstrap
|
3
|
+
module Inputs
|
4
|
+
class BooleanInput < Formtastic::Inputs::BooleanInput
|
5
|
+
include Base
|
6
|
+
|
7
|
+
def to_html
|
8
|
+
clearfix_div_wrapping do
|
9
|
+
empty_label <<
|
10
|
+
hidden_field_html <<
|
11
|
+
input_div_wrapping(:block) do
|
12
|
+
template.content_tag(:ul, :class => "inputs-list") do
|
13
|
+
template.content_tag(:li) do
|
14
|
+
label_with_nested_checkbox
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def label_text_with_embedded_checkbox
|
22
|
+
# That newline matters! Why, I do no not know.
|
23
|
+
check_box_html << "\n" << template.content_tag(:span) do label_text end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Need this for formatting to work.
|
27
|
+
def empty_label
|
28
|
+
template.content_tag(:label) do end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module FormtasticBootstrap
|
2
|
+
module Inputs
|
3
|
+
class CheckBoxesInput < Formtastic::Inputs::CheckBoxesInput
|
4
|
+
include Base
|
5
|
+
include Base::Choices
|
6
|
+
|
7
|
+
def to_html
|
8
|
+
clearfix_div_wrapping do
|
9
|
+
legend_html <<
|
10
|
+
hidden_field_for_all <<
|
11
|
+
input_div_wrapping do
|
12
|
+
choices_group_wrapping do
|
13
|
+
collection.map { |choice|
|
14
|
+
choice_wrapping(choice_wrapping_html_options(choice)) do
|
15
|
+
choice_html(choice)
|
16
|
+
end
|
17
|
+
}.join("\n").html_safe
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def choice_html(choice)
|
24
|
+
template.content_tag(:label,
|
25
|
+
hidden_fields? ?
|
26
|
+
check_box_with_hidden_input(choice) :
|
27
|
+
check_box_without_hidden_input(choice) <<
|
28
|
+
choice_label(choice),
|
29
|
+
label_html_options.merge(:for => choice_input_dom_id(choice), :class => nil)
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module FormtasticBootstrap
|
2
|
+
module Inputs
|
3
|
+
class DateInput < Formtastic::Inputs::DateInput
|
4
|
+
include Base
|
5
|
+
include Base::Stringish
|
6
|
+
include Base::Timeish
|
7
|
+
|
8
|
+
def to_html
|
9
|
+
generic_input_wrapping do
|
10
|
+
date_input_html
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module FormtasticBootstrap
|
2
|
+
module Inputs
|
3
|
+
class DatetimeInput < Formtastic::Inputs::DatetimeInput
|
4
|
+
include Base
|
5
|
+
include Base::Stringish
|
6
|
+
include Base::Timeish
|
7
|
+
|
8
|
+
def to_html
|
9
|
+
generic_input_wrapping do
|
10
|
+
inline_inputs_div_wrapping do
|
11
|
+
# This newline matters.
|
12
|
+
date_input_html << "\n".html_safe << time_input_html
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module FormtasticBootstrap
|
2
|
+
module Inputs
|
3
|
+
class EmailInput < Formtastic::Inputs::EmailInput
|
4
|
+
include Base
|
5
|
+
include Base::Stringish
|
6
|
+
|
7
|
+
def to_html
|
8
|
+
generic_input_wrapping do
|
9
|
+
builder.email_field(method, input_html_options)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module FormtasticBootstrap
|
2
|
+
module Inputs
|
3
|
+
class NumberInput < Formtastic::Inputs::NumberInput
|
4
|
+
include Base
|
5
|
+
include Base::Stringish
|
6
|
+
|
7
|
+
def to_html
|
8
|
+
generic_input_wrapping do
|
9
|
+
builder.number_field(method, input_html_options)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module FormtasticBootstrap
|
2
|
+
module Inputs
|
3
|
+
class PasswordInput < Formtastic::Inputs::PasswordInput
|
4
|
+
include Base
|
5
|
+
include Base::Stringish
|
6
|
+
|
7
|
+
def to_html
|
8
|
+
generic_input_wrapping do
|
9
|
+
builder.password_field(method, input_html_options)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module FormtasticBootstrap
|
2
|
+
module Inputs
|
3
|
+
class PhoneInput < Formtastic::Inputs::PhoneInput
|
4
|
+
include Base
|
5
|
+
include Base::Stringish
|
6
|
+
|
7
|
+
def to_html
|
8
|
+
generic_input_wrapping do
|
9
|
+
builder.phone_field(method, input_html_options)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module FormtasticBootstrap
|
2
|
+
module Inputs
|
3
|
+
class RadioInput < Formtastic::Inputs::RadioInput
|
4
|
+
include Base
|
5
|
+
include Base::Choices
|
6
|
+
|
7
|
+
def to_html
|
8
|
+
clearfix_div_wrapping do
|
9
|
+
legend_html <<
|
10
|
+
input_div_wrapping do
|
11
|
+
choices_group_wrapping do
|
12
|
+
collection.map { |choice|
|
13
|
+
choice_wrapping(choice_wrapping_html_options(choice)) do
|
14
|
+
choice_html(choice)
|
15
|
+
end
|
16
|
+
}.join("\n").html_safe
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def choice_html(choice)
|
23
|
+
template.content_tag(:label, label_html_options.merge(:for => choice_input_dom_id(choice), :class => nil)) do
|
24
|
+
builder.radio_button(input_name, choice_value(choice), input_html_options.merge(choice_html_options(choice)).merge(:required => false)) <<
|
25
|
+
|
26
|
+
choice_label(choice)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|