bootstrap5_helper 1.2.0.pre3 → 2.0.0.beta

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d017b530462e5d5dfbb5344bedc7496990431dedb528d533940811272a9f074
4
- data.tar.gz: 3602757ad95632f48724ef5ef85f35803b9b8cde5081722cae13eb2547370c1f
3
+ metadata.gz: b80e1976cb72cb25fc00dd66922607696c0ecd768f5a13a4fe4133a0b86c8df0
4
+ data.tar.gz: 490c5c5908ae56ca91ea9be973a52c3a9fc10d9e98f18b80518663816c939259
5
5
  SHA512:
6
- metadata.gz: f06b5c4a4dea910830074273ee01fb01798bc21286056ff0f15dc9c3503b5f65c5bb0dc37fbd596be0552909443a7ea8a92c5753909b0a465ee7afc71400ded5
7
- data.tar.gz: 3f040da98e4b6c2ec59ae6bec1f32513673bce8dfea85536a33c5bbacbcd428c13d3c08e77c71404bc910d42bbaf6f8998c5b9c481295a5753461a8e4c1ef1bd
6
+ metadata.gz: 8aa38ac1d5a6577d1f675ad65fee42aa6bd3b4bb9a48193b866ebfab2663de1955e2a5c81cfb3fba19ee51f977bb9bc4e62bad8395b74f3e51f7fec939a1cc2f
7
+ data.tar.gz: f10d1aedb9e4b448a1d0c11ac157d00733dc46a9f64427a0bfc3d457465ccc12c6a4f9e56892d90811c28a09b994f90a0e0aa6099b442631da21f340f39aeb7e
@@ -17,14 +17,15 @@ module Bootstrap5Helper
17
17
  super(template)
18
18
 
19
19
  @parent = parent_id
20
- @id = opts.fetch(:id, uuid)
21
- @class = opts.fetch(:class, '')
22
- @data = opts.fetch(:data, {})
23
- @expanded = opts.fetch(:expanded, false)
24
- @collapse = opts.fetch(:collapse, {})
25
- @collapse_id = @collapse.fetch(:id, uuid)
26
- @collapse_klass = @collapse.fetch(:class, '')
27
- @collapse_data = @collapse.fetch(:data, {})
20
+ @attrs = opts
21
+ @id = @attrs.delete(:id) { uuid }
22
+ @class = @attrs.delete(:class) { '' }
23
+ @data = @attrs.delete(:data) { {} }
24
+ @expanded = @attrs.delete(:expanded) { false }
25
+ @collapse = @attrs.delete(:collapse) { {} }
26
+ @collapse_id = @collapse.delete(:id) { uuid }
27
+ @collapse_klass = @collapse.delete(:class) { '' }
28
+ @collapse_data = @collapse.delete(:data) { {} }
28
29
  @header_id = uuid
29
30
  @content = block || proc { '' }
30
31
  end
@@ -51,15 +52,17 @@ module Bootstrap5Helper
51
52
  def header(*tag_or_options, &block)
52
53
  tag, args = parse_tag_or_options(*tag_or_options, {})
53
54
 
54
- @header_id = args.fetch(:id, @header_id)
55
- klass = args.fetch(:class, '')
56
- data = args.fetch(:data, {})
55
+ @header_id = args.delete(:id) { @header_id }
56
+ klass = args.delete(:class) { '' }
57
+ data = args.delete(:data) { {} }
57
58
 
58
59
  content_tag(
59
60
  tag || config({ accordions: :header }, :h2),
60
- id: @header_id,
61
- class: "accordion-header #{klass}",
62
- data: data
61
+ {
62
+ id: @header_id,
63
+ class: "accordion-header #{klass}",
64
+ data: data
65
+ }.merge(args)
63
66
  ) do
64
67
  content_tag(
65
68
  :button,
@@ -90,9 +93,9 @@ module Bootstrap5Helper
90
93
  # @return [String]
91
94
  #
92
95
  def body(opts = {}, &block)
93
- id = opts.fetch(:id, uuid)
94
- klass = opts.fetch(:class, '')
95
- data = opts.fetch(:data, {})
96
+ id = opts.delete(:id) { uuid }
97
+ klass = opts.delete(:class) { '' }
98
+ data = opts.delete(:data) { {} }
96
99
 
97
100
  content_tag(
98
101
  :div,
@@ -105,9 +108,11 @@ module Bootstrap5Helper
105
108
  ) do
106
109
  content_tag(
107
110
  :div,
108
- id: id,
109
- class: "accordion-body #{klass}",
110
- data: data,
111
+ {
112
+ id: id,
113
+ class: "accordion-body #{klass}",
114
+ data: data
115
+ }.merge(opts),
111
116
  &block
112
117
  )
113
118
  end
@@ -119,7 +124,14 @@ module Bootstrap5Helper
119
124
  # @return [String]
120
125
  #
121
126
  def to_s
122
- content_tag :div, id: @id, class: "accordion-item #{@class}", data: @data do
127
+ content_tag(
128
+ :div,
129
+ {
130
+ id: @id,
131
+ class: "accordion-item #{@class}",
132
+ data: @data
133
+ }.merge(@attrs)
134
+ ) do
123
135
  @content.call(self)
124
136
  end
125
137
  end
@@ -16,11 +16,12 @@ module Bootstrap5Helper
16
16
  def initialize(template, opts = {}, &block)
17
17
  super(template)
18
18
 
19
- @id = opts.fetch(:id, uuid)
20
- @class = opts.fetch(:class, '')
21
- @data = opts.fetch(:data, {})
22
- @always_open = opts.fetch(:always_open, false)
23
- @flush = opts.fetch(:flush, false)
19
+ @attrs = opts
20
+ @id = @attrs.delete(:id) { uuid }
21
+ @class = @attrs.delete(:class) { '' }
22
+ @data = @attrs.delete(:data) { {} }
23
+ @always_open = @attrs.delete(:always_open) { false }
24
+ @flush = @attrs.delete(:flush) { false }
24
25
  @content = block || proc { '' }
25
26
  end
26
27
 
@@ -39,9 +40,11 @@ module Bootstrap5Helper
39
40
  def to_s
40
41
  content_tag(
41
42
  :div,
42
- id: @id,
43
- class: "accordion #{@flush ? 'accordion-flush' : ''} #{@class}",
44
- data: @data
43
+ {
44
+ id: @id,
45
+ class: "accordion #{@flush ? 'accordion-flush' : ''} #{@class}",
46
+ data: @data
47
+ }.merge(@attrs)
45
48
  ) do
46
49
  @content.call(self)
47
50
  end
@@ -17,10 +17,11 @@ module Bootstrap5Helper
17
17
  super(template)
18
18
  @context, args = parse_context_or_options(context_or_options, opts)
19
19
 
20
- @id = args.fetch(:id, uuid)
21
- @class = args.fetch(:class, '')
22
- @data = args.fetch(:data, {})
23
- @dismissible = args.fetch(:dismissible, false)
20
+ @attrs = args
21
+ @id = @attrs.delete(:id) { uuid }
22
+ @class = @attrs.delete(:class) { '' }
23
+ @data = @attrs.delete(:data) { {} }
24
+ @dismissible = @attrs.delete(:dismissible) { false }
24
25
  @content = block || proc { '' }
25
26
  end
26
27
 
@@ -43,7 +44,14 @@ module Bootstrap5Helper
43
44
  # @return [String]
44
45
  #
45
46
  def to_s
46
- content_tag(:div, id: @id, class: container_class, data: @data) do
47
+ content_tag(
48
+ :div,
49
+ {
50
+ id: @id,
51
+ class: container_class,
52
+ data: @data
53
+ }.merge(@attrs)
54
+ ) do
47
55
  concat(@dismissible ? close_button : '')
48
56
  @content.call(self)
49
57
  end
@@ -16,9 +16,10 @@ module Bootstrap5Helper
16
16
  super(template)
17
17
  @context, args = parse_context_or_options(context_or_options, opts)
18
18
 
19
- @id = args.fetch(:id, nil)
20
- @class = args.fetch(:class, '')
21
- @data = args.fetch(:data, {})
19
+ @attrs = args
20
+ @id = @attrs.delete(:id) { nil }
21
+ @class = @attrs.delete(:class) { '' }
22
+ @data = @attrs.delete(:data) { {} }
22
23
  @content = block || proc { '' }
23
24
  end
24
25
 
@@ -29,9 +30,11 @@ module Bootstrap5Helper
29
30
  def to_s
30
31
  content_tag(
31
32
  config({ badges: :base }, :span),
32
- id: @id,
33
- class: container_class,
34
- data: @data
33
+ {
34
+ id: @id,
35
+ class: container_class,
36
+ data: @data
37
+ }.merge(@attrs)
35
38
  ) do
36
39
  @content.call(self)
37
40
  end
@@ -15,9 +15,10 @@ module Bootstrap5Helper
15
15
  super(template)
16
16
  @context, args = parse_context_or_options(context_or_options, opts)
17
17
 
18
- @id = args.fetch(:id, nil)
19
- @class = args.fetch(:class, '')
20
- @data = args.fetch(:data, {})
18
+ @attrs = args
19
+ @id = @attrs.delete(:id) { nil }
20
+ @class = @attrs.delete(:class) { '' }
21
+ @data = @attrs.delete(:data) { {} }
21
22
  @content = block || proc { '' }
22
23
  end
23
24
 
@@ -40,7 +41,14 @@ module Bootstrap5Helper
40
41
  # @return [String]
41
42
  #
42
43
  def to_s
43
- content_tag :div, id: @id, class: container_class, data: @data do
44
+ content_tag(
45
+ :div,
46
+ {
47
+ id: @id,
48
+ class: container_class,
49
+ data: @data
50
+ }.merge(@attrs)
51
+ ) do
44
52
  @content.call(self)
45
53
  end
46
54
  end
@@ -1,7 +1,7 @@
1
1
  module Bootstrap5Helper
2
- # Used to build Bootstrap Card components. Cards are wildly used through Bootstrap 4.
3
- #
4
- #
2
+ # rubocop:disable Metrics/ClassLength
3
+
4
+ # Used to build Bootstrap Card components..
5
5
  class Card < Component
6
6
  # Used to initialize a new Card component.
7
7
  #
@@ -15,9 +15,10 @@ module Bootstrap5Helper
15
15
  def initialize(template, opts = {}, &block)
16
16
  super(template)
17
17
 
18
- @id = opts.fetch(:id, '')
19
- @class = opts.fetch(:class, '')
20
- @data = opts.fetch(:data, nil)
18
+ @attrs = opts
19
+ @id = @attrs.delete(:id) { '' }
20
+ @class = @attrs.delete(:class) { '' }
21
+ @data = @attrs.delete(:data) { {} }
21
22
  @content = block || proc { '' }
22
23
  end
23
24
 
@@ -228,7 +229,14 @@ module Bootstrap5Helper
228
229
  # @return [String]
229
230
  #
230
231
  def to_s
231
- content_tag :div, id: @id, class: "card #{@class}", data: @data do
232
+ content_tag(
233
+ :div,
234
+ {
235
+ id: @id,
236
+ class: "card #{@class}",
237
+ data: @data
238
+ }.merge(@attrs)
239
+ ) do
232
240
  @content.call(self)
233
241
  end
234
242
  end
@@ -256,17 +264,21 @@ module Bootstrap5Helper
256
264
  # @return [String]
257
265
  #
258
266
  def build_sub_component(tag, type, args, &block)
259
- id = args.fetch(:id, '')
260
- klass = args.fetch(:class, '')
261
- data = args.fetch(:data, {})
267
+ attrs = args
268
+ id = attrs.delete(:id) { '' }
269
+ klass = attrs.delete(:class) { '' }
270
+ data = attrs.delete(:data) { {} }
262
271
 
263
272
  content_tag(
264
273
  tag,
265
- id: id,
266
- class: "card-#{type} #{klass}",
267
- data: data,
274
+ {
275
+ id: id,
276
+ class: "card-#{type} #{klass}",
277
+ data: data
278
+ }.merge(attrs),
268
279
  &block
269
280
  )
270
281
  end
271
282
  end
283
+ # rubocop:enable Metrics/ClassLength
272
284
  end
@@ -20,9 +20,11 @@ module Bootstrap5Helper
20
20
  def initialize(template, *context_or_options, &block)
21
21
  super(template)
22
22
  @context, args = parse_context_or_options(*context_or_options, {})
23
- @id = args.fetch(:id, '')
24
- @class = args.fetch(:class, '')
25
- @data = args.fetch(:data, nil)
23
+
24
+ @attrs = args
25
+ @id = @attrs.delete(:id) { '' }
26
+ @class = @attrs.delete(:class) { '' }
27
+ @data = @attrs.delete(:data) { {} }
26
28
  @content = block || proc { '' }
27
29
  end
28
30
 
@@ -47,13 +49,14 @@ module Bootstrap5Helper
47
49
  # @return [Nav]
48
50
  #
49
51
  def nav(*tag_or_options, &block)
50
- tag, args = parse_tag_or_options(*tag_or_options, {})
51
- args[:class] = (args[:class] || '') << ' nav-tabs card-header-tabs'
52
- args[:data] = (args[:data] || {}).merge('bs-toggle' => 'tab')
53
- args[:child] = (args[:child] || {}).merge(
54
- data: {
55
- 'bs-toggle' => 'tab',
56
- 'bs-display' => 'static'
52
+ tag, args = parse_tag_or_options(*tag_or_options, {})
53
+ args[:class] = (args[:class] || '') << ' nav-tabs card-header-tabs'
54
+ args[:bs_attrs] = (args[:bs_attrs] || {}).merge(
55
+ {
56
+ data: {
57
+ 'bs-toggle' => 'tab',
58
+ 'bs-display' => 'static'
59
+ }
57
60
  }
58
61
  )
59
62
 
@@ -82,9 +85,11 @@ module Bootstrap5Helper
82
85
  def to_s
83
86
  content_tag(
84
87
  :div,
85
- class: "card with-nav-tabs-#{@context} #{@class}",
86
- id: @id,
87
- data: @data
88
+ {
89
+ class: "card with-nav-tabs-#{@context} #{@class}",
90
+ id: @id,
91
+ data: @data
92
+ }.merge(@attrs)
88
93
  ) do
89
94
  @content.call(self)
90
95
  end
@@ -18,9 +18,10 @@ module Bootstrap5Helper
18
18
 
19
19
  @context, args = parse_context_or_options(context_or_options, opts)
20
20
 
21
- @id = args.fetch(:id, nil)
22
- @class = args.fetch(:class, '')
23
- @data = args.fetch(:data, {})
21
+ @attrs = args
22
+ @id = @attrs.delete(:id) { nil }
23
+ @class = @attrs.delete(:class) { '' }
24
+ @data = @attrs.delete(:data) { {} }
24
25
  @content = block || proc { '' }
25
26
  end
26
27
 
@@ -42,9 +43,11 @@ module Bootstrap5Helper
42
43
  def to_s
43
44
  content_tag(
44
45
  :div,
45
- id: @id,
46
- class: "input-group #{size_class} #{@class}",
47
- data: @data
46
+ {
47
+ id: @id,
48
+ class: "input-group #{size_class} #{@class}",
49
+ data: @data
50
+ }.merge(@attrs)
48
51
  ) do
49
52
  @content.call(self)
50
53
  end
@@ -12,7 +12,6 @@ module Bootstrap5Helper
12
12
  # @option opts [String] :id
13
13
  # @option opts [String] :class
14
14
  # @option opts [Hash] :data
15
- # @option opts [Hash] :wrapper
16
15
  # @option opts [Boolean] :scrollable
17
16
  # @option opts [Boolean] :vcentered
18
17
  # @option opts [Boolean] :static
@@ -22,15 +21,15 @@ module Bootstrap5Helper
22
21
  def initialize(template, opts = {}, &block)
23
22
  super(template)
24
23
 
25
- @id = opts.fetch(:id, uuid)
26
- @class = opts.fetch(:class, '')
27
- @data = opts.fetch(:data, {})
28
- @wrapper = opts.fetch(:wrapper, {})
29
- @scrollable = opts.fetch(:scrollable, false)
30
- @vcentered = opts.fetch(:vcentered, false)
31
- @static = opts.fetch(:static, false)
32
- @fullscreen = opts.fetch(:fullscreen, false)
33
- @size = opts.fetch(:size, nil)
24
+ @attrs = opts
25
+ @id = @attrs.delete(:id) { uuid }
26
+ @class = @attrs.delete(:class) { '' }
27
+ @data = @attrs.delete(:data) { {} }
28
+ @scrollable = @attrs.delete(:scrollable) { false }
29
+ @vcentered = @attrs.delete(:vcentered) { false }
30
+ @static = @attrs.delete(:static) { false }
31
+ @fullscreen = @attrs.delete(:fullscreen) { false }
32
+ @size = @attrs.delete(:size) { nil }
34
33
  @content = block || proc { '' }
35
34
  end
36
35
 
@@ -89,14 +88,19 @@ module Bootstrap5Helper
89
88
  # @return [String]
90
89
  #
91
90
  def close_button(opts = {})
92
- klass = opts.fetch(:class, '')
91
+ attrs = opts
92
+ klass = attrs.delete(:class) { '' }
93
+ data = attrs.delete(:data) { {} }
94
+ aria = attrs.delete(:aria) { {} }
93
95
 
94
96
  content_tag(
95
97
  :button,
96
- type: 'button',
97
- class: block_given? ? klass : 'btn-close',
98
- data: { 'bs-dismiss': 'modal' },
99
- aria: { label: 'Close' }
98
+ {
99
+ type: 'button',
100
+ class: block_given? ? klass : 'btn-close',
101
+ data: data.merge('bs-dismiss' => 'modal'),
102
+ aria: aria.merge(label: 'Close')
103
+ }.merge(attrs)
100
104
  ) do
101
105
  block_given? ? yield : xbutton
102
106
  end
@@ -113,25 +117,20 @@ module Bootstrap5Helper
113
117
 
114
118
  content_tag(
115
119
  :div,
116
- id: @id,
117
- class: "modal #{@class}",
118
- tabindex: -1,
119
- role: 'dialog',
120
- data: @data
120
+ {
121
+ id: @id,
122
+ class: "modal #{@class}",
123
+ tabindex: -1,
124
+ role: 'dialog',
125
+ data: @data
126
+ }.merge(@attrs)
121
127
  ) do
122
128
  content_tag(
123
129
  :div,
124
130
  class: "modal-dialog #{size} #{scrollable} #{vcentered} #{fullscreen}",
125
131
  role: 'document'
126
132
  ) do
127
- content_tag(
128
- :div,
129
- id: @wrapper.fetch(:id, nil),
130
- class: "modal-content #{@wrapper.fetch(:class, '')}",
131
- data: @wrapper.fetch(:data, {})
132
- ) do
133
- @content.call(self)
134
- end
133
+ content_tag(:div, class: 'modal-content') { @content.call(self) }
135
134
  end
136
135
  end
137
136
  end
@@ -160,15 +159,18 @@ module Bootstrap5Helper
160
159
  # @return [String]
161
160
  #
162
161
  def build_sub_component(tag, type, opts = {}, &block)
163
- id = opts.fetch(:id, nil)
164
- klass = opts.fetch(:class, '')
165
- data = opts.fetch(:data, {})
162
+ attrs = opts
163
+ id = attrs.delete(:id) { nil }
164
+ klass = attrs.delete(:class) { '' }
165
+ data = attrs.delete(:data) { {} }
166
166
 
167
167
  content_tag(
168
168
  tag,
169
- id: id,
170
- class: "modal-#{type} #{klass}",
171
- data: data,
169
+ {
170
+ id: id,
171
+ class: "modal-#{type} #{klass}",
172
+ data: data
173
+ }.merge(attrs),
172
174
  &block
173
175
  )
174
176
  end
@@ -203,8 +205,10 @@ module Bootstrap5Helper
203
205
  #
204
206
  def fullscreen
205
207
  case @fullscreen
206
- when TrueClass then 'modal-fullscreen'
207
- when String, Symbol then "modal-fullscreen-#{@fullscreen}-down "
208
+ when TrueClass
209
+ 'modal-fullscreen'
210
+ when String, Symbol
211
+ "modal-fullscreen-#{@fullscreen}-down "
208
212
  else
209
213
  ''
210
214
  end
@@ -216,9 +220,12 @@ module Bootstrap5Helper
216
220
  #
217
221
  def size
218
222
  case @size.to_s
219
- when 'xlarge', 'xl' then 'modal-xl'
220
- when 'large', 'lg' then 'modal-lg'
221
- when 'small', 'sm' then 'modal-sm'
223
+ when 'xlarge', 'xl'
224
+ 'modal-xl'
225
+ when 'large', 'lg'
226
+ 'modal-lg'
227
+ when 'small', 'sm'
228
+ 'modal-sm'
222
229
  else
223
230
  ''
224
231
  end