rails_bootstrap_form 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +111 -2
  3. data/Gemfile.lock +9 -3
  4. data/README.md +68 -0
  5. data/Rakefile +2 -0
  6. data/demo/app/views/users/_horizontal_form.html.erb +6 -6
  7. data/demo/app/views/users/_vertical_form.html.erb +8 -8
  8. data/demo/config/database.yml +7 -15
  9. data/demo/db/schema.rb +8 -5
  10. data/gemfiles/common.gemfile +10 -2
  11. data/lib/rails_bootstrap_form/bootstrap_form_builder.rb +1 -1
  12. data/lib/rails_bootstrap_form/{components → helpers}/check_box.rb +1 -3
  13. data/lib/rails_bootstrap_form/{components → helpers}/errors.rb +1 -1
  14. data/lib/rails_bootstrap_form/{components → helpers}/help_text.rb +1 -1
  15. data/lib/rails_bootstrap_form/{components → helpers}/labels.rb +1 -1
  16. data/lib/rails_bootstrap_form/{components → helpers}/radio_button.rb +1 -3
  17. data/lib/rails_bootstrap_form/{components → helpers}/required_field.rb +1 -1
  18. data/lib/rails_bootstrap_form/helpers.rb +15 -0
  19. data/lib/rails_bootstrap_form/inputs/base.rb +33 -0
  20. data/lib/rails_bootstrap_form/inputs/check_box.rb +45 -0
  21. data/lib/rails_bootstrap_form/inputs/collection_check_boxes.rb +41 -0
  22. data/lib/rails_bootstrap_form/inputs/collection_radio_buttons.rb +39 -0
  23. data/lib/rails_bootstrap_form/inputs/collection_select.rb +21 -0
  24. data/lib/rails_bootstrap_form/inputs/color_field.rb +21 -0
  25. data/lib/rails_bootstrap_form/inputs/date_field.rb +15 -0
  26. data/lib/rails_bootstrap_form/inputs/date_select.rb +15 -0
  27. data/lib/rails_bootstrap_form/inputs/datetime_field.rb +15 -0
  28. data/lib/rails_bootstrap_form/inputs/datetime_local_field.rb +15 -0
  29. data/lib/rails_bootstrap_form/inputs/datetime_select.rb +15 -0
  30. data/lib/rails_bootstrap_form/inputs/email_field.rb +15 -0
  31. data/lib/rails_bootstrap_form/inputs/file_field.rb +15 -0
  32. data/lib/rails_bootstrap_form/inputs/grouped_collection_select.rb +21 -0
  33. data/lib/rails_bootstrap_form/inputs/hidden_field.rb +19 -0
  34. data/lib/rails_bootstrap_form/inputs/month_field.rb +15 -0
  35. data/lib/rails_bootstrap_form/inputs/number_field.rb +15 -0
  36. data/lib/rails_bootstrap_form/inputs/password_field.rb +15 -0
  37. data/lib/rails_bootstrap_form/inputs/phone_field.rb +15 -0
  38. data/lib/rails_bootstrap_form/inputs/radio_button.rb +45 -0
  39. data/lib/rails_bootstrap_form/inputs/range_field.rb +21 -0
  40. data/lib/rails_bootstrap_form/inputs/search_field.rb +15 -0
  41. data/lib/rails_bootstrap_form/inputs/select.rb +21 -0
  42. data/lib/rails_bootstrap_form/inputs/static_field.rb +30 -0
  43. data/lib/rails_bootstrap_form/inputs/telephone_field.rb +15 -0
  44. data/lib/rails_bootstrap_form/inputs/text_area.rb +15 -0
  45. data/lib/rails_bootstrap_form/inputs/text_field.rb +15 -0
  46. data/lib/rails_bootstrap_form/inputs/time_field.rb +15 -0
  47. data/lib/rails_bootstrap_form/inputs/time_select.rb +15 -0
  48. data/lib/rails_bootstrap_form/inputs/time_zone_select.rb +21 -0
  49. data/lib/rails_bootstrap_form/inputs/url_field.rb +15 -0
  50. data/lib/rails_bootstrap_form/inputs/week_field.rb +15 -0
  51. data/lib/rails_bootstrap_form/inputs.rb +67 -235
  52. data/lib/rails_bootstrap_form/version.rb +1 -1
  53. data/lib/rails_bootstrap_form.rb +2 -2
  54. metadata +69 -10
  55. data/lib/rails_bootstrap_form/components.rb +0 -23
@@ -0,0 +1,39 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module CollectionRadioButtons
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ def collection_radio_buttons(attribute, collection, value_method, text_method, options = {}, html_options = {}, &block)
12
+ inputs = ActiveSupport::SafeBuffer.new
13
+
14
+ collection.each do |object|
15
+ input_value = value_method.respond_to?(:call) ? value_method.call(object) : object.send(value_method)
16
+ input_options = {
17
+ bootstrap_form: {
18
+ label_text: text_method.respond_to?(:call) ? text_method.call(object) : object.send(text_method),
19
+ inline: true
20
+ }
21
+ }.deep_merge!(options)
22
+
23
+ if (checked = input_options[:checked])
24
+ input_options[:checked] = collection_input_checked?(checked, object, object.send(value_method))
25
+ end
26
+
27
+ inputs << radio_button(attribute, input_value, input_options)
28
+ end
29
+
30
+ field_wrapper_builder(attribute, options, html_options) do
31
+ concat(tag.div(class: control_specific_class(:collection_radio_buttons)) do
32
+ concat(inputs)
33
+ end)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module CollectionSelect
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ def collection_select(attribute, collection, value_method, text_method, options = {}, html_options = {})
12
+ options = {bootstrap_form: {field_class: "form-select"}}.deep_merge!(options)
13
+
14
+ field_wrapper_builder(attribute, options, html_options) do
15
+ super(attribute, collection, value_method, text_method, options, html_options)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module ColorField
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ def color_field(attribute, options = {})
12
+ options = {bootstrap_form: {field_class: "form-control form-control-color"}}.deep_merge!(options)
13
+
14
+ field_wrapper_builder(attribute, options) do
15
+ super(attribute, options)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module DateField
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ bootstrap_field :date_field
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module DateSelect
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ bootstrap_select_group :date_select
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module DatetimeField
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ bootstrap_field :datetime_field
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module DatetimeLocalField
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ bootstrap_field :datetime_local_field
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module DatetimeSelect
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ bootstrap_select_group :datetime_select
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module EmailField
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ bootstrap_field :email_field
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module FileField
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ bootstrap_field :file_field
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module GroupedCollectionSelect
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ def grouped_collection_select(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
12
+ options = {bootstrap_form: {field_class: "form-select"}}.deep_merge!(options)
13
+
14
+ field_wrapper_builder(attribute, options, html_options) do
15
+ super(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, options, html_options)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module HiddenField
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ def hidden_field(attribute, options = {})
12
+ options[:value] = object.send(attribute) unless options.key?(:value)
13
+
14
+ super(attribute, options)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module MonthField
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ bootstrap_field :month_field
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module NumberField
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ bootstrap_field :number_field
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module PasswordField
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ bootstrap_field :password_field
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module PhoneField
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ bootstrap_field :phone_field
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,45 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module RadioButton
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ def radio_button(attribute, value, options = {})
12
+ bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap_form))
13
+
14
+ options[:class] = radio_button_classes(attribute, options)
15
+
16
+ radio_button_field = super(attribute, value, options)
17
+ radio_button_help_text = help_text(attribute, bootstrap_options)
18
+
19
+ radio_button_label = radio_button_label(attribute, value, options, bootstrap_options)
20
+
21
+ radio_button_html = tag.div(**radio_button_wrapper_options(bootstrap_options)) do
22
+ concat(radio_button_field)
23
+ concat(radio_button_label)
24
+ concat(radio_button_help_text) unless bootstrap_options.inline?
25
+ concat(generate_error(attribute)) if (is_invalid?(attribute) && !bootstrap_options.inline?)
26
+ end
27
+
28
+ if bootstrap_options.inline?
29
+ radio_button_html
30
+ else
31
+ if bootstrap_options.layout_horizontal?
32
+ tag.div(class: field_wrapper_classes(bootstrap_options)) do
33
+ tag.div(class: radio_button_container_classes(bootstrap_options)) do
34
+ radio_button_html
35
+ end
36
+ end
37
+ else
38
+ radio_button_html
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module RangeField
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ def range_field(attribute, options = {})
12
+ options = {bootstrap_form: {field_class: "form-range"}}.deep_merge!(options)
13
+
14
+ field_wrapper_builder(attribute, options) do
15
+ super(attribute, options)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module SearchField
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ bootstrap_field :search_field
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module Select
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ def select(attribute, choices = nil, options = {}, html_options = {}, &block)
12
+ options = {bootstrap_form: {field_class: "form-select"}}.deep_merge!(options)
13
+
14
+ field_wrapper_builder(attribute, options, html_options) do
15
+ super(attribute, choices, options, html_options, &block)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module StaticField
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ def static_field(*args)
12
+ options = args.extract_options!
13
+ attribute = args.first
14
+
15
+ static_options = options.merge(
16
+ readonly: true,
17
+ disabled: true,
18
+ bootstrap_form: {
19
+ field_class: bootstrap_form_options.static_field_class
20
+ }
21
+ )
22
+
23
+ static_options[:value] = object.send(attribute) unless options.key?(:value)
24
+
25
+ text_field(attribute, static_options)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module TelephoneField
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ bootstrap_field :telephone_field
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module TextArea
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ bootstrap_field :text_area
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module TextField
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ bootstrap_field :text_field
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module TimeField
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ bootstrap_field :time_field
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module TimeSelect
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ bootstrap_select_group :time_select
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module TimeZoneSelect
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ def time_zone_select(attribute, priority_zones = nil, options = {}, html_options = {})
12
+ options = {bootstrap_form: {field_class: "form-select"}}.deep_merge!(options)
13
+
14
+ field_wrapper_builder(attribute, options, html_options) do
15
+ super(attribute, priority_zones, options, html_options)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module UrlField
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ bootstrap_field :url_field
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module WeekField
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ bootstrap_field :week_field
12
+ end
13
+ end
14
+ end
15
+ end