speedo-formstrap 1.2.0 → 1.2.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.
Files changed (82) hide show
  1. data/README.md +2 -2
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/formtastic-bootstrap.gemspec +1 -1
  5. data/lib/formtastic-bootstrap.rb +5 -5
  6. data/lib/formtastic-bootstrap/actions.rb +4 -4
  7. data/lib/formtastic-bootstrap/actions/base.rb +1 -1
  8. data/lib/formtastic-bootstrap/actions/button_action.rb +1 -1
  9. data/lib/formtastic-bootstrap/actions/input_action.rb +1 -1
  10. data/lib/formtastic-bootstrap/actions/link_action.rb +1 -1
  11. data/lib/formtastic-bootstrap/engine.rb +1 -1
  12. data/lib/formtastic-bootstrap/form_builder.rb +9 -11
  13. data/lib/formtastic-bootstrap/helpers.rb +6 -8
  14. data/lib/formtastic-bootstrap/helpers/action_helper.rb +2 -2
  15. data/lib/formtastic-bootstrap/helpers/actions_helper.rb +2 -2
  16. data/lib/formtastic-bootstrap/helpers/buttons_helper.rb +10 -14
  17. data/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb +7 -12
  18. data/lib/formtastic-bootstrap/helpers/input_helper.rb +2 -2
  19. data/lib/formtastic-bootstrap/helpers/inputs_helper.rb +6 -6
  20. data/lib/formtastic-bootstrap/inputs.rb +21 -21
  21. data/lib/formtastic-bootstrap/inputs/base.rb +10 -11
  22. data/lib/formtastic-bootstrap/inputs/base/choices.rb +24 -13
  23. data/lib/formtastic-bootstrap/inputs/base/errors.rb +1 -1
  24. data/lib/formtastic-bootstrap/inputs/base/hints.rb +1 -1
  25. data/lib/formtastic-bootstrap/inputs/base/html.rb +1 -1
  26. data/lib/formtastic-bootstrap/inputs/base/labelling.rb +7 -17
  27. data/lib/formtastic-bootstrap/inputs/base/numeric.rb +1 -1
  28. data/lib/formtastic-bootstrap/inputs/base/stringish.rb +1 -1
  29. data/lib/formtastic-bootstrap/inputs/base/timeish.rb +13 -6
  30. data/lib/formtastic-bootstrap/inputs/base/wrapping.rb +15 -33
  31. data/lib/formtastic-bootstrap/inputs/boolean_input.rb +1 -1
  32. data/lib/formtastic-bootstrap/inputs/check_boxes_input.rb +1 -1
  33. data/lib/formtastic-bootstrap/inputs/date_input.rb +1 -1
  34. data/lib/formtastic-bootstrap/inputs/datetime_input.rb +1 -1
  35. data/lib/formtastic-bootstrap/inputs/email_input.rb +1 -1
  36. data/lib/formtastic-bootstrap/inputs/file_input.rb +1 -1
  37. data/lib/formtastic-bootstrap/inputs/hidden_input.rb +1 -1
  38. data/lib/formtastic-bootstrap/inputs/number_input.rb +3 -3
  39. data/lib/formtastic-bootstrap/inputs/password_input.rb +1 -1
  40. data/lib/formtastic-bootstrap/inputs/phone_input.rb +1 -1
  41. data/lib/formtastic-bootstrap/inputs/radio_input.rb +13 -14
  42. data/lib/formtastic-bootstrap/inputs/range_input.rb +3 -3
  43. data/lib/formtastic-bootstrap/inputs/search_input.rb +1 -1
  44. data/lib/formtastic-bootstrap/inputs/select_input.rb +1 -1
  45. data/lib/formtastic-bootstrap/inputs/string_input.rb +1 -1
  46. data/lib/formtastic-bootstrap/inputs/text_input.rb +1 -1
  47. data/lib/formtastic-bootstrap/inputs/time_input.rb +1 -1
  48. data/lib/formtastic-bootstrap/inputs/time_zone_input.rb +1 -1
  49. data/lib/formtastic-bootstrap/inputs/url_input.rb +1 -1
  50. data/spec/actions/button_action_spec.rb +1 -1
  51. data/spec/actions/generic_action_spec.rb +1 -1
  52. data/spec/actions/input_action_spec.rb +1 -1
  53. data/spec/actions/link_action_spec.rb +1 -1
  54. data/spec/builder/semantic_fields_for_spec.rb +16 -16
  55. data/spec/helpers/action_helper_spec.rb +1 -1
  56. data/spec/helpers/actions_helper_spec.rb +1 -1
  57. data/spec/helpers/buttons_helper_spec.rb +46 -56
  58. data/spec/helpers/input_helper_spec.rb +209 -209
  59. data/spec/helpers/inputs_helper_spec.rb +103 -117
  60. data/spec/inputs/boolean_input_spec.rb +46 -74
  61. data/spec/inputs/check_boxes_input_spec.rb +82 -110
  62. data/spec/inputs/date_input_spec.rb +15 -81
  63. data/spec/inputs/datetime_input_spec.rb +13 -13
  64. data/spec/inputs/email_input_spec.rb +6 -34
  65. data/spec/inputs/file_input_spec.rb +6 -34
  66. data/spec/inputs/hidden_input_spec.rb +13 -41
  67. data/spec/inputs/number_input_spec.rb +97 -127
  68. data/spec/inputs/password_input_spec.rb +6 -34
  69. data/spec/inputs/phone_input_spec.rb +6 -34
  70. data/spec/inputs/radio_input_spec.rb +45 -73
  71. data/spec/inputs/range_input_spec.rb +66 -94
  72. data/spec/inputs/search_input_spec.rb +6 -33
  73. data/spec/inputs/select_input_spec.rb +78 -124
  74. data/spec/inputs/string_input_spec.rb +22 -67
  75. data/spec/inputs/text_input_spec.rb +15 -42
  76. data/spec/inputs/time_input_spec.rb +23 -23
  77. data/spec/inputs/time_zone_input_spec.rb +20 -20
  78. data/spec/inputs/url_input_spec.rb +6 -34
  79. data/spec/support/custom_macros.rb +196 -67
  80. data/spec/support/formtastic_spec_helper.rb +6 -22
  81. data/speedo-formstrap.gemspec +146 -0
  82. metadata +18 -17
@@ -1,4 +1,4 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  module Base
4
4
  module Errors
@@ -1,4 +1,4 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  module Base
4
4
  module Hints
@@ -1,4 +1,4 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  module Base
4
4
  module Html
@@ -1,28 +1,18 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  module Base
4
4
  module Labelling
5
5
 
6
6
  include Formtastic::Inputs::Base::Labelling
7
7
 
8
- def label_html
9
- render_label? ? builder.label(input_name, label_text, control_label_html_options) : "".html_safe
10
- end
11
-
12
8
  def label_html_options
13
- opts = {}
14
- opts[:for] ||= input_html_options[:id]
15
- opts[:class] = [opts[:class]]
16
-
17
- opts
9
+ {}.tap do |opts|
10
+ opts[:for] ||= input_html_options[:id]
11
+ opts[:class] = [opts[:class]]
12
+ end
18
13
  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
-
14
+
25
15
  end
26
16
  end
27
17
  end
28
- end
18
+ end
@@ -1,6 +1,6 @@
1
1
  # Alas, I need to duplicate code from Formtastic::Inputs::Base::Numeric because
2
2
  # there's no way to re-import that module.
3
- module FormtasticBootstrap
3
+ module SpeedoFormstrap
4
4
  module Inputs
5
5
  module Base
6
6
  module Numeric
@@ -1,6 +1,6 @@
1
1
  # Alas, I need to duplicate code from Formtastic::Inputs::Base::Stringish because
2
2
  # there's no way to re-import that module.
3
- module FormtasticBootstrap
3
+ module SpeedoFormstrap
4
4
  module Inputs
5
5
  module Base
6
6
  module Stringish
@@ -1,8 +1,15 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  module Base
4
4
  module Timeish
5
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
+
6
13
  def date_input_html
7
14
  fragment_input_html(:date, "small")
8
15
  end
@@ -10,19 +17,19 @@ module FormtasticBootstrap
10
17
  def time_input_html
11
18
  fragment_input_html(:time, "mini")
12
19
  end
13
-
20
+
14
21
  def fragment_id(fragment)
15
22
  # TODO is this right?
16
23
  # "#{input_html_options[:id]}_#{position(fragment)}i"
17
24
  "#{input_html_options[:id]}[#{fragment}]"
18
25
  end
19
-
26
+
20
27
  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?)
28
+ opts = input_options.merge(:prefix => object_name, :field_name => fragment_name(fragment), :default => value, :include_blank => include_blank?)
22
29
  template.send(:"text_field_#{fragment}", value, opts, input_html_options.merge(:id => fragment_id(fragment), :class => klass))
23
30
  end
24
-
31
+
25
32
  end
26
33
  end
27
34
  end
28
- end
35
+ end
@@ -1,4 +1,4 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  module Base
4
4
  module Wrapping
@@ -6,29 +6,23 @@ module FormtasticBootstrap
6
6
  include Formtastic::Inputs::Base::Wrapping
7
7
 
8
8
  def generic_input_wrapping(&block)
9
- control_group_div_wrapping do
9
+ clearfix_div_wrapping do
10
10
  label_html <<
11
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
12
+ yield
19
13
  end
20
14
  end
21
15
  end
22
16
 
23
- def control_group_div_wrapping(&block)
17
+ def clearfix_div_wrapping(&block)
24
18
  template.content_tag(:div, wrapper_html_options) do
25
19
  yield
26
20
  end
27
21
  end
28
22
 
29
23
  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
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
32
26
  end
33
27
  end
34
28
 
@@ -39,36 +33,24 @@ module FormtasticBootstrap
39
33
  end
40
34
 
41
35
  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"
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"
54
41
  # opts[:class] << "input"
55
42
  opts[:class] << "error" if errors?
56
43
  opts[:class] << "optional" if optional?
57
44
  opts[:class] << "required" if required?
58
45
  opts[:class] << "autofocus" if autofocus?
59
46
  opts[:class] = opts[:class].join(' ')
60
-
47
+
61
48
  opts[:id] ||= wrapper_dom_id
62
-
49
+
63
50
  opts
64
51
  end
65
-
66
- def prepended_input_wrapping(&block)
67
- template.content_tag(:div, :class => 'input-prepend') do
68
- yield
69
- end
70
- end
52
+
71
53
  end
72
54
  end
73
55
  end
74
- end
56
+ end
@@ -1,5 +1,5 @@
1
1
  # TODO See if this can be refactored to make use of some of the Choices code.
2
- module FormtasticBootstrap
2
+ module SpeedoFormstrap
3
3
  module Inputs
4
4
  class BooleanInput < Formtastic::Inputs::BooleanInput
5
5
  include Base
@@ -1,4 +1,4 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  class CheckBoxesInput < Formtastic::Inputs::CheckBoxesInput
4
4
  include Base
@@ -1,4 +1,4 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  class DateInput < Formtastic::Inputs::DateInput
4
4
  include Base
@@ -1,4 +1,4 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  class DatetimeInput < Formtastic::Inputs::DatetimeInput
4
4
  include Base
@@ -1,4 +1,4 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  class EmailInput < Formtastic::Inputs::EmailInput
4
4
  include Base
@@ -1,4 +1,4 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  class FileInput < Formtastic::Inputs::FileInput
4
4
  include Base
@@ -1,4 +1,4 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  class HiddenInput < Formtastic::Inputs::HiddenInput
4
4
  include Base
@@ -1,8 +1,8 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  class NumberInput < Formtastic::Inputs::NumberInput
4
4
  include Base
5
- include Base::Numeric
5
+ include Base::Stringish
6
6
 
7
7
  def to_html
8
8
  generic_input_wrapping do
@@ -12,4 +12,4 @@ module FormtasticBootstrap
12
12
 
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -1,4 +1,4 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  class PasswordInput < Formtastic::Inputs::PasswordInput
4
4
  include Base
@@ -1,4 +1,4 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  class PhoneInput < Formtastic::Inputs::PhoneInput
4
4
  include Base
@@ -1,33 +1,32 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  class RadioInput < Formtastic::Inputs::RadioInput
4
4
  include Base
5
5
  include Base::Choices
6
6
 
7
7
  def to_html
8
- control_group_div_wrapping do
8
+ clearfix_div_wrapping do
9
9
  legend_html <<
10
10
  input_div_wrapping do
11
- collection.map { |choice|
12
- choice_html(choice)
13
- }.join("\n").html_safe
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
14
18
  end
15
19
  end
16
20
  end
17
21
 
18
- def choice_html(choice)
19
- template.content_tag(:label, label_html_options.merge(:for => choice_input_dom_id(choice)).merge(choice_wrapping_html_options(choice))) do
20
- builder.radio_button(input_name, choice_value(choice), input_html_options.merge(choice_html_options(choice)).merge(:required => false)) <<
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)) <<
21
25
 
22
26
  choice_label(choice)
23
27
  end
24
28
  end
25
29
 
26
- def choice_wrapping_html_options(choice)
27
- new_class = [super[:class], 'radio'].join(' ')
28
- super.merge(:class => new_class)
29
- end
30
-
31
30
  end
32
31
  end
33
- end
32
+ end
@@ -1,8 +1,8 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  class RangeInput < Formtastic::Inputs::RangeInput
4
4
  include Base
5
- include Base::Numeric
5
+ include Base::Stringish
6
6
 
7
7
  def to_html
8
8
  generic_input_wrapping do
@@ -12,4 +12,4 @@ module FormtasticBootstrap
12
12
 
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -1,4 +1,4 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  class SearchInput < Formtastic::Inputs::SearchInput
4
4
  include Base
@@ -1,4 +1,4 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  class SelectInput < Formtastic::Inputs::SelectInput
4
4
  include Base
@@ -1,4 +1,4 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  class StringInput < Formtastic::Inputs::StringInput
4
4
  include Base
@@ -1,4 +1,4 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  class TextInput < Formtastic::Inputs::TextInput
4
4
  include Base
@@ -1,4 +1,4 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  class TimeInput < Formtastic::Inputs::TimeInput
4
4
  include Base
@@ -1,4 +1,4 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  class TimeZoneInput < Formtastic::Inputs::TimeZoneInput
4
4
  include Base
@@ -1,4 +1,4 @@
1
- module FormtasticBootstrap
1
+ module SpeedoFormstrap
2
2
  module Inputs
3
3
  class UrlInput < Formtastic::Inputs::UrlInput
4
4
  include Base
@@ -8,7 +8,7 @@ describe 'ButtonAction', 'when submitting' do
8
8
  before do
9
9
  @output_buffer = ''
10
10
  mock_everything
11
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
11
+ Formtastic::Helpers::FormHelper.builder = SpeedoFormstrap::FormBuilder
12
12
 
13
13
  concat(semantic_form_for(@new_post) do |builder|
14
14
  concat(builder.action(:submit, :as => :button))
@@ -23,7 +23,7 @@ describe 'InputAction::Base' do
23
23
  before do
24
24
  @output_buffer = ''
25
25
  mock_everything
26
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
26
+ Formtastic::Helpers::FormHelper.builder = SpeedoFormstrap::FormBuilder
27
27
  end
28
28
 
29
29
  describe 'wrapping HTML' do
@@ -8,7 +8,7 @@ describe 'InputAction', 'when submitting' do
8
8
  before do
9
9
  @output_buffer = ''
10
10
  mock_everything
11
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
11
+ Formtastic::Helpers::FormHelper.builder = SpeedoFormstrap::FormBuilder
12
12
 
13
13
  concat(semantic_form_for(@new_post) do |builder|
14
14
  concat(builder.action(:submit, :as => :input))
@@ -8,7 +8,7 @@ describe 'LinkAction', 'when cancelling' do
8
8
  before do
9
9
  @output_buffer = ''
10
10
  mock_everything
11
- Formtastic::Helpers::FormHelper.builder = FormtasticBootstrap::FormBuilder
11
+ Formtastic::Helpers::FormHelper.builder = SpeedoFormstrap::FormBuilder
12
12
  end
13
13
 
14
14
  context 'without a :url' do