bootstrap4_helper 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +489 -4
- data/lib/bootstrap4_helper.rb +67 -69
- data/lib/bootstrap4_helper/accordion.rb +18 -21
- data/lib/bootstrap4_helper/accordion_group.rb +9 -13
- data/lib/bootstrap4_helper/alert.rb +6 -31
- data/lib/bootstrap4_helper/badge.rb +8 -13
- data/lib/bootstrap4_helper/card.rb +52 -39
- data/lib/bootstrap4_helper/card_column.rb +3 -6
- data/lib/bootstrap4_helper/card_deck.rb +3 -6
- data/lib/bootstrap4_helper/card_group.rb +3 -6
- data/lib/bootstrap4_helper/card_grouping.rb +6 -8
- data/lib/bootstrap4_helper/component.rb +28 -32
- data/lib/bootstrap4_helper/configuration.rb +9 -10
- data/lib/bootstrap4_helper/constants.rb +3 -5
- data/lib/bootstrap4_helper/dropdown.rb +23 -20
- data/lib/bootstrap4_helper/dropdown/menu.rb +42 -25
- data/lib/bootstrap4_helper/initialize.rb +2 -7
- data/lib/bootstrap4_helper/modal.rb +54 -37
- data/lib/bootstrap4_helper/nav.rb +32 -19
- data/lib/bootstrap4_helper/page_header.rb +38 -0
- data/lib/bootstrap4_helper/railtie.rb +1 -1
- data/lib/bootstrap4_helper/spinner.rb +12 -9
- data/lib/bootstrap4_helper/tab.rb +20 -16
- data/lib/bootstrap4_helper/tab/content.rb +25 -17
- data/lib/bootstrap4_helper/version.rb +1 -1
- metadata +58 -9
data/lib/bootstrap4_helper.rb
CHANGED
@@ -8,19 +8,16 @@ end
|
|
8
8
|
|
9
9
|
require 'bootstrap4_helper/initialize'
|
10
10
|
|
11
|
-
#
|
12
|
-
#
|
13
|
-
# use when building components. Like, so we want <h1> for Card Headers or just
|
14
|
-
# <div>'s.
|
11
|
+
# This is the module that will get included in your partials.
|
12
|
+
#
|
15
13
|
#
|
16
14
|
module Bootstrap4Helper
|
17
|
-
#
|
18
|
-
# - Creates a single Accordion element. The header component
|
15
|
+
# Creates a single Accordion element. The header component
|
19
16
|
# already provides the DOM element to link the Collapse area.
|
20
17
|
# You just need to provide the text or additional markup, if
|
21
18
|
# you want it.
|
22
19
|
#
|
23
|
-
#
|
20
|
+
# ```erb
|
24
21
|
# <%= accordion_helper do |a| %>
|
25
22
|
# <%= a.header do %>
|
26
23
|
# // Some HTML or Ruby
|
@@ -29,20 +26,19 @@ module Bootstrap4Helper
|
|
29
26
|
# // Some HTML or Ruby
|
30
27
|
# <% end %>
|
31
28
|
# <% end %>
|
32
|
-
#
|
29
|
+
# ```
|
33
30
|
#
|
34
|
-
# @param
|
31
|
+
# @param [Hash] opts
|
35
32
|
# @return [Accordion]
|
36
33
|
#
|
37
34
|
def accordion_helper(opts = {}, &block)
|
38
35
|
Accordion.new(self, opts, &block)
|
39
36
|
end
|
40
37
|
|
41
|
-
#
|
42
|
-
# - Creates a group of Accordions that stay in sync with each other.
|
38
|
+
# Creates a group of Accordions that stay in sync with each other.
|
43
39
|
# One opens, the other closes.
|
44
40
|
#
|
45
|
-
#
|
41
|
+
# ```erb
|
46
42
|
# <%= accordion_group_helper do |grp| %>
|
47
43
|
# <%= grp.accordion do |a| %>
|
48
44
|
# <%= a.header class: 'text-white bg-primary' do %>
|
@@ -62,58 +58,55 @@ module Bootstrap4Helper
|
|
62
58
|
# <% end %>
|
63
59
|
# <% end %>
|
64
60
|
# <% end $>
|
65
|
-
#
|
61
|
+
# ```
|
66
62
|
#
|
67
|
-
# @param
|
63
|
+
# @param [Mixed] args
|
68
64
|
# @return [Accordion]
|
69
65
|
#
|
70
66
|
def accordion_group_helper(*args, &block)
|
71
67
|
AccordionGroup.new(self, *args, &block)
|
72
68
|
end
|
73
69
|
|
74
|
-
#
|
75
|
-
# - Creates an Alert component.
|
70
|
+
# Creates an Alert component.
|
76
71
|
#
|
77
|
-
#
|
72
|
+
# ```erb
|
78
73
|
# <%= alert_helper :danger, dismissble: true do %>
|
79
74
|
# Something went wrong with your model data...
|
80
75
|
# <% end %>
|
81
|
-
#
|
76
|
+
# ```
|
82
77
|
#
|
83
|
-
# @
|
78
|
+
# @param [Mixed] args
|
84
79
|
# @return [String]
|
85
80
|
#
|
86
81
|
def alert_helper(*args, &block)
|
87
82
|
Alert.new(self, *args, &block)
|
88
83
|
end
|
89
84
|
|
90
|
-
#
|
91
|
-
# - Creates a badge component. Bades have a context variable. Providing nothing
|
85
|
+
# Creates a badge component. Badges have a context variable. Providing nothing
|
92
86
|
# will give you the `secondary` context.
|
93
87
|
#
|
94
|
-
#
|
88
|
+
# ```erb
|
95
89
|
# <li>
|
96
90
|
# Messages: <%= badge_helper(:primary) { @messages.count } %>
|
97
91
|
# </li>
|
98
92
|
# <li>
|
99
93
|
# Notifications: <%= badge_healper { @notifications.count } %>
|
100
94
|
# </li>
|
101
|
-
#
|
95
|
+
# ```
|
102
96
|
#
|
103
|
-
# @
|
97
|
+
# @param [Mixed] args
|
104
98
|
# @return [String]
|
105
99
|
#
|
106
100
|
def badge_helper(*args, &block)
|
107
101
|
Badge.new(self, *args, &block)
|
108
102
|
end
|
109
103
|
|
110
|
-
#
|
111
|
-
# - Creates a Card component.
|
104
|
+
# Creates a Card component.
|
112
105
|
#
|
113
106
|
#
|
114
|
-
#
|
107
|
+
# ```erb
|
115
108
|
#
|
116
|
-
#
|
109
|
+
# <%# Regular %>
|
117
110
|
#
|
118
111
|
# <%= card_helper do |c| %>
|
119
112
|
# <%= c.header class: 'text-white bg-primary' do %>
|
@@ -133,7 +126,7 @@ module Bootstrap4Helper
|
|
133
126
|
# <% end %>
|
134
127
|
# <% end %>
|
135
128
|
#
|
136
|
-
#
|
129
|
+
# <%# Horizontal %>
|
137
130
|
#
|
138
131
|
# <div class="row">
|
139
132
|
# <div class="col-sm mt-3 mb-3">
|
@@ -155,19 +148,18 @@ module Bootstrap4Helper
|
|
155
148
|
# <% end %>
|
156
149
|
# </div>
|
157
150
|
# </div>
|
158
|
-
#
|
151
|
+
# ```
|
159
152
|
#
|
160
|
-
# @param
|
153
|
+
# @param [Hash] opts
|
161
154
|
# @return [String]
|
162
155
|
#
|
163
156
|
def card_helper(opts = {}, &block)
|
164
157
|
Card.new(self, opts, &block)
|
165
158
|
end
|
166
159
|
|
167
|
-
#
|
168
|
-
# - Builds a card group.
|
160
|
+
# Builds a card group.
|
169
161
|
#
|
170
|
-
#
|
162
|
+
# ```erb
|
171
163
|
# <%= card_group_helper do |group| %>
|
172
164
|
# <%= group.card do |c| %>
|
173
165
|
# <%= c.body do %>
|
@@ -214,19 +206,18 @@ module Bootstrap4Helper
|
|
214
206
|
# <% end %>
|
215
207
|
# <% end %>
|
216
208
|
# <% end %>
|
217
|
-
#
|
209
|
+
# ```
|
218
210
|
#
|
219
|
-
# @param
|
211
|
+
# @param [Hash] opts
|
220
212
|
# @return [String]
|
221
213
|
#
|
222
214
|
def card_group_helper(opts = {}, &block)
|
223
215
|
CardGroup.new(self, opts, &block)
|
224
216
|
end
|
225
217
|
|
226
|
-
#
|
227
|
-
# - Builds a card deck.
|
218
|
+
# Builds a card deck.
|
228
219
|
#
|
229
|
-
#
|
220
|
+
# ```erb
|
230
221
|
# <%= card_deck_helper do |deck| %>
|
231
222
|
# <%= deck.card do |c| %>
|
232
223
|
# <%= c.body do %>
|
@@ -273,19 +264,18 @@ module Bootstrap4Helper
|
|
273
264
|
# <% end %>
|
274
265
|
# <% end %>
|
275
266
|
# <% end %>
|
276
|
-
#
|
267
|
+
# ```
|
277
268
|
#
|
278
|
-
# @param
|
269
|
+
# @param [Hash] opts
|
279
270
|
# @return [String]
|
280
271
|
#
|
281
272
|
def card_deck_helper(opts = {}, &block)
|
282
273
|
CardDeck.new(self, opts, &block)
|
283
274
|
end
|
284
275
|
|
285
|
-
#
|
286
|
-
# - Builds a card column.
|
276
|
+
# Builds a card column.
|
287
277
|
#
|
288
|
-
#
|
278
|
+
# ```erb
|
289
279
|
# <%= card_column_helper do |column| %>
|
290
280
|
# <%= column.card do |c| %>
|
291
281
|
# <%= c.body do %>
|
@@ -332,20 +322,19 @@ module Bootstrap4Helper
|
|
332
322
|
# <% end %>
|
333
323
|
# <% end %>
|
334
324
|
# <% end %>
|
335
|
-
#
|
325
|
+
# ```
|
336
326
|
#
|
337
|
-
# @param
|
327
|
+
# @param [Hash] opts
|
338
328
|
# @return [String]
|
339
329
|
#
|
340
330
|
def card_column_helper(opts = {}, &block)
|
341
331
|
CardColumn.new(self, opts, &block)
|
342
332
|
end
|
343
333
|
|
344
|
-
#
|
345
|
-
# - Generates a Dropdown component. Default type `:dropdown`. For inline buttons, use
|
334
|
+
# Generates a Dropdown component. Default type `:dropdown`. For inline buttons, use
|
346
335
|
# `:group`.
|
347
336
|
#
|
348
|
-
#
|
337
|
+
# ```erb
|
349
338
|
# <%= dropdown_helper do |dropdown| %>
|
350
339
|
# <%= dropdown.button(:primary) { "Action" } %>
|
351
340
|
# <%= dropdown.menu do |menu| %>
|
@@ -395,19 +384,18 @@ module Bootstrap4Helper
|
|
395
384
|
# <%= menu.link "Forgot password", "#" %>
|
396
385
|
# <% end %>
|
397
386
|
# <% end %>
|
398
|
-
#
|
387
|
+
# ```
|
399
388
|
#
|
400
|
-
# @param
|
389
|
+
# @param [Mixed] args
|
401
390
|
# @return [String]
|
402
391
|
#
|
403
392
|
def dropdown_helper(*args, &block)
|
404
393
|
Dropdown.new(self, *args, &block)
|
405
394
|
end
|
406
395
|
|
407
|
-
#
|
408
|
-
# - Generates Modal windows.
|
396
|
+
# Generates Modal windows.
|
409
397
|
#
|
410
|
-
#
|
398
|
+
# ```erb
|
411
399
|
# <%= modal_helper id: 'exampleModal' do |m| %>
|
412
400
|
# <%= m.header do %>
|
413
401
|
# <%= m.title { 'Example Modal' } %>
|
@@ -425,19 +413,18 @@ module Bootstrap4Helper
|
|
425
413
|
# <% end %>
|
426
414
|
# <% end %>
|
427
415
|
# <% end %>
|
428
|
-
#
|
416
|
+
# ```
|
429
417
|
#
|
430
|
-
# @param
|
418
|
+
# @param [Hash] opts
|
431
419
|
# @return [String]
|
432
420
|
#
|
433
421
|
def modal_helper(opts = {}, &block)
|
434
422
|
Modal.new(self, opts, &block)
|
435
423
|
end
|
436
424
|
|
437
|
-
#
|
438
|
-
# - Generates Nav components.
|
425
|
+
# Generates Nav components.
|
439
426
|
#
|
440
|
-
#
|
427
|
+
# ```erb
|
441
428
|
# <%= nav_helper do |nav| %>
|
442
429
|
# <%= nav.link "Item 1", "https://www.google.com" %>
|
443
430
|
# <%= nav.link "Item 2", "#" %>
|
@@ -452,19 +439,27 @@ module Bootstrap4Helper
|
|
452
439
|
# <%= menu.link 'Records', '#' %>
|
453
440
|
# <% end %>
|
454
441
|
# <% end %>
|
455
|
-
#
|
442
|
+
# ```
|
456
443
|
#
|
457
|
-
# @param
|
444
|
+
# @param [Hash] opts
|
458
445
|
# @return [String]
|
459
446
|
#
|
460
447
|
def nav_helper(opts = {}, &block)
|
461
448
|
Nav.new(self, opts, &block)
|
462
449
|
end
|
463
450
|
|
464
|
-
#
|
465
|
-
#
|
451
|
+
# Generates a page header, similiar to bootstrap 3
|
452
|
+
#
|
453
|
+
# @param [Hash] opts
|
454
|
+
# @return [String]
|
455
|
+
#
|
456
|
+
def page_header_helper(opts = {}, &block)
|
457
|
+
PageHeader.new(self, opts, &block)
|
458
|
+
end
|
459
|
+
|
460
|
+
# Generates a Tab component.
|
466
461
|
#
|
467
|
-
#
|
462
|
+
# ```erb
|
468
463
|
# <%= tab_helper do |tab| %>
|
469
464
|
# <%= tab.nav do |nav| %>
|
470
465
|
# <%= nav.item :item1 do %>
|
@@ -505,19 +500,22 @@ module Bootstrap4Helper
|
|
505
500
|
# <% end %>
|
506
501
|
# <% end %>
|
507
502
|
# <% end %>
|
508
|
-
#
|
503
|
+
# ```
|
504
|
+
# @param [Mixed] args
|
505
|
+
# @return [String]
|
509
506
|
#
|
510
507
|
def tab_helper(*args, &block)
|
511
508
|
Tab.new(self, *args, &block)
|
512
509
|
end
|
513
510
|
|
514
|
-
#
|
515
|
-
# - Generates spinner annimations.
|
511
|
+
# Generates spinner annimations.
|
516
512
|
#
|
517
|
-
#
|
513
|
+
# ```erb
|
518
514
|
# <%= spinner_helper class: 'text-warning' %>
|
519
515
|
# <%= spinner_helper type: :grow, class: 'text-danger', id: 'loadingRecords' %>
|
520
|
-
#
|
516
|
+
# ```
|
517
|
+
# @param [Mixed] args
|
518
|
+
# @return [String]
|
521
519
|
#
|
522
520
|
def spinner_helper(*args, &block)
|
523
521
|
Spinner.new(self, *args, &block)
|
@@ -1,9 +1,6 @@
|
|
1
|
-
# @root
|
2
|
-
#
|
3
|
-
#
|
4
1
|
module Bootstrap4Helper
|
5
|
-
#
|
6
|
-
#
|
2
|
+
# Builds a Accordion out of the collapse component of Bootstrap 4.
|
3
|
+
#
|
7
4
|
#
|
8
5
|
class Accordion < Component
|
9
6
|
CARD_METHODS = %i[
|
@@ -12,11 +9,16 @@ module Bootstrap4Helper
|
|
12
9
|
image_overlay
|
13
10
|
].freeze
|
14
11
|
|
15
|
-
#
|
12
|
+
# Class constructor
|
16
13
|
# -
|
17
14
|
#
|
18
15
|
# @param [ActionView] template
|
19
16
|
# @param [Hash] opts
|
17
|
+
# @option opts [String] :id
|
18
|
+
# @option opts [String] :class
|
19
|
+
# @option opts [Hash] :data
|
20
|
+
# @option opts [String] :parent
|
21
|
+
# @option opts [String] :target
|
20
22
|
#
|
21
23
|
def initialize(template, opts = {}, &block)
|
22
24
|
super(template)
|
@@ -30,11 +32,10 @@ module Bootstrap4Helper
|
|
30
32
|
@card = Card.new(@template)
|
31
33
|
end
|
32
34
|
|
33
|
-
#
|
34
|
-
# - Builds a header component for the accordion, which is actually the header
|
35
|
+
# Builds a header component for the accordion, which is actually the header
|
35
36
|
# of a Card.
|
36
37
|
#
|
37
|
-
# @param
|
38
|
+
# @param [Hash] opts
|
38
39
|
# @return [String]
|
39
40
|
#
|
40
41
|
def header(opts = {}, &block)
|
@@ -49,15 +50,13 @@ module Bootstrap4Helper
|
|
49
50
|
end
|
50
51
|
end
|
51
52
|
|
52
|
-
#
|
53
|
-
# - Builds the body component for the accordion, which is actually the body
|
53
|
+
# Builds the body component for the accordion, which is actually the body
|
54
54
|
# of a Card.
|
55
55
|
#
|
56
|
-
# @note
|
57
|
-
#
|
58
|
-
# gets used primarily in the `AccordionGroup`.
|
56
|
+
# @note The `@parent` gets used to set the parent element for the accordion. This
|
57
|
+
# gets used primarily in the `AccordionGroup`.
|
59
58
|
#
|
60
|
-
# @param
|
59
|
+
# @param [Hash] opts
|
61
60
|
# @return [String]
|
62
61
|
#
|
63
62
|
def body(opts = {}, &block)
|
@@ -68,8 +67,7 @@ module Bootstrap4Helper
|
|
68
67
|
end
|
69
68
|
end
|
70
69
|
|
71
|
-
#
|
72
|
-
# - Because Accordions are basically `Cards` with a wrapper, we might as
|
70
|
+
# Because Accordions are basically `Cards` with a wrapper, we might as
|
73
71
|
# well catch common `Card` methods and send them to the card object. No
|
74
72
|
# point in creating similar methods for `Accordions`.
|
75
73
|
#
|
@@ -84,15 +82,14 @@ module Bootstrap4Helper
|
|
84
82
|
end
|
85
83
|
end
|
86
84
|
|
87
|
-
#
|
88
|
-
#
|
85
|
+
# Checks if the Object reponds to missing.
|
86
|
+
#
|
89
87
|
#
|
90
88
|
def respond_to_missing?(method, include_private = false)
|
91
89
|
CARD_METHODS.include?(method) || super
|
92
90
|
end
|
93
91
|
|
94
|
-
#
|
95
|
-
# - Leaving off the the default `accordion` class because with only 1 accordion,
|
92
|
+
# Leaving off the default `accordion` class because with only 1 accordion,
|
96
93
|
# there is no bottom.
|
97
94
|
#
|
98
95
|
# @return [String]
|
@@ -1,17 +1,15 @@
|
|
1
|
-
# @root
|
2
|
-
#
|
3
|
-
#
|
4
1
|
module Bootstrap4Helper
|
5
|
-
#
|
6
|
-
#
|
2
|
+
# Used to build groups of Accordions, that are all synced with each other.
|
3
|
+
#
|
7
4
|
#
|
8
5
|
class AccordionGroup < Component
|
9
|
-
#
|
10
|
-
# -
|
6
|
+
# Class constructor
|
11
7
|
#
|
12
8
|
# @param [ActionView] template
|
13
|
-
# @param [
|
14
|
-
# @
|
9
|
+
# @param [Hash] opts
|
10
|
+
# @option opts [String] :id
|
11
|
+
# @option opts [String] :class
|
12
|
+
# @option opts [Hash] :data
|
15
13
|
#
|
16
14
|
def initialize(template, opts = {}, &block)
|
17
15
|
super(template)
|
@@ -22,8 +20,7 @@ module Bootstrap4Helper
|
|
22
20
|
@content = block || proc { '' }
|
23
21
|
end
|
24
22
|
|
25
|
-
#
|
26
|
-
# - Used to build a `Accordion` for the `AccordionGroup`.
|
23
|
+
# Used to build a `Accordion` for the `AccordionGroup`.
|
27
24
|
#
|
28
25
|
# @param [Mixed] args
|
29
26
|
# @return [Accordion]
|
@@ -40,8 +37,7 @@ module Bootstrap4Helper
|
|
40
37
|
Accordion.new(self, *opts, &block)
|
41
38
|
end
|
42
39
|
|
43
|
-
#
|
44
|
-
# - Used to get the HTML markup of the `AccordionGroup`
|
40
|
+
# Used to get the HTML markup of the `AccordionGroup`
|
45
41
|
#
|
46
42
|
# @return [String]
|
47
43
|
#
|