bootstrap_concerns 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d61b71941d532fae03d4f55f7a9f96c904875e66ddcce382b81c20ae83af6dcf
4
+ data.tar.gz: 1e9c94c3be1da17c995f5fb9c46ff374cf91e64ddcb08bac56385ca320257f83
5
+ SHA512:
6
+ metadata.gz: 69b1d85e690aa244fd412110ff6595830079451933aaa0cf627ebdf59866c231b728a384e532bcf423f362c2804db5d94f4f2a82c8b3156badf44cba13fc8c49
7
+ data.tar.gz: e1f878fc1661b73924ff27d3c11d6d216533290de6cddee05e241c69aa3f31e7349633022d2fd049bdfbfac6bd4ffd2743b3898b385abdf2054049b381a1eec5
@@ -0,0 +1,30 @@
1
+ module BootstrapConcerns
2
+ module ButtonHelper
3
+ def bs_button_to(name = nil, options = nil, html_options = nil, &)
4
+ bs_link_or_button_to(:button_to, name, options, html_options, &)
5
+ end
6
+
7
+ def bs_link_to(name = nil, options = nil, html_options = nil, &)
8
+ bs_link_or_button_to(:link_to, name, options, html_options, &)
9
+ end
10
+
11
+ def bs_link_or_button_to(method_name, name, options, html_options, &)
12
+ normalized_html_options =
13
+ if block_given?
14
+ options ||= {}
15
+ else
16
+ html_options ||= {}
17
+ end
18
+
19
+ normalized_html_options.merge!(Option.options_with_button_class(normalized_html_options))
20
+
21
+ public_send(
22
+ method_name,
23
+ name,
24
+ options,
25
+ html_options,
26
+ &
27
+ )
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,155 @@
1
+ module BootstrapConcerns
2
+ module FormBuilder
3
+ FORM_LABEL_BASE_CLASS = "form-label".freeze
4
+ FORM_CHECK_INPUT_BASE_CLASS = "form-check-input".freeze
5
+ FORM_CONTROL_BASE_CLASS = "form-control".freeze
6
+ FORM_CONTROL_PLAIN_TEXT_BASE_CLASS = "form-control-plaintext".freeze
7
+ FORM_SELECT_BASE_CLASS = "form-select".freeze
8
+ REQUIRED_CLASS = "required".freeze
9
+
10
+ def bs_button(value = nil, options = {}, &)
11
+ normalized_options = value.is_a?(Hash) ? value : options
12
+ normalized_options.merge!(Option.options_with_button_class(normalized_options))
13
+
14
+ button(value, options, &)
15
+ end
16
+
17
+ def bs_check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
18
+ check_box(method, options_with_form_check_input_class(options), checked_value, unchecked_value)
19
+ end
20
+
21
+ def bs_check_label(method, text = nil, options = {}, &)
22
+ normalized_options = text.is_a?(Hash) ? text : options
23
+ normalized_options.merge!(options_with_form_label_class(normalized_options))
24
+
25
+ label(method, text, options, &)
26
+ end
27
+
28
+ def bs_color_field(method, options = {})
29
+ color_field(method, options_with_form_control_class(options))
30
+ end
31
+
32
+ def bs_collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
33
+ collection_select(
34
+ method,
35
+ collection,
36
+ value_method,
37
+ text_method,
38
+ options,
39
+ options_with_form_select_class(options, html_options)
40
+ )
41
+ end
42
+
43
+ def bs_date_field(method, options = {})
44
+ date_field(method, options_with_form_control_class(options))
45
+ end
46
+
47
+ def bs_datetime_field(method, options = {})
48
+ datetime_field(method, options_with_form_control_class(options))
49
+ end
50
+
51
+ def bs_email_field(method, options = {})
52
+ email_field(method, options_with_form_control_class(options))
53
+ end
54
+
55
+ def bs_grouped_collection_select(
56
+ method,
57
+ collection,
58
+ group_method,
59
+ group_label_method,
60
+ option_key_method,
61
+ option_value_method,
62
+ options = {},
63
+ html_options = {}
64
+ )
65
+ grouped_collection_select(
66
+ method,
67
+ collection,
68
+ group_method,
69
+ group_label_method,
70
+ option_key_method,
71
+ option_value_method,
72
+ options,
73
+ options_with_form_select_class(options, html_options)
74
+ )
75
+ end
76
+
77
+ def bs_label(method, text = nil, options = {}, &)
78
+ normalized_options = text.is_a?(Hash) ? text : options
79
+ normalized_options.merge!(options_with_form_label_class(normalized_options))
80
+
81
+ label(method, text, options, &)
82
+ end
83
+
84
+ def bs_number_field(method, options = {})
85
+ number_field(method, options_with_form_control_class(options))
86
+ end
87
+
88
+ def bs_password_field(method, options = {})
89
+ password_field(method, options_with_form_control_class(options))
90
+ end
91
+
92
+ def bs_radio_button(method, tag_value, options = {})
93
+ radio_button(method, tag_value, options_with_form_check_input_class(options))
94
+ end
95
+
96
+ def bs_search_field(method, options = {})
97
+ search_field(method, options_with_form_control_class(options))
98
+ end
99
+
100
+ def bs_select(method, choices = nil, options = {}, html_options = {}, &)
101
+ select(method, choices, options, options_with_form_select_class(options, html_options), &)
102
+ end
103
+
104
+ def bs_submit(value = nil, options = {})
105
+ normalized_options = value.is_a?(Hash) ? value : options
106
+ normalized_options.merge!(Option.options_with_button_class(normalized_options))
107
+
108
+ submit(value, options)
109
+ end
110
+
111
+ def bs_phone_field(method, options = {})
112
+ phone_field(method, options_with_form_control_class(options))
113
+ end
114
+
115
+ def bs_plain_text_field(method, options = {})
116
+ text_field(
117
+ method,
118
+ Option.options_with_base_class(options, FORM_CONTROL_PLAIN_TEXT_BASE_CLASS).merge(readonly: true)
119
+ )
120
+ end
121
+
122
+ def bs_text_field(method, options = {})
123
+ text_field(method, options_with_form_control_class(options))
124
+ end
125
+
126
+ def bs_text_area(method, options = {})
127
+ text_area(method, options_with_form_control_class(options))
128
+ end
129
+
130
+ def bs_url_field(method, options = {})
131
+ url_field(method, options_with_form_control_class(options))
132
+ end
133
+
134
+ private
135
+
136
+ def options_with_form_check_input_class(options)
137
+ Option.options_with_base_class(options, FORM_CHECK_INPUT_BASE_CLASS)
138
+ end
139
+
140
+ def options_with_form_control_class(options)
141
+ size = Option.prefixed_option(options, key: :size, prefix: FORM_CONTROL_BASE_CLASS)
142
+ Option.options_with_base_class(options, FORM_CONTROL_BASE_CLASS, size)
143
+ end
144
+
145
+ def options_with_form_select_class(options, html_options)
146
+ size = Option.prefixed_option(options, key: :size, prefix: FORM_SELECT_BASE_CLASS)
147
+ Option.options_with_base_class(html_options, FORM_SELECT_BASE_CLASS, size)
148
+ end
149
+
150
+ def options_with_form_label_class(options)
151
+ required = REQUIRED_CLASS if options.delete(:required)
152
+ Option.options_with_base_class(options, FORM_LABEL_BASE_CLASS, required)
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,24 @@
1
+ module BootstrapConcerns
2
+ class Option
3
+ BUTTON_BASE_CLASS = "btn".freeze
4
+ DEFAULT_BUTTON_COLOR = "primary".freeze
5
+
6
+ class << self
7
+ def options_with_button_class(options)
8
+ color = prefixed_option(options, key: :color, prefix: BUTTON_BASE_CLASS, default: DEFAULT_BUTTON_COLOR)
9
+ size = prefixed_option(options, key: :size, prefix: BUTTON_BASE_CLASS)
10
+ options_with_base_class(options, BUTTON_BASE_CLASS, color, size)
11
+ end
12
+
13
+ def prefixed_option(options, key:, prefix:, default: nil)
14
+ (options.delete(key) || default)&.then { "#{prefix}-#{_1}" }
15
+ end
16
+
17
+ def options_with_base_class(options, *base_class)
18
+ options.merge(
19
+ class: (base_class + [options[:class]]).compact.join(" ")
20
+ )
21
+ end
22
+ end
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bootstrap_concerns
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Evan Brooks
8
+ - Robert Keresnyei
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-02-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionview
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: standard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1'
55
+ executables: []
56
+ extensions: []
57
+ extra_rdoc_files: []
58
+ files:
59
+ - lib/bootstrap_concerns/button_helper.rb
60
+ - lib/bootstrap_concerns/form_builder.rb
61
+ - lib/bootstrap_concerns/option.rb
62
+ homepage: https://github.com/swiftvee/bootstrap_form_builder_concern
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 3.4.0
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubygems_version: 3.6.3
81
+ specification_version: 4
82
+ summary: Concerns for building Bootstrap components with Ruby on Rails.
83
+ test_files: []