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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7690ea3af6632902048f7f389e97a9c2317e007c6dab849b754fabe805a7357e
4
- data.tar.gz: 2c8234630ce566f379f1d1a46d9ab7e47e958c3b1059df4aa41a0003a27700bc
3
+ metadata.gz: 4052a52cedf01461e605010a66bbf78a2f1741e4046a755495226edeccff6027
4
+ data.tar.gz: 538817f6096634dcfead3335a03198f34bcecc987d95d22561f79e34553ffa50
5
5
  SHA512:
6
- metadata.gz: d54b3740ae4f7bd45adcea82506ebe65fae16dcca0837c42e83ada33480c67053acaee9112ffe7029283d2d4babe71d0cfbe9183e97b8d30e886527fd2cf70e5
7
- data.tar.gz: 5e42f3ff987c0e32aa5f2b5dd94c744abc7d4afbadeb41ee17da5b1cfd64b5975a123aa4d3d135e9dd2871fa9abd1ee3ec7d6862cd41d53a8bc41ece2e9a6ea8
6
+ metadata.gz: bc609fbe4d4cb0d76fcd70155ee21b9edb27741cd4b590bacce764408d34ca4fc47232ba4458fb6a657c9c4894a7310675ac6d774ae6ad567a31724b8fd52ebb
7
+ data.tar.gz: c6e1cdca50954072d204055706352aca4ee29abaa394749d1c623b2ce9eb43d970c3d5da51663cd641ccee0a98382459ebf4ee8f169ef3acc044186940c7b17b
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Bootstrap3Helper
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
- ## Usage
21
+ ## Panel Helper
22
22
 
23
- `Panel Helper`
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
- Some Header for your panel
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
- `Alert Helper`
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
- `Accordion Helper`
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, { class: 'optional-class', id: 'optional_id', collapse_id: 'optional_collapse_id', expanded: true } do |accordion| %>
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 attribute you are looking for.
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
- `AccordionGroup Helper`
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
- **Note:** the accordion_group 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 individual accordions. The helper does the rest.
166
+ ## Tab Helper
99
167
 
100
- ---
168
+ Tabs respond to the following methods:
101
169
 
102
- `Panel Helper`
170
+ - menu
171
+ - item (Used for linking to tab content)
172
+ - dropdown (Used for making dropdown menus)
173
+ - content
103
174
 
104
- ```erb
105
- <%= tabs_helper type: :pills do |menu, content| %>
106
- <% menu.item(:testing1, class: 'active') { ' Testing 1' } %>
107
- <% menu.item :testing2 %>
108
- <% menu.item(:testing3) { ' Testing 3' } %>
109
- <% menu.dropdown 'Testing Dropdown' do |dropdown| %>
110
- <%= dropdown.item(:testing5 ) { 'Testing 5' } %>
111
- <%= dropdown.item(:testing6 ) { 'Testing 6' } %>
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
- <% content.item :testing1, class: 'active' do %>
117
- Testing 1 content
118
- <% end %>
119
- <% content.item :testing2 do %>
120
- Testing 2 content
121
- <% end %>
122
- <% content.item :testing3 do %>
123
- Testing 3 content
124
- <% end %>
125
- <% content.item :testing5 do %>
126
- Testing 5 content
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
- <% content.item :testing7 do %>
132
- Testing 7 content
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
- # @root
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
- # @description
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] - Bootstrap class context, or options hash.
11
+ # @param [NilClass|String|Symbol|Hash] context_or_options Bootstrap class context, or options hash.
27
12
  # @param [Hash] opts
28
- # <code>
29
- # args = {
30
- # parent_id: [String]
31
- # id: [String]
32
- # class: [String]
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 = parse_arguments(context_or_options, opts)
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
- # @description
51
- # - Creates the header element for the accordion
52
- #
53
- # @note
54
- # - NilClass :to_s returns an empty String
55
- #
56
- # @params [Hash] args
57
- # <code>
58
- # args = {
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
- # rubocop:disable Metrics/MethodLength
69
- def header(args = {})
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 = content_tag :div, id: id, class: 'panel-heading ' + klass do
78
- content_tag :h3, class: 'panel-title' do
79
- content_tag :a, href: "##{@collapse_id}", data: data do
80
- content = yield if block_given?
81
- content.to_s.html_safe
82
- end
83
- end
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
- # @description
89
- # - Creates the body element for the accordion.
90
- #
91
- # @note
92
- # - NilClass :to_s returns an empty String
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
- # @params [Hash] args
95
- # <code>
96
- # args = {
97
- # id: [String]
98
- # class: [String]
99
- # data: [Hash]
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
- # @yields [Accordion] self
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(args = {})
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
- @body = content_tag :div, id: @collapse_id, class: klass do
114
- content_tag :div, class: 'panel-body', data: data do
115
- content = yield if block_given?
116
- content.to_s.html_safe
117
- end
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
- # @description
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(args = {})
138
- id = args.fetch(:id, nil)
139
- klass = args.fetch(:class, '')
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
- # @description
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
- content = content_tag :div, id: @id, class: container_classes do
157
- @header + @body + @footer
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
- # @description
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
- # @root
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
- # <code>
9
- # <%= accordion_group_helper do |group| %>
10
- # <%= group.accordion :primary do |accordion| %>
11
- # <%= accordion.header { "accordion 1" } %>
12
- # <%= accordion.body do %>
13
- # <p>This is accordion 1</p>
14
- # <% end %>
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
- # <%= group.accordion :info do |accordion| %>
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
- # @description
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
- def initialize(template, opts = {})
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
- @accordions = []
40
- @id = opts.fetch(:id, uuid)
41
- @class = opts.fetch(: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
- # @description
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] - Bootstrap class context, or options hash.
51
+ # @param [NilClass|String|Symbol|Hash] context_or_options
49
52
  # @param [Hash] opts
50
- # <code>
51
- # args = {
52
- # id: [String]
53
- # class: [String]
54
- # }
55
- # </code>
53
+ # @option opts [String] :id
54
+ # @option opts [String] :class
55
+ # @yieldreturn [Accordion] accordion
56
56
  #
57
- # @yields [Accordion] accordion
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
- accordion = Accordion.new(@template, context_or_options, opts)
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
- # @description
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
- content = content_tag :div, id: @id, class: "panel-group #{@class}" do
82
- @accordions.map(&:to_s).join.html_safe
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