speedo-formstrap 1.2.7 → 1.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/Gemfile +2 -2
  2. data/Gemfile.lock +67 -65
  3. data/README.md +12 -2
  4. data/Rakefile +1 -1
  5. data/VERSION +1 -1
  6. data/lib/formtastic-bootstrap.rb +1 -0
  7. data/lib/formtastic-bootstrap/actions.rb +4 -0
  8. data/lib/formtastic-bootstrap/actions/base.rb +18 -0
  9. data/lib/formtastic-bootstrap/actions/button_action.rb +7 -0
  10. data/lib/formtastic-bootstrap/actions/input_action.rb +7 -0
  11. data/lib/formtastic-bootstrap/actions/link_action.rb +7 -0
  12. data/lib/formtastic-bootstrap/form_builder.rb +7 -5
  13. data/lib/formtastic-bootstrap/helpers.rb +3 -1
  14. data/lib/formtastic-bootstrap/helpers/action_helper.rb +12 -0
  15. data/lib/formtastic-bootstrap/helpers/actions_helper.rb +23 -0
  16. data/lib/formtastic-bootstrap/helpers/buttons_helper.rb +13 -9
  17. data/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb +11 -6
  18. data/lib/formtastic-bootstrap/helpers/inputs_helper.rb +4 -4
  19. data/lib/formtastic-bootstrap/inputs/base.rb +2 -1
  20. data/lib/formtastic-bootstrap/inputs/base/choices.rb +12 -23
  21. data/lib/formtastic-bootstrap/inputs/base/labelling.rb +16 -6
  22. data/lib/formtastic-bootstrap/inputs/base/numeric.rb +18 -0
  23. data/lib/formtastic-bootstrap/inputs/base/timeish.rb +5 -12
  24. data/lib/formtastic-bootstrap/inputs/base/wrapping.rb +32 -14
  25. data/lib/formtastic-bootstrap/inputs/boolean_input.rb +7 -11
  26. data/lib/formtastic-bootstrap/inputs/check_boxes_input.rb +10 -9
  27. data/lib/formtastic-bootstrap/inputs/hidden_input.rb +5 -3
  28. data/lib/formtastic-bootstrap/inputs/number_input.rb +2 -2
  29. data/lib/formtastic-bootstrap/inputs/radio_input.rb +13 -12
  30. data/lib/formtastic-bootstrap/inputs/range_input.rb +2 -2
  31. data/spec/actions/button_action_spec.rb +68 -0
  32. data/spec/actions/generic_action_spec.rb +486 -0
  33. data/spec/actions/input_action_spec.rb +64 -0
  34. data/spec/actions/link_action_spec.rb +93 -0
  35. data/spec/builder/semantic_fields_for_spec.rb +14 -14
  36. data/spec/helpers/action_helper_spec.rb +365 -0
  37. data/spec/helpers/actions_helper_spec.rb +143 -0
  38. data/spec/helpers/buttons_helper_spec.rb +55 -45
  39. data/spec/helpers/input_helper_spec.rb +188 -188
  40. data/spec/helpers/inputs_helper_spec.rb +116 -102
  41. data/spec/inputs/boolean_input_spec.rb +72 -44
  42. data/spec/inputs/check_boxes_input_spec.rb +108 -80
  43. data/spec/inputs/date_input_spec.rb +80 -14
  44. data/spec/inputs/datetime_input_spec.rb +12 -12
  45. data/spec/inputs/email_input_spec.rb +33 -5
  46. data/spec/inputs/file_input_spec.rb +33 -5
  47. data/spec/inputs/hidden_input_spec.rb +40 -12
  48. data/spec/inputs/number_input_spec.rb +126 -96
  49. data/spec/inputs/password_input_spec.rb +33 -5
  50. data/spec/inputs/phone_input_spec.rb +33 -5
  51. data/spec/inputs/radio_input_spec.rb +72 -44
  52. data/spec/inputs/range_input_spec.rb +93 -65
  53. data/spec/inputs/search_input_spec.rb +32 -5
  54. data/spec/inputs/select_input_spec.rb +123 -77
  55. data/spec/inputs/string_input_spec.rb +66 -21
  56. data/spec/inputs/text_input_spec.rb +40 -13
  57. data/spec/inputs/time_input_spec.rb +22 -22
  58. data/spec/inputs/time_zone_input_spec.rb +17 -17
  59. data/spec/inputs/url_input_spec.rb +33 -5
  60. data/spec/support/custom_macros.rb +59 -188
  61. data/spec/support/formtastic_spec_helper.rb +19 -3
  62. data/speedo-formstrap.gemspec +146 -0
  63. metadata +31 -16
@@ -3,17 +3,13 @@ module FormtasticBootstrap
3
3
  module FieldsetWrapper
4
4
 
5
5
  include Formtastic::Helpers::FieldsetWrapper
6
-
6
+
7
7
  protected
8
8
 
9
9
  def field_set_and_list_wrapping(*args, &block) #:nodoc:
10
10
  contents = args.last.is_a?(::Hash) ? '' : args.pop.flatten
11
11
  html_options = args.extract_options!
12
12
 
13
- legend = (html_options[:name] || '').to_s
14
- legend %= parent_child_index(html_options[:parent]) if html_options[:parent]
15
- legend = template.content_tag(:legend, Formtastic::Util.html_safe(legend)) unless legend.blank?
16
-
17
13
  if block_given?
18
14
  contents = if template.respond_to?(:is_haml?) && template.is_haml?
19
15
  template.capture_haml(&block)
@@ -24,6 +20,8 @@ module FormtasticBootstrap
24
20
 
25
21
  # Ruby 1.9: String#to_s behavior changed, need to make an explicit join.
26
22
  contents = contents.join if contents.respond_to?(:join)
23
+
24
+ legend = field_set_legend(html_options)
27
25
  fieldset = template.content_tag(:fieldset,
28
26
  Formtastic::Util.html_safe(legend) << Formtastic::Util.html_safe(contents),
29
27
  html_options.except(:builder, :parent, :name)
@@ -32,6 +30,13 @@ module FormtasticBootstrap
32
30
  fieldset
33
31
  end
34
32
 
33
+ def field_set_legend(html_options)
34
+ legend = (html_options[:name] || '').to_s
35
+ legend %= parent_child_index(html_options[:parent]) if html_options[:parent]
36
+ legend = template.content_tag(:legend, Formtastic::Util.html_safe(legend)) unless legend.blank?
37
+ legend
38
+ end
39
+
35
40
  end
36
41
  end
37
- end
42
+ end
@@ -6,7 +6,7 @@ module FormtasticBootstrap
6
6
  def inputs(*args, &block)
7
7
  wrap_it = @already_in_an_inputs_block ? true : false
8
8
  @already_in_an_inputs_block = true
9
-
9
+
10
10
  title = field_set_title_from_args(*args)
11
11
  html_options = args.extract_options!
12
12
  html_options[:class] ||= "inputs"
@@ -25,12 +25,12 @@ module FormtasticBootstrap
25
25
  field_set_and_list_wrapping(*((args << html_options) << contents))
26
26
  end
27
27
  end
28
-
28
+
29
29
  # out = template.content_tag(:li, out, :class => "input") if wrap_it
30
- @already_in_an_inputs_block = false
30
+ @already_in_an_inputs_block = wrap_it
31
31
  out
32
32
  end
33
33
 
34
34
  end
35
35
  end
36
- end
36
+ end
@@ -3,6 +3,7 @@ require "formtastic-bootstrap/inputs/base/errors"
3
3
  require "formtastic-bootstrap/inputs/base/hints"
4
4
  require "formtastic-bootstrap/inputs/base/html"
5
5
  require "formtastic-bootstrap/inputs/base/labelling"
6
+ require "formtastic-bootstrap/inputs/base/numeric"
6
7
  require "formtastic-bootstrap/inputs/base/stringish"
7
8
  require "formtastic-bootstrap/inputs/base/timeish"
8
9
  require "formtastic-bootstrap/inputs/base/wrapping"
@@ -16,7 +17,7 @@ module FormtasticBootstrap
16
17
  include Html
17
18
  include Labelling
18
19
  include Wrapping
19
-
20
+
20
21
  end
21
22
  end
22
23
  end
@@ -5,45 +5,34 @@ module FormtasticBootstrap
5
5
 
6
6
  def input_div_wrapping(&block)
7
7
  template.content_tag(:div, choices_wrapping_html_options) do
8
- [yield, error_html(:block), hint_html(:block)].join("\n").html_safe
8
+ [yield, error_html(:block), hint_html(:block)].join("\n").html_safe
9
9
  end
10
10
  end
11
11
 
12
12
  def choices_wrapping_html_options
13
- # TODO Call the Formtastic one explicity and append?
14
- { :class => "choices input" }
13
+ new_class = [super[:class], "controls"].compact.join(" ")
14
+ super.merge(:class => new_class)
15
15
  end
16
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
- def choices_group_wrapping_html_options
25
- { :class => "choices-group inputs-list" }
26
- end
27
-
28
- def choice_label(choice)
29
- "\n".html_safe + template.content_tag(:span) do
30
- # (choice.is_a?(Array) ? choice.first : choice).to_s
31
- (choice.is_a?(Array) ? choice.first : choice).to_s
32
- end
33
- end
17
+ #def choices_group_wrapping(&block)
18
+ # template.content_tag(:ul,
19
+ # template.capture(&block),
20
+ # choices_group_wrapping_html_options
21
+ # )
22
+ #end
34
23
 
35
24
  # This is actually a label in Bootstrap.
36
25
  def legend_html
37
- template.content_tag(:label, label_html_options) do
26
+ template.content_tag(:label, control_label_html_options) do
38
27
  render_label? ? label_text : "".html_safe
39
28
  end
40
29
  end
41
30
 
42
- def label_html_options
31
+ def control_label_html_options
43
32
  super.merge(:for => nil)
44
33
  end
45
34
 
46
35
  end
47
36
  end
48
37
  end
49
- end
38
+ end
@@ -5,14 +5,24 @@ module FormtasticBootstrap
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
+
8
12
  def label_html_options
9
- {}.tap do |opts|
10
- opts[:for] ||= input_html_options[:id]
11
- opts[:class] = [opts[:class]]
12
- end
13
+ opts = {}
14
+ opts[:for] ||= input_html_options[:id]
15
+ opts[:class] = [opts[:class]]
16
+
17
+ opts
13
18
  end
14
-
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
+
15
25
  end
16
26
  end
17
27
  end
18
- 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
@@ -3,13 +3,6 @@ module FormtasticBootstrap
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
-
13
6
  def date_input_html
14
7
  fragment_input_html(:date, "small")
15
8
  end
@@ -17,19 +10,19 @@ module FormtasticBootstrap
17
10
  def time_input_html
18
11
  fragment_input_html(:time, "mini")
19
12
  end
20
-
13
+
21
14
  def fragment_id(fragment)
22
15
  # TODO is this right?
23
16
  # "#{input_html_options[:id]}_#{position(fragment)}i"
24
17
  "#{input_html_options[:id]}[#{fragment}]"
25
18
  end
26
-
19
+
27
20
  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?)
21
+ opts = input_options.merge(:prefix => fragment_prefix, :field_name => fragment_name(fragment), :default => value, :include_blank => include_blank?)
29
22
  template.send(:"text_field_#{fragment}", value, opts, input_html_options.merge(:id => fragment_id(fragment), :class => klass))
30
23
  end
31
-
24
+
32
25
  end
33
26
  end
34
27
  end
35
- end
28
+ end
@@ -6,23 +6,29 @@ module FormtasticBootstrap
6
6
  include Formtastic::Inputs::Base::Wrapping
7
7
 
8
8
  def generic_input_wrapping(&block)
9
- clearfix_div_wrapping do
9
+ control_group_div_wrapping do
10
10
  label_html <<
11
11
  input_div_wrapping do
12
- yield
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
13
19
  end
14
20
  end
15
21
  end
16
22
 
17
- def clearfix_div_wrapping(&block)
23
+ def control_group_div_wrapping(&block)
18
24
  template.content_tag(:div, wrapper_html_options) do
19
25
  yield
20
26
  end
21
27
  end
22
28
 
23
29
  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
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
26
32
  end
27
33
  end
28
34
 
@@ -33,24 +39,36 @@ module FormtasticBootstrap
33
39
  end
34
40
 
35
41
  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"
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"
41
54
  # opts[:class] << "input"
42
55
  opts[:class] << "error" if errors?
43
56
  opts[:class] << "optional" if optional?
44
57
  opts[:class] << "required" if required?
45
58
  opts[:class] << "autofocus" if autofocus?
46
59
  opts[:class] = opts[:class].join(' ')
47
-
60
+
48
61
  opts[:id] ||= wrapper_dom_id
49
-
62
+
50
63
  opts
51
64
  end
52
-
65
+
66
+ def prepended_input_wrapping(&block)
67
+ template.content_tag(:div, :class => 'input-prepend') do
68
+ yield
69
+ end
70
+ end
53
71
  end
54
72
  end
55
73
  end
56
- end
74
+ end
@@ -5,29 +5,25 @@ module FormtasticBootstrap
5
5
  include Base
6
6
 
7
7
  def to_html
8
- clearfix_div_wrapping do
8
+ control_group_div_wrapping do
9
9
  empty_label <<
10
10
  hidden_field_html <<
11
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
12
+ label_with_nested_checkbox
17
13
  end
18
14
  end
19
15
  end
20
16
 
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
17
+ def label_html_options
18
+ new_class = [super[:class], "checkbox"].compact.join(" ")
19
+ super.merge(:class => new_class)
24
20
  end
25
21
 
26
22
  # Need this for formatting to work.
27
23
  def empty_label
28
- template.content_tag(:label) do end
24
+ template.content_tag(:label, '', :class => 'control-label') do end
29
25
  end
30
26
 
31
27
  end
32
28
  end
33
- end
29
+ end
@@ -5,17 +5,13 @@ module FormtasticBootstrap
5
5
  include Base::Choices
6
6
 
7
7
  def to_html
8
- clearfix_div_wrapping do
8
+ control_group_div_wrapping do
9
9
  legend_html <<
10
10
  hidden_field_for_all <<
11
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
12
+ collection.map { |choice|
13
+ choice_html(choice)
14
+ }.join("\n").html_safe
19
15
  end
20
16
  end
21
17
  end
@@ -26,10 +22,15 @@ module FormtasticBootstrap
26
22
  check_box_with_hidden_input(choice) :
27
23
  check_box_without_hidden_input(choice) <<
28
24
  choice_label(choice),
29
- label_html_options.merge(:for => choice_input_dom_id(choice), :class => nil)
25
+ label_html_options.merge(:for => choice_input_dom_id(choice)).merge(choice_wrapping_html_options(choice))
30
26
  )
31
27
  end
32
28
 
29
+ def choice_wrapping_html_options(choice)
30
+ new_class = [super[:class], 'checkbox'].join(' ')
31
+ super.merge(:class => new_class)
32
+ end
33
+
33
34
  end
34
35
  end
35
36
  end
@@ -3,10 +3,12 @@ module FormtasticBootstrap
3
3
  class HiddenInput < Formtastic::Inputs::HiddenInput
4
4
  include Base
5
5
  def to_html
6
- generic_input_wrapping do
7
- builder.hidden_field(method, input_html_options)
6
+ control_group_div_wrapping do
7
+ input_div_wrapping do
8
+ builder.hidden_field(method, input_html_options)
9
+ end
8
10
  end
9
11
  end
10
12
  end
11
13
  end
12
- end
14
+ end
@@ -2,7 +2,7 @@ module FormtasticBootstrap
2
2
  module Inputs
3
3
  class NumberInput < Formtastic::Inputs::NumberInput
4
4
  include Base
5
- include Base::Stringish
5
+ include Base::Numeric
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
@@ -5,28 +5,29 @@ module FormtasticBootstrap
5
5
  include Base::Choices
6
6
 
7
7
  def to_html
8
- clearfix_div_wrapping do
8
+ control_group_div_wrapping do
9
9
  legend_html <<
10
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
11
+ collection.map { |choice|
12
+ choice_html(choice)
13
+ }.join("\n").html_safe
18
14
  end
19
15
  end
20
16
  end
21
17
 
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)) <<
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)) <<
25
21
 
26
22
  choice_label(choice)
27
23
  end
28
24
  end
29
25
 
26
+ def choice_wrapping_html_options(choice)
27
+ new_class = [super[:class], 'radio'].join(' ')
28
+ super.merge(:class => new_class)
29
+ end
30
+
30
31
  end
31
32
  end
32
- end
33
+ end