formtastic-bootstrap 2.1.3 → 3.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +43 -56
  3. data/VERSION +1 -1
  4. data/lib/action_view/helpers/text_field_date_helper.rb +7 -7
  5. data/lib/formtastic-bootstrap/actions/base.rb +11 -6
  6. data/lib/formtastic-bootstrap/form_builder.rb +5 -5
  7. data/lib/formtastic-bootstrap/helpers.rb +1 -1
  8. data/lib/formtastic-bootstrap/helpers/actions_helper.rb +4 -4
  9. data/lib/formtastic-bootstrap/helpers/errors_helper.rb +1 -1
  10. data/lib/formtastic-bootstrap/helpers/fieldset_wrapper.rb +2 -2
  11. data/lib/formtastic-bootstrap/helpers/input_helper.rb +3 -3
  12. data/lib/formtastic-bootstrap/helpers/inputs_helper.rb +3 -3
  13. data/lib/formtastic-bootstrap/inputs.rb +19 -19
  14. data/lib/formtastic-bootstrap/inputs/base.rb +1 -1
  15. data/lib/formtastic-bootstrap/inputs/base/errors.rb +2 -2
  16. data/lib/formtastic-bootstrap/inputs/base/hints.rb +3 -3
  17. data/lib/formtastic-bootstrap/inputs/base/html.rb +8 -2
  18. data/lib/formtastic-bootstrap/inputs/base/labelling.rb +6 -11
  19. data/lib/formtastic-bootstrap/inputs/base/stringish.rb +4 -4
  20. data/lib/formtastic-bootstrap/inputs/base/timeish.rb +24 -18
  21. data/lib/formtastic-bootstrap/inputs/base/wrapping.rb +30 -52
  22. data/lib/formtastic-bootstrap/inputs/boolean_input.rb +18 -10
  23. data/lib/formtastic-bootstrap/inputs/check_boxes_input.rb +19 -18
  24. data/lib/formtastic-bootstrap/inputs/email_input.rb +1 -1
  25. data/lib/formtastic-bootstrap/inputs/number_input.rb +3 -3
  26. data/lib/formtastic-bootstrap/inputs/password_input.rb +1 -1
  27. data/lib/formtastic-bootstrap/inputs/phone_input.rb +1 -1
  28. data/lib/formtastic-bootstrap/inputs/radio_input.rb +19 -18
  29. data/lib/formtastic-bootstrap/inputs/range_input.rb +1 -1
  30. data/lib/formtastic-bootstrap/inputs/search_input.rb +1 -1
  31. data/lib/formtastic-bootstrap/inputs/select_input.rb +17 -0
  32. data/lib/formtastic-bootstrap/inputs/text_input.rb +4 -4
  33. data/lib/formtastic-bootstrap/inputs/url_input.rb +1 -1
  34. data/lib/formtastic-bootstrap/version.rb +1 -1
  35. data/vendor/assets/stylesheets/formtastic-bootstrap.css +32 -0
  36. metadata +51 -55
@@ -2,7 +2,7 @@ module FormtasticBootstrap
2
2
  module Inputs
3
3
  module Base
4
4
  module Hints
5
-
5
+
6
6
  include Formtastic::Inputs::Base::Hints
7
7
 
8
8
  def hint_html(inline_or_block = :block)
@@ -13,8 +13,8 @@ module FormtasticBootstrap
13
13
  options[:hint_class] || builder.default_block_hint_class
14
14
  end
15
15
  template.content_tag(
16
- :span,
17
- Formtastic::Util.html_safe(hint_text),
16
+ :span,
17
+ Formtastic::Util.html_safe(hint_text),
18
18
  :class => hint_class
19
19
  )
20
20
  end
@@ -5,9 +5,15 @@ module FormtasticBootstrap
5
5
 
6
6
  include Formtastic::Inputs::Base::Html
7
7
 
8
+ def form_control_input_html_options
9
+ orig_class = input_html_options[:class]
10
+ new_class = [orig_class, "form-control"].compact.join(" ")
11
+ input_html_options.merge(:class => new_class)
12
+ end
13
+
8
14
  def input_html_options
9
15
  if errors?
10
- {
16
+ {
11
17
  :class => "error"
12
18
  }.merge(super)
13
19
  else
@@ -18,4 +24,4 @@ module FormtasticBootstrap
18
24
  end
19
25
  end
20
26
  end
21
- end
27
+ end
@@ -7,23 +7,18 @@ module FormtasticBootstrap
7
7
 
8
8
  def label_html_options
9
9
  super.tap do |options|
10
- # Bootstrap defines class 'label'
10
+ # Bootstrap defines class 'label' too, so remove the
11
+ # one that gets created by Formtastic.
11
12
  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
13
  end
20
14
  end
21
15
 
22
- def control_label_html
23
- render_label? ? builder.label(input_name, label_text, control_label_html_options) : "".html_safe
16
+ # def control_label_html
17
+ def label_html
18
+ render_label? ? builder.label(input_name, label_text, label_html_options) : "".html_safe
24
19
  end
25
20
 
26
21
  end
27
22
  end
28
23
  end
29
- end
24
+ end
@@ -2,16 +2,16 @@ module FormtasticBootstrap
2
2
  module Inputs
3
3
  module Base
4
4
  module Stringish
5
-
5
+
6
6
  include Formtastic::Inputs::Base::Stringish
7
7
 
8
8
  def to_html
9
9
  bootstrap_wrapping do
10
- builder.text_field(method, input_html_options)
10
+ builder.text_field(method, form_control_input_html_options)
11
11
  end
12
12
  end
13
-
13
+
14
14
  end
15
15
  end
16
16
  end
17
- end
17
+ end
@@ -4,10 +4,10 @@ module FormtasticBootstrap
4
4
  module Timeish
5
5
 
6
6
  def to_html
7
- control_group_wrapping do
8
- control_label_html <<
9
- controls_wrapping do
10
- hidden_fragments <<
7
+ form_group_wrapping do
8
+ label_html <<
9
+ hidden_fragments <<
10
+ form_control_row_wrapping do
11
11
  fragments.map do |fragment|
12
12
  fragment_input_html(fragment.to_sym)
13
13
  end.join.html_safe
@@ -15,10 +15,15 @@ module FormtasticBootstrap
15
15
  end
16
16
  end
17
17
 
18
- def controls_wrapper_html_options
19
- super.tap do |options|
20
- options[:class] = (options[:class].split << "controls-row").join(" ")
21
- end
18
+ def form_control_row_wrapping(&block)
19
+ template.content_tag(:div,
20
+ template.capture(&block).html_safe,
21
+ form_control_row_wrapper_html_options
22
+ )
23
+ end
24
+
25
+ def form_control_row_wrapper_html_options
26
+ { :class => "form-control" }
22
27
  end
23
28
 
24
29
  def fragment_input_html(fragment)
@@ -34,22 +39,23 @@ module FormtasticBootstrap
34
39
  end
35
40
  end
36
41
 
37
- def fragment_class(fragment)
38
- {
39
- :year => "span1",
40
- :month => "span2",
41
- :day => "span1",
42
- :hour => "span1",
43
- :minute => "span1",
44
- :second => "span1"
42
+ def fragment_class(fragment)
43
+ {
44
+ :year => "col-xs-1",
45
+ :month => "col-xs-2",
46
+ :day => "col-xs-1",
47
+ :hour => "col-xs-1",
48
+ :minute => "col-xs-1",
49
+ :second => "col-xs-1"
45
50
  }[fragment]
46
51
  end
47
52
 
48
53
  def fragment_placeholder(fragment)
49
- "." + fragment_class(fragment)
54
+ # TODO This sets a useless placeholer right now.
55
+ "." + fragment_class(fragment)
50
56
  end
51
57
 
52
58
  end
53
59
  end
54
60
  end
55
- end
61
+ end
@@ -6,74 +6,52 @@ module FormtasticBootstrap
6
6
  include Formtastic::Inputs::Base::Wrapping
7
7
 
8
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
9
+ input_content = [
10
+ add_on_content(options[:prepend]),
11
+ options[:prepend_content],
12
+ yield,
13
+ add_on_content(options[:append]),
14
+ options[:append_content],
15
+ hint_html
16
+ ].compact.join("\n").html_safe
17
+
18
+ form_group_wrapping do
19
+ label_html <<
20
+ if prepended_or_appended?(options)
21
+ template.content_tag(:div, :class => add_on_wrapper_classes(options).join(" ")) do
22
+ input_content
28
23
  end
24
+ else
25
+ input_content
29
26
  end
30
27
  end
31
28
  end
32
29
 
33
- def control_group_wrapping(&block)
34
- template.content_tag(:div,
35
- template.capture(&block).html_safe,
36
- wrapper_html_options
37
- )
30
+ def prepended_or_appended?(options)
31
+ options[:prepend] || options[:prepend_content] || options[:append] || options[:append_content]
32
+ end
33
+
34
+ def add_on_content(content)
35
+ return nil unless content
36
+ template.content_tag(:span, content, :class => 'add-on')
38
37
  end
39
38
 
40
- def controls_wrapping(&block)
39
+ def form_group_wrapping(&block)
41
40
  template.content_tag(:div,
42
- [template.capture(&block), error_html].join("\n").html_safe,
43
- controls_wrapper_html_options
41
+ template.capture(&block).html_safe,
42
+ wrapper_html_options
44
43
  )
45
44
  end
46
-
47
- def controls_wrapper_html_options
48
- {
49
- :class => "controls"
50
- }
51
- end
52
45
 
53
46
  def wrapper_html_options
54
47
  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
48
+ options[:class] << " form-group"
70
49
  end
71
50
  end
72
51
 
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
52
+ def add_on_wrapper_classes(options)
53
+ [:prepend, :append, :prepend_content, :append_content].map do |key|
54
+ "input-#{key.to_s.gsub('_content', '')}" if options[key]
77
55
  end
78
56
  end
79
57
 
@@ -5,25 +5,33 @@ module FormtasticBootstrap
5
5
  include Base
6
6
 
7
7
  def to_html
8
- control_group_wrapping do
9
- (options[:label_outside] ? control_label_html : "".html_safe) <<
10
- hidden_field_html <<
11
- controls_wrapping do
12
- [label_with_nested_checkbox, hint_html].join("\n").html_safe
13
- end
8
+ checkbox_wrapping do
9
+ "".html_safe <<
10
+ [label_with_nested_checkbox, hint_html].join("\n").html_safe
14
11
  end
15
12
  end
16
13
 
17
14
  def label_with_nested_checkbox
18
15
  builder.label(
19
16
  method,
20
- options[:label_outside] ? check_box_html : label_text_with_embedded_checkbox,
21
- label_html_options.tap do |options|
22
- options[:class] << "checkbox"
23
- end
17
+ label_text_with_embedded_checkbox,
18
+ label_html_options
24
19
  )
25
20
  end
26
21
 
22
+ def checkbox_wrapping(&block)
23
+ template.content_tag(:div,
24
+ template.capture(&block).html_safe,
25
+ wrapper_html_options
26
+ )
27
+ end
28
+
29
+ def wrapper_html_options
30
+ super.tap do |options|
31
+ options[:class] = (options[:class].split - ["form-group"] + ["checkbox"]).join(" ")
32
+ end
33
+ end
34
+
27
35
  end
28
36
  end
29
37
  end
@@ -8,30 +8,31 @@ module FormtasticBootstrap
8
8
  # TODO Support .inline
9
9
 
10
10
  def to_html
11
- control_group_wrapping do
12
- control_label_html <<
13
- hidden_field_for_all <<
14
- controls_wrapping do
15
- collection.map { |choice|
16
- choice_html(choice)
17
- }.join("\n").html_safe
18
- end
11
+ form_group_wrapping do
12
+ label_html <<
13
+ hidden_field_for_all << # Might need to remove this guy.
14
+ collection.map { |choice|
15
+ choice_html(choice)
16
+ }.join("\n").html_safe
19
17
  end
20
18
  end
21
19
 
22
- def choice_wrapping_html_options(choice)
23
- super(choice).tap do |options|
24
- options[:class] = ((options[:class].split) << "checkbox").join(" ")
20
+ def choice_html(choice)
21
+ checkbox_wrapping do
22
+ template.content_tag(:label,
23
+ hidden_fields? ?
24
+ check_box_with_hidden_input(choice) :
25
+ check_box_without_hidden_input(choice) <<
26
+ choice_label(choice),
27
+ label_html_options.merge(choice_label_html_options(choice))
28
+ )
25
29
  end
26
30
  end
27
31
 
28
- def choice_html(choice)
29
- template.content_tag(:label,
30
- hidden_fields? ?
31
- check_box_with_hidden_input(choice) :
32
- check_box_without_hidden_input(choice) <<
33
- choice_label(choice),
34
- label_html_options.merge(choice_label_html_options(choice))
32
+ def checkbox_wrapping(&block)
33
+ template.content_tag(:div,
34
+ template.capture(&block).html_safe,
35
+ :class => "checkbox"
35
36
  )
36
37
  end
37
38
 
@@ -6,7 +6,7 @@ module FormtasticBootstrap
6
6
 
7
7
  def to_html
8
8
  bootstrap_wrapping do
9
- builder.email_field(method, input_html_options)
9
+ builder.email_field(method, form_control_input_html_options)
10
10
  end
11
11
  end
12
12
 
@@ -6,10 +6,10 @@ module FormtasticBootstrap
6
6
 
7
7
  def to_html
8
8
  bootstrap_wrapping do
9
- builder.number_field(method, input_html_options)
9
+ builder.number_field(method, form_control_input_html_options)
10
10
  end
11
11
  end
12
-
12
+
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -6,7 +6,7 @@ module FormtasticBootstrap
6
6
 
7
7
  def to_html
8
8
  bootstrap_wrapping do
9
- builder.password_field(method, input_html_options)
9
+ builder.password_field(method, form_control_input_html_options)
10
10
  end
11
11
  end
12
12
 
@@ -6,7 +6,7 @@ module FormtasticBootstrap
6
6
 
7
7
  def to_html
8
8
  bootstrap_wrapping do
9
- builder.phone_field(method, input_html_options)
9
+ builder.phone_field(method, form_control_input_html_options)
10
10
  end
11
11
  end
12
12
 
@@ -8,13 +8,11 @@ module FormtasticBootstrap
8
8
  # TODO Support .inline
9
9
 
10
10
  def to_html
11
- control_group_wrapping do
12
- control_label_html <<
13
- controls_wrapping do
14
- collection.map { |choice|
15
- choice_html(choice)
16
- }.join("\n").html_safe
17
- end
11
+ form_group_wrapping do
12
+ label_html <<
13
+ collection.map { |choice|
14
+ choice_html(choice)
15
+ }.join("\n").html_safe
18
16
  end
19
17
  end
20
18
 
@@ -26,21 +24,24 @@ module FormtasticBootstrap
26
24
  end
27
25
  end
28
26
 
29
- # This came from check_boxes. Do needed refactoring.
30
- def choice_wrapping_html_options(choice)
31
- super(choice).tap do |options|
32
- options[:class] = ((options[:class].split) << "radio").join(" ")
27
+ def choice_html(choice)
28
+ radio_wrapping do
29
+ template.content_tag(:label,
30
+ builder.radio_button(input_name, choice_value(choice), input_html_options.merge(choice_html_options(choice)).merge(:required => false)) <<
31
+ choice_label(choice),
32
+ label_html_options.merge(choice_label_html_options(choice))
33
+ )
33
34
  end
34
35
  end
35
36
 
36
- def choice_html(choice)
37
- template.content_tag(:label,
38
- builder.radio_button(input_name, choice_value(choice), input_html_options.merge(choice_html_options(choice)).merge(:required => false)) <<
39
- choice_label(choice),
40
- label_html_options.merge(choice_label_html_options(choice))
37
+ def radio_wrapping(&block)
38
+ template.content_tag(:div,
39
+ template.capture(&block).html_safe,
40
+ :class => "radio"
41
41
  )
42
42
  end
43
-
43
+
44
44
  end
45
45
  end
46
- end
46
+ end
47
+