bootstrap3_helper 1.0.0 → 3.0.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 +128 -43
- data/lib/bootstrap3_helper/accordion.rb +80 -115
- data/lib/bootstrap3_helper/accordion_group.rb +47 -56
- data/lib/bootstrap3_helper/alert.rb +29 -47
- data/lib/bootstrap3_helper/callout.rb +15 -25
- data/lib/bootstrap3_helper/component.rb +71 -30
- data/lib/bootstrap3_helper/configuration.rb +36 -0
- data/lib/bootstrap3_helper/initialize.rb +19 -0
- data/lib/bootstrap3_helper/panel.rb +117 -64
- data/lib/bootstrap3_helper/tabs/content.rb +33 -39
- data/lib/bootstrap3_helper/tabs/dropdown.rb +53 -45
- data/lib/bootstrap3_helper/tabs/menu.rb +63 -64
- data/lib/bootstrap3_helper/tabs.rb +59 -73
- data/lib/bootstrap3_helper/version.rb +1 -1
- data/lib/bootstrap3_helper.rb +187 -156
- metadata +36 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4052a52cedf01461e605010a66bbf78a2f1741e4046a755495226edeccff6027
|
4
|
+
data.tar.gz: 538817f6096634dcfead3335a03198f34bcecc987d95d22561f79e34553ffa50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc609fbe4d4cb0d76fcd70155ee21b9edb27741cd4b590bacce764408d34ca4fc47232ba4458fb6a657c9c4894a7310675ac6d774ae6ad567a31724b8fd52ebb
|
7
|
+
data.tar.gz: c6e1cdca50954072d204055706352aca4ee29abaa394749d1c623b2ce9eb43d970c3d5da51663cd641ccee0a98382459ebf4ee8f169ef3acc044186940c7b17b
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# Bootstrap 3 Helper
|
2
2
|
|
3
3
|
This gem was designed to help you rapidly build common Bootstrap 3 Components. They where designed to very flexible and reduce a lot of boiler plate HTML.
|
4
4
|
|
@@ -18,14 +18,42 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
$ gem install bootstrap3_helper
|
20
20
|
|
21
|
-
##
|
21
|
+
## Panel Helper
|
22
22
|
|
23
|
-
|
23
|
+
Panels supper the following methods:
|
24
|
+
|
25
|
+
- body
|
26
|
+
- heaader
|
27
|
+
- footer
|
28
|
+
- title
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
# @overload panel_helper(context, opts)
|
32
|
+
# @param [String|Symbol] context - :primary, :danger etc
|
33
|
+
# @param [Hash] opts
|
34
|
+
# @option opts [String] :id
|
35
|
+
# @option opts [String] :class
|
36
|
+
# @option opts [Hash] :data
|
37
|
+
# @option opts [Hash] :aria
|
38
|
+
#
|
39
|
+
# @overload panel_helper(opts)
|
40
|
+
# @param [Hash] opts
|
41
|
+
# @option opts [String] :id
|
42
|
+
# @option opts [String] :class
|
43
|
+
# @option opts [Hash] :data
|
44
|
+
# @option opts [Hash] :aria
|
45
|
+
#
|
46
|
+
# @yieldparam [Panel] panel
|
47
|
+
# @return [String]
|
48
|
+
```
|
49
|
+
|
50
|
+
#### Example
|
24
51
|
|
25
52
|
```erb
|
26
53
|
<%= panel_helper :primary do |p| %>
|
27
54
|
<%= p.header id: 'optional-id', class: 'any-optional-extra-classes' do %>
|
28
|
-
|
55
|
+
<%= p.header { 'Optional header title' } %>
|
56
|
+
<p>Non styled content for header...</p>
|
29
57
|
<% end %>
|
30
58
|
<%= p.body id: 'optional-id', class: 'any-optional-extra-classes' do %>
|
31
59
|
All your custom HTML or Ruby. You can render blocks here, whatever
|
@@ -37,9 +65,25 @@ Or install it yourself as:
|
|
37
65
|
end
|
38
66
|
```
|
39
67
|
|
40
|
-
|
68
|
+
## Alert Helper
|
41
69
|
|
42
|
-
|
70
|
+
```ruby
|
71
|
+
# @overload alert_helper(context, opts)
|
72
|
+
# @param [Symbol|String] context - :primary, :danger etc
|
73
|
+
# @param [Hash] opts
|
74
|
+
# @option opts [String] :id
|
75
|
+
# @option opts [String] :class
|
76
|
+
# @option opts [Boolean] :dismissible
|
77
|
+
#
|
78
|
+
# @overload alert_helper(opts)
|
79
|
+
# @param [Hash] opts
|
80
|
+
# @option opts [String] :id
|
81
|
+
# @option opts [String] :class
|
82
|
+
#
|
83
|
+
# @return [String]
|
84
|
+
```
|
85
|
+
|
86
|
+
### Example
|
43
87
|
|
44
88
|
```erb
|
45
89
|
<%= alert_helper :success { 'Some success message' } %>
|
@@ -51,12 +95,28 @@ end
|
|
51
95
|
<% end %>
|
52
96
|
```
|
53
97
|
|
54
|
-
|
98
|
+
## Acordion Helper
|
55
99
|
|
56
|
-
|
100
|
+
```ruby
|
101
|
+
# @overload accordion_helper(context, opts)
|
102
|
+
# @param [Symbol|String] context - :primary, :danger etc
|
103
|
+
# @param [Hash] opts
|
104
|
+
# @option opts [String] :id
|
105
|
+
# @option opts [String] :class
|
106
|
+
#
|
107
|
+
# @overload accordion_helper(opts)
|
108
|
+
# @param [Hash] opts
|
109
|
+
# @option opts [String] :id
|
110
|
+
# @option opts [String] :class
|
111
|
+
#
|
112
|
+
# @yieldparam [Accordion] accordion
|
113
|
+
# @return [String]
|
114
|
+
```
|
115
|
+
|
116
|
+
### Example
|
57
117
|
|
58
118
|
```erb
|
59
|
-
<%= accordion_helper :primary,
|
119
|
+
<%= accordion_helper :primary, id: 'optional_id', expanded: true do |accordion| %>
|
60
120
|
<%= accordion.header do %>
|
61
121
|
<span class="something">This is the heading....</span>
|
62
122
|
<% end %>
|
@@ -66,11 +126,19 @@ end
|
|
66
126
|
<% end %>
|
67
127
|
```
|
68
128
|
|
69
|
-
**Note:** the accordion helper handles all the attributes and data attributes needed to sync up the javascript in order to give the component its functionality. You just worry about about the class or state of the component. The helper does the rest. But if you do want to control the collapse ID and syncing, `collapse_id` is the
|
129
|
+
**Note:** the accordion helper handles all the attributes and data attributes needed to sync up the javascript in order to give the component its functionality. You just worry about about the class or state of the component. The helper does the rest. But if you do want to control the collapse ID and syncing, `collapse_id` is the parameter you are looking for.
|
70
130
|
|
71
|
-
|
131
|
+
## Accordion Group
|
72
132
|
|
73
|
-
|
133
|
+
```ruby
|
134
|
+
# @param [Hash] opts
|
135
|
+
# @option opts [String] :id
|
136
|
+
# @option opts [String] :class
|
137
|
+
# @yieldparam [AccordionGroup] group
|
138
|
+
# @return [String]
|
139
|
+
```
|
140
|
+
|
141
|
+
### Example
|
74
142
|
|
75
143
|
```erb
|
76
144
|
<%= accordion_group_helper do |g| %>
|
@@ -79,7 +147,7 @@ end
|
|
79
147
|
<%= accordion.body do %>
|
80
148
|
<p>This is accordion 1</p>
|
81
149
|
<% end %>
|
82
|
-
<%end %>
|
150
|
+
<% end %>
|
83
151
|
<% g.accordion :info do |accordion| %>
|
84
152
|
<%= accordion.header { "Accordion 2" } %>
|
85
153
|
<%= accordion.body do %>
|
@@ -91,45 +159,62 @@ end
|
|
91
159
|
<%= accordion.body do %>
|
92
160
|
<p>This is accordion 3</p>
|
93
161
|
<% end %>
|
94
|
-
<%end %>
|
162
|
+
<% end %>
|
95
163
|
<% end %>
|
96
164
|
```
|
97
165
|
|
98
|
-
|
166
|
+
## Tab Helper
|
99
167
|
|
100
|
-
|
168
|
+
Tabs respond to the following methods:
|
101
169
|
|
102
|
-
|
170
|
+
- menu
|
171
|
+
- item (Used for linking to tab content)
|
172
|
+
- dropdown (Used for making dropdown menus)
|
173
|
+
- content
|
103
174
|
|
104
|
-
```
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
<%= dropdown.item(:testing7 ) { 'Testing 7' } %>
|
113
|
-
<% end %>
|
175
|
+
```ruby
|
176
|
+
# @param [Hash] opts
|
177
|
+
# @option args [String|Symbol] :type - :tabs, :pills
|
178
|
+
# @option args [String] :id
|
179
|
+
# @option args [String] :class
|
180
|
+
# @yieldparam [Tabs] tabs
|
181
|
+
# @return [String]
|
182
|
+
```
|
114
183
|
|
184
|
+
### Example
|
115
185
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
<% end %>
|
128
|
-
<% content.item :testing6 do %>
|
129
|
-
Testing 6 content
|
186
|
+
```erb
|
187
|
+
<%= tabs_helper type: :pills do |tabs| %>
|
188
|
+
<%= tabs.menu do |menu| %>
|
189
|
+
<%= menu.item(:testing1, class: 'active') { ' Testing 1' } %>
|
190
|
+
<%= menu.item :testing2 %>
|
191
|
+
<%= menu.item(:testing3) { ' Testing 3' } %>
|
192
|
+
<%= menu.dropdown 'Testing Dropdown' do |dropdown| %>
|
193
|
+
<%= dropdown.item(:testing5 ) { 'Testing 5' } %>
|
194
|
+
<%= dropdown.item(:testing6 ) { 'Testing 6' } %>
|
195
|
+
<%= dropdown.item(:testing7 ) { 'Testing 7' } %>
|
196
|
+
<% end %>
|
130
197
|
<% end %>
|
131
|
-
|
132
|
-
|
198
|
+
|
199
|
+
<%= tabs.content do |content| %>
|
200
|
+
<% content.pane :testing1, class: 'active' do %>
|
201
|
+
Testing 1 content
|
202
|
+
<% end %>
|
203
|
+
<% content.pane :testing2 do %>
|
204
|
+
Testing 2 content
|
205
|
+
<% end %>
|
206
|
+
<% content.pane :testing3 do %>
|
207
|
+
Testing 3 content
|
208
|
+
<% end %>
|
209
|
+
<% content.pane :testing5 do %>
|
210
|
+
Testing 5 content
|
211
|
+
<% end %>
|
212
|
+
<% content.pane :testing6 do %>
|
213
|
+
Testing 6 content
|
214
|
+
<% end %>
|
215
|
+
<% content.pane :testing7 do %>
|
216
|
+
Testing 7 content
|
217
|
+
<% end %>
|
133
218
|
<% end %>
|
134
219
|
<% end %>
|
135
220
|
```
|
@@ -1,169 +1,134 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
module Bootstrap3Helper
|
5
|
-
# @description
|
6
|
-
# - Used to generate Bootstrap Accordion objects.
|
1
|
+
module Bootstrap3Helper # :nodoc:
|
2
|
+
# Used to generate Bootstrap Accordion objects.
|
7
3
|
#
|
8
|
-
# <code>
|
9
|
-
# <%= accordion_helper :primary do |accordion| %>
|
10
|
-
# <%= accordion.header do %>
|
11
|
-
# <span class="something">This is the heading....</span>
|
12
|
-
# <% end %>
|
13
|
-
# <%= accordion.body do %>
|
14
|
-
# <p>This is the body of the accordion....</p>
|
15
|
-
# <% end %>
|
16
|
-
# <% end %>
|
17
|
-
# </code>
|
18
4
|
#
|
19
5
|
class Accordion < Component
|
20
|
-
#
|
21
|
-
# - Initlize a new accordion object. If this part of a parent element, i.e
|
6
|
+
# Initlize a new accordion object. If this part of a parent element, i.e
|
22
7
|
# AccordionGroup, we need to keep track of the parent element id, so we can
|
23
8
|
# pass it down to the other components.
|
24
9
|
#
|
25
10
|
# @param [Class] template - Template in which your are binding too.
|
26
|
-
# @param [NilClass|String|Symbol|Hash]
|
11
|
+
# @param [NilClass|String|Symbol|Hash] context_or_options Bootstrap class context, or options hash.
|
27
12
|
# @param [Hash] opts
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
# collapse_id: [String]
|
34
|
-
# expanded: Boolean
|
35
|
-
# }
|
36
|
-
# </code>
|
13
|
+
# @option opts [String] :parent_id The parent element ID if this accordion is part of a group.
|
14
|
+
# @option opts [String] :id The ID of the element
|
15
|
+
# @option opts [String] :class Custom class for the component.
|
16
|
+
# @option opts [String] :collapse_id The ID of the element to collapse when clicked.
|
17
|
+
# @option opts [Boolean] :expanded Initial state of the accordion.
|
37
18
|
# @return [Accordion]
|
38
19
|
#
|
39
|
-
def initialize(template, context_or_options = nil, opts = {})
|
20
|
+
def initialize(template, context_or_options = nil, opts = {}, &block)
|
40
21
|
super(template)
|
41
|
-
@context, args =
|
22
|
+
@context, args = parse_context_or_options(context_or_options, opts)
|
42
23
|
|
43
24
|
@parent_id = args.fetch(:parent_id, nil)
|
44
25
|
@id = args.fetch(:id, nil)
|
45
26
|
@class = args.fetch(:class, '')
|
46
27
|
@collapse_id = args.fetch(:collapse_id, uuid)
|
47
28
|
@expanded = args.fetch(:expanded, false)
|
29
|
+
@content = block || proc { '' }
|
30
|
+
@panel = Panel.new(@template, context_or_options, opts)
|
48
31
|
end
|
49
32
|
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
# @
|
54
|
-
#
|
55
|
-
#
|
56
|
-
# @
|
57
|
-
#
|
58
|
-
#
|
59
|
-
# id: [String]
|
60
|
-
# class: [String]
|
61
|
-
# data: [Hash]
|
62
|
-
# }
|
63
|
-
# </code>
|
64
|
-
#
|
65
|
-
# @yields [Accordion] self
|
66
|
-
# @return [NilClass]
|
33
|
+
# Creates the header element for the accordion
|
34
|
+
#
|
35
|
+
# @param [Symbol|String|Hash|NilClass] tag_or_options
|
36
|
+
# @param [Hash] opts
|
37
|
+
# @option opts [String] :id
|
38
|
+
# @option opts [String] :class
|
39
|
+
# @option opts [Hash] :data
|
40
|
+
# @option opts [Hash] :aria
|
41
|
+
# @return [String]
|
67
42
|
#
|
68
|
-
|
69
|
-
|
70
|
-
id = args.fetch(:id, nil)
|
71
|
-
klass = args.fetch(:class, '')
|
72
|
-
data = args.fetch(:data, {})
|
43
|
+
def header(tag_or_options = nil, opts = {}, &block)
|
44
|
+
tag, args = parse_tag_or_options(tag_or_options, opts)
|
73
45
|
|
46
|
+
data = {}
|
74
47
|
data[:toggle] = 'collapse'
|
75
|
-
data[:parent] = "##{@parent_id}"
|
48
|
+
data[:parent] = "##{@parent_id}" if @parent_id.present?
|
49
|
+
data[:target] = "##{@collapse_id}"
|
76
50
|
|
77
|
-
@header
|
78
|
-
content_tag
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
51
|
+
@panel.header(tag, args.merge!(config_for: :accordions)) do
|
52
|
+
content_tag(
|
53
|
+
:span,
|
54
|
+
role: 'button',
|
55
|
+
data: data,
|
56
|
+
aria: { expanded: @expanded, controls: "##{@collapse_id}" },
|
57
|
+
&block
|
58
|
+
)
|
84
59
|
end
|
85
60
|
end
|
86
|
-
# rubocop:enable Metrics/MethodLength
|
87
61
|
|
88
|
-
#
|
89
|
-
#
|
90
|
-
#
|
91
|
-
# @
|
92
|
-
#
|
62
|
+
# Builds a title component for the accordion header.
|
63
|
+
#
|
64
|
+
# @param [Symbol|String|Hash|NilClass] tag_or_options
|
65
|
+
# @param [Hash] opts
|
66
|
+
# @option opts [String] :id
|
67
|
+
# @option opts [String] :class
|
68
|
+
# @option opts [Hash] :data
|
69
|
+
# @option opts [Hash] :aria
|
70
|
+
# @return [String]
|
93
71
|
#
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
#
|
100
|
-
# }
|
101
|
-
# </code>
|
72
|
+
def title(tag_or_options = nil, opts = {}, &block)
|
73
|
+
tag, args = parse_tag_or_options(tag_or_options, opts)
|
74
|
+
@panel.title(tag, args.merge!(config_for: :accordions), &block)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Creates the body element for the accordion.
|
102
78
|
#
|
103
|
-
# @
|
104
|
-
# @return [nilClass]
|
79
|
+
# @note NilClass :to_s returns an empty String
|
105
80
|
#
|
81
|
+
# @param [Hash] args
|
82
|
+
# @option args [String] :id
|
83
|
+
# @option args [String] :class
|
84
|
+
# @option args [Hash] :data
|
85
|
+
# @yieldreturn [String]
|
106
86
|
#
|
107
|
-
def body(
|
87
|
+
def body(tag_or_options = nil, opts = {}, &block)
|
88
|
+
tag, args = parse_tag_or_options(tag_or_options, opts)
|
89
|
+
|
108
90
|
klass = 'panel-collapse collapse '
|
109
|
-
data = args.fetch(:data, {})
|
110
|
-
klass += args.fetch(:class, '')
|
111
91
|
klass += ' in' if @expanded
|
112
92
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
93
|
+
content_tag(
|
94
|
+
:div,
|
95
|
+
id: @collapse_id,
|
96
|
+
role: 'tabpanel',
|
97
|
+
class: klass,
|
98
|
+
aria: { labelledby: "##{@collapse_id}" }
|
99
|
+
) do
|
100
|
+
@panel.body(tag, args.merge!(config_for: :accordions), &block)
|
118
101
|
end
|
119
102
|
end
|
120
103
|
|
121
|
-
#
|
122
|
-
# - Creates the footer element for the accordion
|
123
|
-
#
|
124
|
-
# @params [Hash] args
|
125
|
-
# <code>
|
126
|
-
# args = {
|
127
|
-
# id: [String]
|
128
|
-
# class: [String]
|
129
|
-
# data: [Hash]
|
130
|
-
# }
|
131
|
-
# </code>
|
132
|
-
#
|
133
|
-
# @yields [Accordion] self
|
134
|
-
# @return [nilClass]
|
104
|
+
# Creates the footer element for the accordion
|
135
105
|
#
|
106
|
+
# @param [Hash] args
|
107
|
+
# @option args [String] :id
|
108
|
+
# @option args [String] :class
|
109
|
+
# @option args [Hash] :data
|
110
|
+
# @return [String]
|
136
111
|
#
|
137
|
-
def footer(
|
138
|
-
|
139
|
-
|
140
|
-
data = args.fetch(:data, {})
|
141
|
-
|
142
|
-
@footer = content_tag :div, id: id, class: 'panel-footer ' + klass, data: data do
|
143
|
-
content = yield if block_given?
|
144
|
-
content.to_s.html_safe
|
145
|
-
end
|
112
|
+
def footer(tag_or_options = nil, opts = {}, &block)
|
113
|
+
tag, args = parse_tag_or_options(tag_or_options, opts)
|
114
|
+
@panel.footer(tag, args.merge!(config_for: :accordions), &block)
|
146
115
|
end
|
147
116
|
|
148
|
-
#
|
149
|
-
# - The to string method here is what is responsible for rendering out the
|
117
|
+
# The to string method here is what is responsible for rendering out the
|
150
118
|
# accordion element. As long as the main method is rendered out in the
|
151
119
|
# helper, you will get the entire accordion.
|
152
120
|
#
|
153
121
|
# @return [String]
|
154
122
|
#
|
155
123
|
def to_s
|
156
|
-
|
157
|
-
@
|
124
|
+
content_tag :div, id: @id, class: container_classes do
|
125
|
+
@content.call(self)
|
158
126
|
end
|
159
|
-
|
160
|
-
content
|
161
127
|
end
|
162
128
|
|
163
129
|
private
|
164
130
|
|
165
|
-
#
|
166
|
-
# - Used to get the container element classes
|
131
|
+
# Used to get the container element classes
|
167
132
|
#
|
168
133
|
# @return [String]
|
169
134
|
#
|
@@ -1,88 +1,79 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
module Bootstrap3Helper
|
5
|
-
# @description
|
6
|
-
# - This class is used to general groups of accordions.
|
1
|
+
module Bootstrap3Helper # :nodoc:
|
2
|
+
# This class is used to general groups of accordions.
|
7
3
|
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# <%=
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
4
|
+
# @example Rendering out an Accordion Group in template:
|
5
|
+
# <code>
|
6
|
+
# <%= accordion_group_helper do |group| %>
|
7
|
+
# <%= group.accordion :primary do |accordion| %>
|
8
|
+
# <%= accordion.header { "accordion 1" } %>
|
9
|
+
# <%= accordion.body do %>
|
10
|
+
# <p>This is accordion 1</p>
|
11
|
+
# <% end %>
|
12
|
+
# <% end %>
|
13
|
+
# <%= group.accordion :info do |accordion| %>
|
14
|
+
# <%= accordion.header { "accordion 2" } %>
|
15
|
+
# <%= accordion.body do %>
|
16
|
+
# <p>This is accordion 2</p>
|
17
|
+
# <% end %>
|
18
|
+
# <% end %>
|
19
|
+
# <%= group.accordion :danger do |accordion| %>
|
20
|
+
# <%= accordion.header { "accordion 3" } %>
|
21
|
+
# <%= accordion.body do %>
|
22
|
+
# <p>This is accordion 3</p>
|
23
|
+
# <% end %>
|
24
|
+
# <% end %>
|
15
25
|
# <% end %>
|
16
|
-
#
|
17
|
-
# <%= accordion.header { "accordion 2" } %>
|
18
|
-
# <%= accordion.body do %>
|
19
|
-
# <p>This is accordion 2</p>
|
20
|
-
# <% end %>
|
21
|
-
# <% end %>
|
22
|
-
# <%= group.accordion :danger do |accordion| %>
|
23
|
-
# <%= accordion.header { "accordion 3" } %>
|
24
|
-
# <%= accordion.body do %>
|
25
|
-
# <p>This is accordion 3</p>
|
26
|
-
# <% end %>
|
27
|
-
# <% end %>
|
28
|
-
# <% end %>
|
29
|
-
# </code>
|
26
|
+
# </code>
|
30
27
|
#
|
31
28
|
class AccordionGroup < Component
|
32
|
-
#
|
33
|
-
# - Used to initialize the main object. This objects sole purpose is to
|
29
|
+
# Used to initialize the main object. This objects sole purpose is to
|
34
30
|
# generate a wrapper element with a distinct id and pass that id down to
|
35
31
|
# all the child elements.
|
36
32
|
#
|
37
|
-
|
33
|
+
# @param [ActionView] template
|
34
|
+
# @param [Hash] opts
|
35
|
+
# @option opts [String] :id
|
36
|
+
# @option opts [String] :class
|
37
|
+
# @option opts [Hash] :data
|
38
|
+
#
|
39
|
+
def initialize(template, opts = {}, &block)
|
38
40
|
super(template)
|
39
|
-
|
40
|
-
@id
|
41
|
-
@class
|
41
|
+
|
42
|
+
@id = opts.fetch(:id, uuid)
|
43
|
+
@class = opts.fetch(:class, '')
|
44
|
+
@data = opts.fetch(:data, {})
|
45
|
+
@content = block || proc { '' }
|
42
46
|
end
|
43
47
|
|
44
|
-
#
|
45
|
-
# - This method is the main method for generating individual accordions.
|
48
|
+
# This method is the main method for generating individual accordions.
|
46
49
|
# This is where you would pass in the html attributes.
|
47
50
|
#
|
48
|
-
# @param [NilClass|String|Symbol|Hash]
|
51
|
+
# @param [NilClass|String|Symbol|Hash] context_or_options
|
49
52
|
# @param [Hash] opts
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
# class: [String]
|
54
|
-
# }
|
55
|
-
# </code>
|
53
|
+
# @option opts [String] :id
|
54
|
+
# @option opts [String] :class
|
55
|
+
# @yieldreturn [Accordion] accordion
|
56
56
|
#
|
57
|
-
|
58
|
-
# @return [nilClass]
|
59
|
-
#
|
60
|
-
def accordion(context_or_options = nil, opts = {})
|
57
|
+
def accordion(context_or_options = nil, opts = {}, &block)
|
61
58
|
if context_or_options.is_a?(Hash)
|
62
59
|
context_or_options[:parent_id] = @id
|
63
60
|
else
|
64
61
|
opts[:parent_id] = @id
|
65
62
|
end
|
66
63
|
|
67
|
-
|
68
|
-
yield accordion if block_given?
|
69
|
-
|
70
|
-
@accordions.push(accordion)
|
64
|
+
Accordion.new(@template, context_or_options, opts, &block)
|
71
65
|
end
|
72
66
|
|
73
|
-
#
|
74
|
-
# - The to string method here is what is responsible for rendering out the
|
67
|
+
# The to string method here is what is responsible for rendering out the
|
75
68
|
# entire accordion. As long as the main method is rendered out in the helper,
|
76
69
|
# you will get all the contents.
|
77
70
|
#
|
78
71
|
# @return [String]
|
79
72
|
#
|
80
73
|
def to_s
|
81
|
-
|
82
|
-
@
|
74
|
+
content_tag :div, id: @id, class: "panel-group #{@class}" do
|
75
|
+
@content.call(self)
|
83
76
|
end
|
84
|
-
|
85
|
-
content
|
86
77
|
end
|
87
78
|
end
|
88
79
|
end
|