bootstrap4_helper 1.0.0 → 1.0.1
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 +4 -4
- data/README.md +7 -0
- data/lib/bootstrap4_helper.rb +58 -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 +7 -9
- data/lib/bootstrap4_helper/constants.rb +2 -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/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 +24 -17
- data/lib/bootstrap4_helper/version.rb +1 -1
- metadata +50 -7
@@ -1,9 +1,7 @@
|
|
1
|
-
# @root
|
2
|
-
#
|
3
|
-
#
|
4
1
|
module Bootstrap4Helper
|
5
|
-
#
|
2
|
+
# Simple configuration object for setting options for the gem.
|
6
3
|
#
|
4
|
+
# @todo Build a better, more comprehensive system.
|
7
5
|
#
|
8
6
|
class Configuration
|
9
7
|
DEFAULT_SETTINGS = {
|
@@ -16,18 +14,18 @@ module Bootstrap4Helper
|
|
16
14
|
|
17
15
|
attr_accessor(*DEFAULT_SETTINGS.keys)
|
18
16
|
|
19
|
-
#
|
20
|
-
# -
|
17
|
+
# Class constructor
|
21
18
|
#
|
22
|
-
# @
|
19
|
+
# @param [Hash] _args
|
23
20
|
# @return [ClassName]
|
24
21
|
#
|
25
22
|
def initialize(_args = {})
|
26
23
|
DEFAULT_SETTINGS.each { |key, value| instance_variable_set("@#{key}", value) }
|
27
24
|
end
|
28
25
|
|
29
|
-
#
|
30
|
-
#
|
26
|
+
# Simple predicate method
|
27
|
+
#
|
28
|
+
# @return [Boolean]
|
31
29
|
#
|
32
30
|
def autoload_in_views?
|
33
31
|
@autoload_in_views
|
@@ -1,18 +1,16 @@
|
|
1
|
-
# @root
|
2
|
-
#
|
3
|
-
#
|
4
1
|
module Bootstrap4Helper
|
5
|
-
#
|
2
|
+
# Builds a Dropdown component that can be used in other components.
|
6
3
|
#
|
7
4
|
#
|
8
5
|
class Dropdown < Component
|
9
|
-
#
|
10
|
-
# -
|
6
|
+
# Class constructor
|
11
7
|
#
|
12
|
-
# @param [ActionView]
|
8
|
+
# @param [ActionView] template
|
13
9
|
# @param [Symbol|String] type
|
14
|
-
# @param [Hash]
|
15
|
-
# @
|
10
|
+
# @param [Hash] opts
|
11
|
+
# @option opts [String] :id
|
12
|
+
# @option opts [String] :class
|
13
|
+
# @option opts [Hash] :data
|
16
14
|
#
|
17
15
|
def initialize(template, type = :dropdown, opts = {}, &block)
|
18
16
|
super(template)
|
@@ -24,13 +22,16 @@ module Bootstrap4Helper
|
|
24
22
|
@content = block || proc { '' }
|
25
23
|
end
|
26
24
|
|
27
|
-
#
|
28
|
-
# - Used to generate a button for the dropdown. The buttons default as just
|
25
|
+
# Used to generate a button for the dropdown. The buttons default as just
|
29
26
|
# a button that opens the coresponding dropdown menu. The `split: true` option
|
30
27
|
# make the button just the arrow indicator that open the menu.
|
31
28
|
#
|
32
|
-
# @param
|
33
|
-
# @param
|
29
|
+
# @param [Symbol] context
|
30
|
+
# @param [Hash] opts
|
31
|
+
# @option opts [Boolean] :split
|
32
|
+
# @option opts [String] :id
|
33
|
+
# @option opts [String] :class
|
34
|
+
# @option opts [Hash] :data
|
34
35
|
# @return [String]
|
35
36
|
#
|
36
37
|
def button(context = :primary, opts = {})
|
@@ -52,18 +53,21 @@ module Bootstrap4Helper
|
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
55
|
-
#
|
56
|
-
# - Used to create a new `Dropdown::Menu`
|
56
|
+
# Used to create a new `Dropdown::Menu`
|
57
57
|
#
|
58
|
-
# @param
|
58
|
+
# @param [Hash] opts
|
59
|
+
# @option opts [String] :id
|
60
|
+
# @option opts [String] :class
|
61
|
+
# @option opts [Hash] :data
|
59
62
|
# @return [Dropdown::Menu]
|
60
63
|
#
|
61
64
|
def menu(opts = {}, &block)
|
62
65
|
Menu.new(@template, opts, &block)
|
63
66
|
end
|
64
67
|
|
65
|
-
#
|
66
|
-
#
|
68
|
+
# String reprentation of the object.
|
69
|
+
#
|
70
|
+
# @return [String]
|
67
71
|
#
|
68
72
|
def to_s
|
69
73
|
content_tag :div, id: @id, class: "#{container_class} #{@class}", data: @data do
|
@@ -73,8 +77,7 @@ module Bootstrap4Helper
|
|
73
77
|
|
74
78
|
private
|
75
79
|
|
76
|
-
#
|
77
|
-
# - Returns the container class for the dropdown component.
|
80
|
+
# Returns the container class for the dropdown component.
|
78
81
|
#
|
79
82
|
# @return [String]
|
80
83
|
#
|
@@ -1,18 +1,16 @@
|
|
1
|
-
# @root
|
2
|
-
#
|
3
|
-
#
|
4
1
|
module Bootstrap4Helper
|
5
2
|
class Dropdown
|
6
|
-
#
|
3
|
+
# Builds a menu component for use in dropdowns.
|
7
4
|
#
|
8
5
|
#
|
9
6
|
class Menu < Component
|
10
|
-
#
|
11
|
-
# -
|
7
|
+
# Class constructor
|
12
8
|
#
|
13
9
|
# @param [ActionView] template
|
14
10
|
# @param [Hash] opts
|
15
|
-
# @
|
11
|
+
# @option opts [String] :id
|
12
|
+
# @option opts [String] :class
|
13
|
+
# @option opts [Hash] :data
|
16
14
|
#
|
17
15
|
def initialize(template, opts = {}, &block)
|
18
16
|
super(template)
|
@@ -23,22 +21,30 @@ module Bootstrap4Helper
|
|
23
21
|
@content = block || proc { '' }
|
24
22
|
end
|
25
23
|
|
26
|
-
#
|
27
|
-
# - Use this method when the `item`, `link` in the item in the menu is nothing
|
24
|
+
# Use this method when the `item`, `link` in the item in the menu is nothing
|
28
25
|
# more than a hyperlink.
|
29
26
|
#
|
27
|
+
# @param [String] name
|
28
|
+
# @param [Hash] options
|
29
|
+
# @param [Hash] html_options
|
30
|
+
# @return [String]
|
31
|
+
#
|
30
32
|
def link(name = nil, options = nil, html_options = nil, &block)
|
31
33
|
html_options = (html_options || {}).merge(class: 'dropdown-item')
|
32
34
|
|
33
35
|
@template.link_to(name, options, html_options, &block)
|
34
36
|
end
|
35
37
|
|
36
|
-
#
|
37
|
-
# - Use this method when you are using the item in the menu as trigger for tab
|
38
|
+
# Use this method when you are using the item in the menu as trigger for tab
|
38
39
|
# content.
|
39
40
|
#
|
40
41
|
# @param [Symbol|String] target
|
41
42
|
# @param [Hash] opts
|
43
|
+
# @option opts [String] :id
|
44
|
+
# @option opts [String] :class
|
45
|
+
# @option opts [Hash] :data
|
46
|
+
# @option opts [Hash] :aria
|
47
|
+
# @return [String]
|
42
48
|
#
|
43
49
|
def item(target, opts = {})
|
44
50
|
id = opts.fetch(:id, nil)
|
@@ -58,35 +64,43 @@ module Bootstrap4Helper
|
|
58
64
|
end
|
59
65
|
end
|
60
66
|
|
61
|
-
#
|
62
|
-
# - Builds a Text component
|
67
|
+
# Builds a Text component
|
63
68
|
#
|
64
|
-
# @param
|
65
|
-
# @param
|
69
|
+
# @param [Symbol|String] text
|
70
|
+
# @param [Hash] opts
|
71
|
+
# @option opts [String] :id
|
72
|
+
# @option opts [String] :class
|
73
|
+
# @option opts [Hash] :data
|
74
|
+
# @return [String]
|
66
75
|
#
|
67
76
|
def text(text, opts = {}, &block)
|
68
77
|
build_sub_component :span, text, 'item-text', opts, &block
|
69
78
|
end
|
70
79
|
|
71
|
-
#
|
72
|
-
# - Builds a Header component
|
80
|
+
# Builds a Header component
|
73
81
|
#
|
74
|
-
# @param
|
75
|
-
# @param
|
82
|
+
# @param [Symbol|String] text
|
83
|
+
# @param [Hash] opts
|
84
|
+
# @option opts [String] :id
|
85
|
+
# @option opts [String] :class
|
86
|
+
# @option opts [Hash] :data
|
87
|
+
# @return [String]
|
76
88
|
#
|
77
89
|
def header(text, opts = {}, &block)
|
78
90
|
build_sub_component :h6, text, 'header', opts, &block
|
79
91
|
end
|
80
92
|
|
81
|
-
#
|
82
|
-
#
|
93
|
+
# Builds a divider element
|
94
|
+
#
|
95
|
+
# @return [String]
|
83
96
|
#
|
84
97
|
def divider
|
85
98
|
content_tag :div, '', class: 'dropdown-divider'
|
86
99
|
end
|
87
100
|
|
88
|
-
#
|
89
|
-
#
|
101
|
+
# String representation of the object.
|
102
|
+
#
|
103
|
+
# @return [String]
|
90
104
|
#
|
91
105
|
def to_s
|
92
106
|
content_tag :div, id: @id, class: "dropdown-menu #{@class}", data: @data do
|
@@ -96,13 +110,16 @@ module Bootstrap4Helper
|
|
96
110
|
|
97
111
|
private
|
98
112
|
|
99
|
-
#
|
100
|
-
# - Used to build specific components.
|
113
|
+
# Used to build specific components.
|
101
114
|
#
|
102
115
|
# @param [Symbol] tag
|
103
116
|
# @param [Symbol|String] text
|
104
117
|
# @param [Symbol|String] type
|
105
118
|
# @param [Hash] opts
|
119
|
+
# @option opts [String] :id
|
120
|
+
# @option opts [String] :class
|
121
|
+
# @option opts [Hash] :data
|
122
|
+
# @return [String]
|
106
123
|
#
|
107
124
|
def build_sub_component(tag, text, type, opts)
|
108
125
|
id = opts.fetch(:id, nil)
|
@@ -1,17 +1,12 @@
|
|
1
|
-
# @root
|
2
|
-
#
|
3
|
-
#
|
4
1
|
module Bootstrap4Helper
|
5
|
-
#
|
6
|
-
# - Naming convention used as to not pollute views where the module is
|
2
|
+
# Naming convention used as to not pollute views where the module is
|
7
3
|
# included. @config is a common instance variable name. We don't want
|
8
4
|
# to risk overriding another developers variable.
|
9
5
|
#
|
10
6
|
@_bs4h_config = Configuration.new
|
11
7
|
|
12
8
|
class << self
|
13
|
-
#
|
14
|
-
# - Simple interface for exposing the configuration object.
|
9
|
+
# Simple interface for exposing the configuration object.
|
15
10
|
#
|
16
11
|
# @return [Bootstrap4Helper::Configuration]
|
17
12
|
#
|
@@ -1,16 +1,17 @@
|
|
1
|
-
# @root
|
2
|
-
#
|
3
|
-
#
|
4
1
|
module Bootstrap4Helper
|
5
|
-
#
|
2
|
+
# Builds a Modal window component.
|
6
3
|
#
|
7
4
|
#
|
8
5
|
class Modal < Component
|
9
|
-
#
|
10
|
-
# -
|
6
|
+
# Class constructor
|
11
7
|
#
|
12
|
-
# @param
|
13
|
-
# @param
|
8
|
+
# @param [ActionView] template
|
9
|
+
# @param [Hash] opts
|
10
|
+
# @option opts [String] :id
|
11
|
+
# @option opts [String] :class
|
12
|
+
# @option opts [Hash] :data
|
13
|
+
# @option opts [Boolean] :scrollable
|
14
|
+
# @option opts [Boolean] :vcentered
|
14
15
|
#
|
15
16
|
def initialize(template, opts = {}, &block)
|
16
17
|
super(template)
|
@@ -23,46 +24,59 @@ module Bootstrap4Helper
|
|
23
24
|
@content = block || proc { '' }
|
24
25
|
end
|
25
26
|
|
26
|
-
#
|
27
|
-
# - Build the header component for the modal.
|
27
|
+
# Build the header component for the modal.
|
28
28
|
#
|
29
|
-
# @param
|
29
|
+
# @param [Hash] opts
|
30
|
+
# @option opts [String] :id
|
31
|
+
# @option opts [String] :class
|
32
|
+
# @option opts [Hash] :data
|
33
|
+
# @return [String]
|
30
34
|
#
|
31
35
|
def header(opts = {}, &block)
|
32
36
|
build_main_component :header, opts, &block
|
33
37
|
end
|
34
38
|
|
35
|
-
#
|
36
|
-
# - Builds the body component.
|
39
|
+
# Builds the body component.
|
37
40
|
#
|
38
|
-
# @param
|
41
|
+
# @param [Hash] opts
|
42
|
+
# @option opts [String] :id
|
43
|
+
# @option opts [String] :class
|
44
|
+
# @option opts [Hash] :data
|
45
|
+
# @return [String]
|
39
46
|
#
|
40
47
|
def body(opts = {}, &block)
|
41
48
|
build_main_component :body, opts, &block
|
42
49
|
end
|
43
50
|
|
44
|
-
#
|
45
|
-
# - Builds the footer component.
|
51
|
+
# Builds the footer component.
|
46
52
|
#
|
47
|
-
# @param
|
53
|
+
# @param [Hash] opts
|
54
|
+
# @option opts [String] :id
|
55
|
+
# @option opts [String] :class
|
56
|
+
# @option opts [Hash] :data
|
57
|
+
# @return [String]
|
48
58
|
#
|
49
59
|
def footer(opts = {}, &block)
|
50
60
|
build_main_component :footer, opts, &block
|
51
61
|
end
|
52
62
|
|
53
|
-
#
|
54
|
-
# - Builds a title component.
|
63
|
+
# Builds a title component.
|
55
64
|
#
|
56
|
-
# @param
|
65
|
+
# @param [Hash] opts
|
66
|
+
# @option opts [String] :id
|
67
|
+
# @option opts [String] :class
|
68
|
+
# @option opts [Hash] :data
|
69
|
+
# @return [String]
|
57
70
|
#
|
58
71
|
def title(opts = {}, &block)
|
59
72
|
build_sub_component :h5, :title, opts, &block
|
60
73
|
end
|
61
74
|
|
62
|
-
#
|
63
|
-
# - Builds a close button component.
|
75
|
+
# Builds a close button component.
|
64
76
|
#
|
65
|
-
# @param
|
77
|
+
# @param [Hash] opts
|
78
|
+
# @option opts [String] :class
|
79
|
+
# @return [String]
|
66
80
|
#
|
67
81
|
def close_button(opts = {})
|
68
82
|
klass = opts.fetch(:class, '')
|
@@ -78,8 +92,9 @@ module Bootstrap4Helper
|
|
78
92
|
end
|
79
93
|
end
|
80
94
|
|
81
|
-
#
|
82
|
-
#
|
95
|
+
# String representation of the object.
|
96
|
+
#
|
97
|
+
# @return [String]
|
83
98
|
#
|
84
99
|
def to_s
|
85
100
|
content_tag :div, id: @id, class: "modal #{@class}", tabindex: -1, role: 'dialog', data: @data do
|
@@ -91,22 +106,25 @@ module Bootstrap4Helper
|
|
91
106
|
|
92
107
|
private
|
93
108
|
|
94
|
-
#
|
95
|
-
# - Used to build main components, usually divs.
|
109
|
+
# Used to build main components, usually divs.
|
96
110
|
#
|
97
|
-
# @param
|
98
|
-
# @param
|
111
|
+
# @param [Symbol|String] type
|
112
|
+
# @param [Hash] opts
|
113
|
+
# @return [String]
|
99
114
|
#
|
100
115
|
def build_main_component(type, opts = {}, &block)
|
101
116
|
build_sub_component :div, type, opts, &block
|
102
117
|
end
|
103
118
|
|
104
|
-
#
|
105
|
-
# - Used to build more specific components.
|
119
|
+
# Used to build more specific components.
|
106
120
|
#
|
107
121
|
# @param [Symbol] tag
|
108
122
|
# @param [Symbol|String] type
|
109
123
|
# @param [Hash] opts
|
124
|
+
# @option opts [String] :id
|
125
|
+
# @option opts [String] :class
|
126
|
+
# @option opts [Hash] :data
|
127
|
+
# @return [String]
|
110
128
|
#
|
111
129
|
def build_sub_component(tag, type, opts = {}, &block)
|
112
130
|
id = opts.fetch(:id, nil)
|
@@ -122,15 +140,15 @@ module Bootstrap4Helper
|
|
122
140
|
)
|
123
141
|
end
|
124
142
|
|
125
|
-
#
|
126
|
-
#
|
143
|
+
# Builds the `x` button normally used in the header.
|
144
|
+
#
|
145
|
+
# @return [String]
|
127
146
|
#
|
128
147
|
def xbutton
|
129
148
|
content_tag :span, '×'.html_safe, aria: { hidden: true }
|
130
149
|
end
|
131
150
|
|
132
|
-
#
|
133
|
-
# - Gets the scrollable CSS class.
|
151
|
+
# Gets the scrollable CSS class.
|
134
152
|
#
|
135
153
|
# @return [String]
|
136
154
|
#
|
@@ -138,8 +156,7 @@ module Bootstrap4Helper
|
|
138
156
|
@scrollable ? 'modal-dialog-scrollable' : ''
|
139
157
|
end
|
140
158
|
|
141
|
-
#
|
142
|
-
# - Gets the vertical-center CSS class.
|
159
|
+
# Gets the vertical-center CSS class.
|
143
160
|
#
|
144
161
|
# @return [String]
|
145
162
|
#
|