speedo-formstrap 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +13 -0
  4. data/Gemfile.lock +117 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.md +192 -0
  7. data/Rakefile +49 -0
  8. data/VERSION +1 -0
  9. data/formtastic-bootstrap.gemspec +56 -0
  10. data/lib/action_view/helpers/text_field_date_helper.rb +166 -0
  11. data/lib/formtastic-bootstrap.rb +7 -0
  12. data/lib/formtastic-bootstrap/actions.rb +4 -0
  13. data/lib/formtastic-bootstrap/actions/base.rb +18 -0
  14. data/lib/formtastic-bootstrap/actions/button_action.rb +7 -0
  15. data/lib/formtastic-bootstrap/actions/input_action.rb +7 -0
  16. data/lib/formtastic-bootstrap/actions/link_action.rb +7 -0
  17. data/lib/formtastic-bootstrap/engine.rb +4 -0
  18. data/lib/formtastic-bootstrap/form_builder.rb +40 -0
  19. data/lib/formtastic-bootstrap/helpers.rb +21 -0
  20. data/lib/formtastic-bootstrap/helpers/action_helper.rb +12 -0
  21. data/lib/formtastic-bootstrap/helpers/actions_helper.rb +23 -0
  22. data/lib/formtastic-bootstrap/helpers/buttons_helper.rb +56 -0
  23. data/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb +42 -0
  24. data/lib/formtastic-bootstrap/helpers/input_helper.rb +12 -0
  25. data/lib/formtastic-bootstrap/helpers/inputs_helper.rb +36 -0
  26. data/lib/formtastic-bootstrap/inputs.rb +29 -0
  27. data/lib/formtastic-bootstrap/inputs/base.rb +23 -0
  28. data/lib/formtastic-bootstrap/inputs/base/choices.rb +38 -0
  29. data/lib/formtastic-bootstrap/inputs/base/errors.rb +48 -0
  30. data/lib/formtastic-bootstrap/inputs/base/hints.rb +27 -0
  31. data/lib/formtastic-bootstrap/inputs/base/html.rb +21 -0
  32. data/lib/formtastic-bootstrap/inputs/base/labelling.rb +28 -0
  33. data/lib/formtastic-bootstrap/inputs/base/numeric.rb +18 -0
  34. data/lib/formtastic-bootstrap/inputs/base/stringish.rb +18 -0
  35. data/lib/formtastic-bootstrap/inputs/base/timeish.rb +28 -0
  36. data/lib/formtastic-bootstrap/inputs/base/wrapping.rb +74 -0
  37. data/lib/formtastic-bootstrap/inputs/boolean_input.rb +29 -0
  38. data/lib/formtastic-bootstrap/inputs/check_boxes_input.rb +36 -0
  39. data/lib/formtastic-bootstrap/inputs/date_input.rb +16 -0
  40. data/lib/formtastic-bootstrap/inputs/datetime_input.rb +19 -0
  41. data/lib/formtastic-bootstrap/inputs/email_input.rb +15 -0
  42. data/lib/formtastic-bootstrap/inputs/file_input.rb +14 -0
  43. data/lib/formtastic-bootstrap/inputs/hidden_input.rb +14 -0
  44. data/lib/formtastic-bootstrap/inputs/number_input.rb +15 -0
  45. data/lib/formtastic-bootstrap/inputs/password_input.rb +15 -0
  46. data/lib/formtastic-bootstrap/inputs/phone_input.rb +15 -0
  47. data/lib/formtastic-bootstrap/inputs/radio_input.rb +33 -0
  48. data/lib/formtastic-bootstrap/inputs/range_input.rb +15 -0
  49. data/lib/formtastic-bootstrap/inputs/search_input.rb +15 -0
  50. data/lib/formtastic-bootstrap/inputs/select_input.rb +14 -0
  51. data/lib/formtastic-bootstrap/inputs/string_input.rb +15 -0
  52. data/lib/formtastic-bootstrap/inputs/text_input.rb +14 -0
  53. data/lib/formtastic-bootstrap/inputs/time_input.rb +16 -0
  54. data/lib/formtastic-bootstrap/inputs/time_zone_input.rb +14 -0
  55. data/lib/formtastic-bootstrap/inputs/url_input.rb +14 -0
  56. data/spec/actions/button_action_spec.rb +68 -0
  57. data/spec/actions/generic_action_spec.rb +486 -0
  58. data/spec/actions/input_action_spec.rb +64 -0
  59. data/spec/actions/link_action_spec.rb +93 -0
  60. data/spec/builder/semantic_fields_for_spec.rb +130 -0
  61. data/spec/helpers/action_helper_spec.rb +365 -0
  62. data/spec/helpers/actions_helper_spec.rb +143 -0
  63. data/spec/helpers/buttons_helper_spec.rb +159 -0
  64. data/spec/helpers/input_helper_spec.rb +956 -0
  65. data/spec/helpers/inputs_helper_spec.rb +591 -0
  66. data/spec/inputs/boolean_input_spec.rb +221 -0
  67. data/spec/inputs/check_boxes_input_spec.rb +467 -0
  68. data/spec/inputs/date_input_spec.rb +213 -0
  69. data/spec/inputs/datetime_input_spec.rb +101 -0
  70. data/spec/inputs/email_input_spec.rb +87 -0
  71. data/spec/inputs/file_input_spec.rb +91 -0
  72. data/spec/inputs/hidden_input_spec.rb +150 -0
  73. data/spec/inputs/number_input_spec.rb +817 -0
  74. data/spec/inputs/password_input_spec.rb +101 -0
  75. data/spec/inputs/phone_input_spec.rb +87 -0
  76. data/spec/inputs/radio_input_spec.rb +268 -0
  77. data/spec/inputs/range_input_spec.rb +507 -0
  78. data/spec/inputs/search_input_spec.rb +86 -0
  79. data/spec/inputs/select_input_spec.rb +613 -0
  80. data/spec/inputs/string_input_spec.rb +227 -0
  81. data/spec/inputs/text_input_spec.rb +190 -0
  82. data/spec/inputs/time_input_spec.rb +206 -0
  83. data/spec/inputs/time_zone_input_spec.rb +120 -0
  84. data/spec/inputs/url_input_spec.rb +87 -0
  85. data/spec/spec_helper.rb +24 -0
  86. data/spec/support/custom_macros.rb +575 -0
  87. data/spec/support/depracation.rb +6 -0
  88. data/spec/support/formtastic_spec_helper.rb +398 -0
  89. metadata +216 -0
@@ -0,0 +1,36 @@
1
+ module FormtasticBootstrap
2
+ module Helpers
3
+ module InputsHelper
4
+ include FormtasticBootstrap::Helpers::FieldsetWrapper
5
+
6
+ def inputs(*args, &block)
7
+ wrap_it = @already_in_an_inputs_block ? true : false
8
+ @already_in_an_inputs_block = true
9
+
10
+ title = field_set_title_from_args(*args)
11
+ html_options = args.extract_options!
12
+ html_options[:class] ||= "inputs"
13
+ html_options[:name] = title
14
+
15
+ out = begin
16
+ if html_options[:for] # Nested form
17
+ inputs_for_nested_attributes(*(args << html_options), &block)
18
+ elsif block_given?
19
+ field_set_and_list_wrapping(*(args << html_options), &block)
20
+ else
21
+ legend = args.shift if args.first.is_a?(::String)
22
+ args = default_columns_for_object if @object && args.empty?
23
+ contents = fieldset_contents_from_column_list(args)
24
+ args.unshift(legend) if legend.present?
25
+ field_set_and_list_wrapping(*((args << html_options) << contents))
26
+ end
27
+ end
28
+
29
+ # out = template.content_tag(:li, out, :class => "input") if wrap_it
30
+ @already_in_an_inputs_block = wrap_it
31
+ out
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,29 @@
1
+ require "formtastic-bootstrap/inputs/base"
2
+ require "formtastic-bootstrap/inputs/boolean_input"
3
+ require "formtastic-bootstrap/inputs/check_boxes_input"
4
+ require "formtastic-bootstrap/inputs/date_input"
5
+ require "formtastic-bootstrap/inputs/datetime_input"
6
+ require "formtastic-bootstrap/inputs/email_input"
7
+ require "formtastic-bootstrap/inputs/file_input"
8
+ require "formtastic-bootstrap/inputs/hidden_input"
9
+ require "formtastic-bootstrap/inputs/number_input"
10
+ require "formtastic-bootstrap/inputs/password_input"
11
+ require "formtastic-bootstrap/inputs/phone_input"
12
+ require "formtastic-bootstrap/inputs/radio_input"
13
+ require "formtastic-bootstrap/inputs/range_input"
14
+ require "formtastic-bootstrap/inputs/search_input"
15
+ require "formtastic-bootstrap/inputs/select_input"
16
+ require "formtastic-bootstrap/inputs/string_input"
17
+ require "formtastic-bootstrap/inputs/text_input"
18
+ require "formtastic-bootstrap/inputs/time_input"
19
+ require "formtastic-bootstrap/inputs/time_zone_input"
20
+ require "formtastic-bootstrap/inputs/url_input"
21
+
22
+ module FormtasticBootstrap
23
+ module Inputs
24
+
25
+ include Base
26
+
27
+ end
28
+ end
29
+
@@ -0,0 +1,23 @@
1
+ require "formtastic-bootstrap/inputs/base/choices"
2
+ require "formtastic-bootstrap/inputs/base/errors"
3
+ require "formtastic-bootstrap/inputs/base/hints"
4
+ require "formtastic-bootstrap/inputs/base/html"
5
+ require "formtastic-bootstrap/inputs/base/labelling"
6
+ require "formtastic-bootstrap/inputs/base/numeric"
7
+ require "formtastic-bootstrap/inputs/base/stringish"
8
+ require "formtastic-bootstrap/inputs/base/timeish"
9
+ require "formtastic-bootstrap/inputs/base/wrapping"
10
+
11
+ module FormtasticBootstrap
12
+ module Inputs
13
+ module Base
14
+
15
+ include Errors
16
+ include Hints
17
+ include Html
18
+ include Labelling
19
+ include Wrapping
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,38 @@
1
+ module FormtasticBootstrap
2
+ module Inputs
3
+ module Base
4
+ module Choices
5
+
6
+ def input_div_wrapping(&block)
7
+ template.content_tag(:div, choices_wrapping_html_options) do
8
+ [yield, error_html(:block), hint_html(:block)].join("\n").html_safe
9
+ end
10
+ end
11
+
12
+ def choices_wrapping_html_options
13
+ new_class = [super[:class], "controls"].compact.join(" ")
14
+ super.merge(:class => new_class)
15
+ end
16
+
17
+ #def choices_group_wrapping(&block)
18
+ # template.content_tag(:ul,
19
+ # template.capture(&block),
20
+ # choices_group_wrapping_html_options
21
+ # )
22
+ #end
23
+
24
+ # This is actually a label in Bootstrap.
25
+ def legend_html
26
+ template.content_tag(:label, control_label_html_options) do
27
+ render_label? ? label_text : "".html_safe
28
+ end
29
+ end
30
+
31
+ def control_label_html_options
32
+ super.merge(:for => nil)
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+ 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 = :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,28 @@
1
+ module FormtasticBootstrap
2
+ module Inputs
3
+ module Base
4
+ module Labelling
5
+
6
+ include Formtastic::Inputs::Base::Labelling
7
+
8
+ def label_html
9
+ render_label? ? builder.label(input_name, label_text, control_label_html_options) : "".html_safe
10
+ end
11
+
12
+ def label_html_options
13
+ opts = {}
14
+ opts[:for] ||= input_html_options[:id]
15
+ opts[:class] = [opts[:class]]
16
+
17
+ opts
18
+ end
19
+
20
+ def control_label_html_options
21
+ new_class = [label_html_options[:class], "control-label"].compact.join(" ")
22
+ label_html_options.merge(:class => new_class)
23
+ end
24
+
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,18 @@
1
+ # Alas, I need to duplicate code from Formtastic::Inputs::Base::Numeric because
2
+ # there's no way to re-import that module.
3
+ module FormtasticBootstrap
4
+ module Inputs
5
+ module Base
6
+ module Numeric
7
+
8
+ include Formtastic::Inputs::Base::Numeric
9
+
10
+ def wrapper_html_options
11
+ new_class = [super[:class], "numeric", "stringish"].compact.join(" ")
12
+ super.merge(:class => new_class)
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,28 @@
1
+ module FormtasticBootstrap
2
+ module Inputs
3
+ module Base
4
+ module Timeish
5
+
6
+ def date_input_html
7
+ fragment_input_html(:date, "small")
8
+ end
9
+
10
+ def time_input_html
11
+ fragment_input_html(:time, "mini")
12
+ end
13
+
14
+ def fragment_id(fragment)
15
+ # TODO is this right?
16
+ # "#{input_html_options[:id]}_#{position(fragment)}i"
17
+ "#{input_html_options[:id]}[#{fragment}]"
18
+ end
19
+
20
+ def fragment_input_html(fragment, klass)
21
+ opts = input_options.merge(:prefix => fragment_prefix, :field_name => fragment_name(fragment), :default => value, :include_blank => include_blank?)
22
+ template.send(:"text_field_#{fragment}", value, opts, input_html_options.merge(:id => fragment_id(fragment), :class => klass))
23
+ end
24
+
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,74 @@
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
+ control_group_div_wrapping do
10
+ label_html <<
11
+ input_div_wrapping do
12
+ if options[:prepend]
13
+ prepended_input_wrapping do
14
+ [template.content_tag(:span, options[:prepend], :class => 'add-on'), yield].join("\n").html_safe
15
+ end
16
+ else
17
+ yield
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ def control_group_div_wrapping(&block)
24
+ template.content_tag(:div, wrapper_html_options) do
25
+ yield
26
+ end
27
+ end
28
+
29
+ def input_div_wrapping(inline_or_block_errors = :inline)
30
+ template.content_tag(:div, :class => "controls") do
31
+ [yield, error_html(inline_or_block_errors), hint_html(inline_or_block_errors)].join("\n").html_safe
32
+ end
33
+ end
34
+
35
+ def inline_inputs_div_wrapping(&block)
36
+ template.content_tag(:div, :class => "inline-inputs") do
37
+ yield
38
+ end
39
+ end
40
+
41
+ def wrapper_html_options
42
+ opts = (options[:wrapper_html] || {}).dup
43
+ opts[:class] =
44
+ case opts[:class]
45
+ when Array
46
+ opts[:class].dup
47
+ when nil
48
+ []
49
+ else
50
+ [opts[:class].to_s]
51
+ end
52
+ opts[:class] << "#{as}-wrapper"
53
+ opts[:class] << "control-group"
54
+ # opts[:class] << "input"
55
+ opts[:class] << "error" if errors?
56
+ opts[:class] << "optional" if optional?
57
+ opts[:class] << "required" if required?
58
+ opts[:class] << "autofocus" if autofocus?
59
+ opts[:class] = opts[:class].join(' ')
60
+
61
+ opts[:id] ||= wrapper_dom_id
62
+
63
+ opts
64
+ end
65
+
66
+ def prepended_input_wrapping(&block)
67
+ template.content_tag(:div, :class => 'input-prepend') do
68
+ yield
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,29 @@
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
+ control_group_div_wrapping do
9
+ empty_label <<
10
+ hidden_field_html <<
11
+ input_div_wrapping(:block) do
12
+ label_with_nested_checkbox
13
+ end
14
+ end
15
+ end
16
+
17
+ def label_html_options
18
+ new_class = [super[:class], "checkbox"].compact.join(" ")
19
+ super.merge(:class => new_class)
20
+ end
21
+
22
+ # Need this for formatting to work.
23
+ def empty_label
24
+ template.content_tag(:label, '', :class => 'control-label') do end
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,36 @@
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
+ control_group_div_wrapping do
9
+ legend_html <<
10
+ hidden_field_for_all <<
11
+ input_div_wrapping do
12
+ collection.map { |choice|
13
+ choice_html(choice)
14
+ }.join("\n").html_safe
15
+ end
16
+ end
17
+ end
18
+
19
+ def choice_html(choice)
20
+ template.content_tag(:label,
21
+ hidden_fields? ?
22
+ check_box_with_hidden_input(choice) :
23
+ check_box_without_hidden_input(choice) <<
24
+ choice_label(choice),
25
+ label_html_options.merge(:for => choice_input_dom_id(choice)).merge(choice_wrapping_html_options(choice))
26
+ )
27
+ end
28
+
29
+ def choice_wrapping_html_options(choice)
30
+ new_class = [super[:class], 'checkbox'].join(' ')
31
+ super.merge(:class => new_class)
32
+ end
33
+
34
+ end
35
+ end
36
+ end