bootstrap3_helper 1.0.1 → 2.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: 74e356782b2f424f78b9bd3731009d7ba7a1492a392e782c5cade487ea765a26
4
- data.tar.gz: 7a8fb76f39fa53b9bdcebf6542239c58448e8caa88b725b5f47c4255ad31d80f
3
+ metadata.gz: fa4a4982f3b39160bbef89613d224a4445460f48f7c57493f13b2e716a762c27
4
+ data.tar.gz: d896ed4c7700a1d4be61432c016790de7774a8fef92b3942a5c9e43f8b45531e
5
5
  SHA512:
6
- metadata.gz: 71bad603e6cf3834f68c6f216e1dcc3c0b0e88f76ef4a44c05bc9f101d4eba4271a9312caee0500ae2e317e35485ee9fdd214dc807c4d42422eb9a4acc090c20
7
- data.tar.gz: 8f062f014b468ba1b8fb916666556a69b3ddb03cfa9e024738babe7480ffcb4ad55f3507672d69b98abcb55251c4d3ae664f6055bbca1cf2c7de9d21440fb632
6
+ metadata.gz: a69b36f433d89b6003e8b7662dc3b2c0eae7b1d2e2241eb87aa8b168f3cd15cd48acf0b55e893c44366ba311bb48ce5e20ceb3595b4b57ebce58e64d52f5d2f6
7
+ data.tar.gz: bfb6e3bb9c1472159609be87b92aff76e7bc28c40249a2b721610acbb3a002d8118b290f2bc006e2b595a0bf0cfdf86616795318cab1dd47070abb51c456262f
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
 
@@ -79,7 +79,7 @@ end
79
79
  <%= accordion.body do %>
80
80
  <p>This is accordion 1</p>
81
81
  <% end %>
82
- <%end %>
82
+ <% end %>
83
83
  <% g.accordion :info do |accordion| %>
84
84
  <%= accordion.header { "Accordion 2" } %>
85
85
  <%= accordion.body do %>
@@ -91,7 +91,7 @@ end
91
91
  <%= accordion.body do %>
92
92
  <p>This is accordion 3</p>
93
93
  <% end %>
94
- <%end %>
94
+ <% end %>
95
95
  <% end %>
96
96
  ```
97
97
 
@@ -99,7 +99,7 @@ end
99
99
 
100
100
  ---
101
101
 
102
- `Panel Helper`
102
+ `Tab Helper`
103
103
 
104
104
  ```erb
105
105
  <%= tabs_helper type: :pills do |menu, content| %>
@@ -13,15 +13,13 @@ require 'bootstrap3_helper/tabs/dropdown'
13
13
  require 'bootstrap3_helper/tabs/menu'
14
14
  require 'bootstrap3_helper/railtie'
15
15
 
16
- # @description
17
- # - This helper module includes UI helpers that will help generate
16
+ # This helper module includes UI helpers that will help generate
18
17
  # common Bootstrap components.
19
18
  #
20
19
  module Bootstrap3Helper
21
- # @description
22
- # - Allows you to rapidly build Panel components.
20
+ # Allows you to rapidly build Panel components.
23
21
  #
24
- # <code>
22
+ # @example Bootstrap Panel Component:
25
23
  # <%= panel_helper :primary do |p| %>
26
24
  # <%= p.header { "Some Title" }
27
25
  # <%= p.body class: 'custom-class', id: 'custom-id' do %>
@@ -31,53 +29,46 @@ module Bootstrap3Helper
31
29
  # //HTML or Ruby
32
30
  # <% end %>
33
31
  # <% end %>
34
- # </code>
35
32
  #
36
- # @params [Symbol|String|Hash|NilClass] *args
33
+ # @param [Symbol|String|Hash|NilClass] args
34
+ # @yieldparam [Panel] panel
37
35
  # @return [String]
38
36
  #
39
- def panel_helper(*args)
40
- panel = Panel.new(self, *args)
41
- capture { yield(panel) if block_given? }
42
- panel
37
+ def panel_helper(*args, &block)
38
+ Panel.new(self, *args, &block)
43
39
  end
44
40
 
45
- # @description
46
- # - Creates an Alert component.
41
+ # Creates an Alert component.
47
42
  #
48
- # <code>
43
+ # @example Bootstrap Alert Component:
49
44
  # <%= alert_helper :danger, dismissble: true do %>
50
45
  # Something went wrong with your model data...
51
46
  # <% end %>
52
- # </code>
53
47
  #
54
- # @params [Symbol|String|Hash|NilClass] *args
48
+ # @param [Symbol|String|Hash|NilClass] args
49
+ # @yieldreturn [String]
55
50
  # @return [String]
56
51
  #
57
52
  def alert_helper(*args, &block)
58
- alert = Alert.new(self, *args, &block)
59
- alert
53
+ Alert.new(self, *args, &block)
60
54
  end
61
55
 
62
- # @description
63
- # - Creates an Callout component.
56
+ # Creates an Callout component.
64
57
  #
65
- # <code>
58
+ # @example Bootstrap Callout Component:
66
59
  # <%= callout_helper :danger %>
67
60
  # Some information that needs your attention...
68
61
  # <% end %>
69
- # </code>
70
62
  #
71
- # @params [Symbol|String|Hash|NilClass] *args
63
+ # @param [Symbol|String|Hash|NilClass] args
64
+ # @yieldreturn [String]
72
65
  # @return [String]
73
66
  #
74
67
  def callout_helper(*args, &block)
75
- callout = Callout.new(self, *args, &block)
76
- callout
68
+ Callout.new(self, *args, &block)
77
69
  end
78
70
 
79
- # @description
80
- # - Just a easy way of checking if the environment is a devbox
71
+ # Just a easy way of checking if the environment is a devbox
81
72
  # or a server.
82
73
  #
83
74
  # @return [Boolean]
@@ -86,79 +77,68 @@ module Bootstrap3Helper
86
77
  Rails.root.to_s.include?('home')
87
78
  end
88
79
 
89
- # @description
90
- # - Easily build a bootstrap accordion group component.
80
+ # Easily build a bootstrap accordion group component.
91
81
  #
92
- # @note
93
- # - All the element ids and data attributes needed to make the javascript
94
- # function, are all synced up in the AccordionGroup and Accordion classes.
95
- # You don't need to worry about them :)
82
+ # @note All the element ids and data attributes needed to make the javascript
83
+ # function, are all synced up in the AccordionGroup and Accordion classes.
84
+ # You don't need to worry about them.
96
85
  #
97
- # <code>
86
+ # @example Bootstrap Accordion Group Component:
98
87
  # <%= accordion_group_helper do |group| %>
99
88
  # <% group.accordion class: 'primary' do |accordion| %>
100
89
  # <%= accordion.header { "accordion 1" } %>
101
90
  # <%= accordion.body do %>
102
91
  # <p>This is accordion 1</p>
103
92
  # <% end %>
104
- # <%end %>
93
+ # <% end %>
105
94
  # <% group.accordion class: 'info' do |accordion| %>
106
95
  # <%= accordion.header { "accordion 2" } %>
107
96
  # <%= accordion.body do %>
108
97
  # <p>This is accordion 2</p>
109
98
  # <% end %>
110
- # <%end %>
99
+ # <% end %>
111
100
  # <% group.accordion class: 'danger' do |accordion| %>
112
101
  # <%= accordion.header { "accordion 3" } %>
113
102
  # <%= accordion.body do %>
114
103
  # <p>This is accordion 3</p>
115
104
  # <% end %>
116
- # <%end %>
105
+ # <% end %>
117
106
  # <% end %>
118
- # </code>
119
107
  #
120
- # @yields [AccordionGroup] group
108
+ # @param [Symbol|String|Hash|NilClass] args
109
+ # @yieldparam [AccordionGroup] group
121
110
  # @return [String]
122
111
  #
123
- def accordion_group_helper(*args)
124
- group = AccordionGroup.new(self, *args)
125
- capture { yield group if block_given? }
126
- group
112
+ def accordion_group_helper(*args, &block)
113
+ AccordionGroup.new(self, *args, &block)
127
114
  end
128
115
 
129
- # @description
130
- # - Easily build a bootstrap accordion component
131
- #
132
- # <code>
133
- # <%= accordion_helper class: 'primary' do |accordion| %>
134
- # <%= accordion.header do %>
135
- # <span class="something">This is the heading....</span>
136
- # <% end %>
137
- # <%= accordion.body do %>
138
- # <p>This is the body of the accordion....</p>
139
- # <% end %>
140
- # <% end %>
141
- # </code>
116
+ # Easily build a bootstrap accordion component
117
+ #
118
+ # @example Bootstrap Panel Component:
119
+ # <%= accordion_helper class: 'primary' do |accordion| %>
120
+ # <%= accordion.header do %>
121
+ # <span class="something">This is the heading....</span>
122
+ # <% end %>
123
+ # <%= accordion.body do %>
124
+ # <p>This is the body of the accordion....</p>
125
+ # <% end %>
126
+ # <% end %>
142
127
  #
143
- # @params [Symbol|String|Hash|NilClass] *args
128
+ # @param [Symbol|String|Hash|NilClass] args
129
+ # @yieldparam [Accordion] accordion
144
130
  # @return [String]
145
131
  #
146
- def accordion_helper(*args)
147
- accordion = Accordion.new(self, *args)
148
- capture { yield accordion if block_given? }
149
- accordion
132
+ def accordion_helper(*args, &block)
133
+ Accordion.new(self, *args, &block)
150
134
  end
151
135
 
152
- # @description
153
- # - Allows you to rapidly build bootstrap glyphs.
136
+ # Allows you to rapidly build bootstrap glyphs.
154
137
  #
155
- # @note
156
- # - Only supply the last part of the glyph makrup.
138
+ # @note Only supply the last part of the glyph makrup.
157
139
  #
158
- # <code>
159
- # <span class"glyphicon glyphicon-pencil"></span>
140
+ # @example Bootstrap Glyphicon Component:
160
141
  # <%= icon_helper('pencil') %>
161
- # </code>
162
142
  #
163
143
  # @param [String|Symbol] name
164
144
  #
@@ -166,54 +146,52 @@ module Bootstrap3Helper
166
146
  content_tag :span, '', class: "glyphicon glyphicon-#{name}"
167
147
  end
168
148
 
169
- # @description
170
- # - Used to rapidly build Tabs.
171
- #
172
- # @note
173
- # - On menu items - you can pass in either symbol or string for the link. If
174
- # you pass in a block, it will use the block for the title of the li. If no
175
- # block is present, then it will titleize the symbol or string.
176
- #
177
- # Tabs::Menu will respond to <code>item</code> and <code>dropdown</code>
178
- # Each method will yield the corresponding component, either a Tabs::Menu
179
- # or a Tabs::Dropdown.
180
- #
181
- # <code>
182
- # <%= tabs_helper type: :pills do |menu, content| %>
183
- # <% menu.item(:testing1, class: 'active') { ' Testing 1' } %>
184
- # <% menu.item :testing2 %>
185
- # <% menu.item(:testing3) { ' Testing 3' } %>
186
- # <% menu.dropdown 'Testing Dropdown' do |dropdown| %>
187
- # <%= dropdown.item(:testing5 ) { 'Testing 5' } %>
188
- # <%= dropdown.item(:testing6 ) { 'Testing 6' } %>
189
- # <%= dropdown.item(:testing7 ) { 'Testing 7' } %>
190
- # <% end %>
191
- #
192
- #
193
- # <% content.item :testing1, class: 'active' do %>
194
- # Testing 1 content
195
- # <% end %>
196
- # <% content.item :testing2 do %>
197
- # Testing 2 content
198
- # <% end %>
199
- # <% content.item :testing3 do %>
200
- # Testing 3 content
201
- # <% end %>
202
- # <% content.item :testing5 do %>
203
- # Testing 5 content
204
- # <% end %>
205
- # <% content.item :testing6 do %>
206
- # Testing 6 content
207
- # <% end %>
208
- # <% content.item :testing7 do %>
209
- # Testing 7 content
210
- # <% end %>
211
- # <% end %>
212
- # </code>
213
- #
214
- def tabs_helper(args = {})
215
- tabs = Tabs.new(self, args)
216
- capture { yield(tabs.menu, tabs.content) if block_given? }
217
- tabs
149
+ # Used to rapidly build Tabs.
150
+ #
151
+ # @note On menu items - you can pass in either symbol or string for the link. If
152
+ # you pass in a block, it will use the block for the title of the li. If no
153
+ # block is present, then it will titleize the symbol or string.
154
+ # Tabs::Menu will respond to <code>item</code> and <code>dropdown</code>
155
+ # Each method will yield the corresponding component, either a Tabs::Menu
156
+ # or a Tabs::Dropdown.
157
+ #
158
+ # @example Bootstrap Tabs Component:
159
+ # <%= tabs_helper type: :pills do |menu, content| %>
160
+ # <%= menu.item(:testing1, class: 'active') { ' Testing 1' } %>
161
+ # <%= menu.item :testing2 %>
162
+ # <%= menu.item(:testing3) { ' Testing 3' } %>
163
+ # <%= menu.dropdown 'Testing Dropdown' do |dropdown| %>
164
+ # <%= dropdown.item(:testing5 ) { 'Testing 5' } %>
165
+ # <%= dropdown.item(:testing6 ) { 'Testing 6' } %>
166
+ # <%= dropdown.item(:testing7 ) { 'Testing 7' } %>
167
+ # <% end %>
168
+ #
169
+ #
170
+ # <%= content.item :testing1, class: 'active' do %>
171
+ # Testing 1 content
172
+ # <% end %>
173
+ # <%= content.item :testing2 do %>
174
+ # Testing 2 content
175
+ # <% end %>
176
+ # <%= content.item :testing3 do %>
177
+ # Testing 3 content
178
+ # <% end %>
179
+ # <%= content.item :testing5 do %>
180
+ # Testing 5 content
181
+ # <% end %>
182
+ # <%= content.item :testing6 do %>
183
+ # Testing 6 content
184
+ # <% end %>
185
+ # <%= content.item :testing7 do %>
186
+ # Testing 7 content
187
+ # <% end %>
188
+ # <% end %>
189
+ #
190
+ # @param [Symbol|String|Hash|NilClass] args
191
+ # @yieldparam [Tabs] tabs
192
+ # @return [String]
193
+ #
194
+ def tabs_helper(args = {}, &block)
195
+ Tabs.new(self, args, &block)
218
196
  end
219
197
  end
@@ -1,42 +1,34 @@
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>
4
+ # @example Render out an Accordion component in a template:
5
+ # <code>
6
+ # <%= accordion_helper :primary do |accordion| %>
7
+ # <%= accordion.header do %>
8
+ # <span class="something">This is the heading....</span>
9
+ # <% end %>
10
+ # <%= accordion.body do %>
11
+ # <p>This is the body of the accordion....</p>
12
+ # <% end %>
13
+ # <% end %>
14
+ # </code>
18
15
  #
19
16
  class Accordion < Component
20
- # @description
21
- # - Initlize a new accordion object. If this part of a parent element, i.e
17
+ # Initlize a new accordion object. If this part of a parent element, i.e
22
18
  # AccordionGroup, we need to keep track of the parent element id, so we can
23
19
  # pass it down to the other components.
24
20
  #
25
21
  # @param [Class] template - Template in which your are binding too.
26
22
  # @param [NilClass|String|Symbol|Hash] - Bootstrap class context, or options hash.
27
23
  # @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>
24
+ # @option opts [String] :parent_id The parent element ID if this accordion is part of a group.
25
+ # @option opts [String] :id The ID of the element
26
+ # @option opts [String] :class Custom class for the component.
27
+ # @option opts [String] :collapse_id The ID of the element to collapse when clicked.
28
+ # @option opts [Boolean] :expanded Initial state of the accordion.
37
29
  # @return [Accordion]
38
30
  #
39
- def initialize(template, context_or_options = nil, opts = {})
31
+ def initialize(template, context_or_options = nil, opts = {}, &block)
40
32
  super(template)
41
33
  @context, args = parse_arguments(context_or_options, opts)
42
34
 
@@ -45,127 +37,81 @@ module Bootstrap3Helper
45
37
  @class = args.fetch(:class, '')
46
38
  @collapse_id = args.fetch(:collapse_id, uuid)
47
39
  @expanded = args.fetch(:expanded, false)
40
+ @content = block || proc { '' }
41
+ @panel = Panel.new(@template, context_or_options, opts)
48
42
  end
49
43
 
50
- # @description
51
- # - Creates the header element for the accordion
44
+ # rubocop:disable Metrics/MethodLength
45
+
46
+ # Creates the header element for the accordion
52
47
  #
53
- # @note
54
- # - NilClass :to_s returns an empty String
48
+ # @note NilClass :to_s returns an empty String
55
49
  #
56
50
  # @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]
51
+ # @option opts [String] :id
52
+ # @option opts [String] :class
53
+ # @option opts [Hash] :data
54
+ # @yieldreturn [String]
67
55
  #
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, {})
73
-
56
+ def header(args = {}, &block)
57
+ data = args.fetch(:data, {})
74
58
  data[:toggle] = 'collapse'
75
- data[:parent] = "##{@parent_id}"
59
+ data[:parent] = "##{@parent_id}" if @parent_id.present?
76
60
 
77
- @header = content_tag(
78
- :div,
79
- id: id,
80
- role: 'tab',
81
- class: 'panel-heading ' + klass
82
- ) do
83
- content_tag :h3, class: 'panel-title' do
84
- content_tag(
85
- :a,
86
- href: "##{@collapse_id}",
87
- role: 'button',
88
- data: data,
89
- aria: { expanded: @expanded, controls: "##{@collapse_id}" }
90
- ) do
91
- content = yield if block_given?
92
- content.to_s.html_safe
93
- end
94
- end
61
+ @panel.header(args) do
62
+ content_tag(
63
+ :a,
64
+ href: "##{@collapse_id}",
65
+ role: 'button',
66
+ data: data,
67
+ aria: { expanded: @expanded, controls: "##{@collapse_id}" },
68
+ &block
69
+ )
95
70
  end
96
71
  end
97
72
  # rubocop:enable Metrics/MethodLength
98
73
 
99
- # @description
100
- # - Creates the body element for the accordion.
74
+ # rubocop:disable Metrics/MethodLength
75
+
76
+ # Creates the body element for the accordion.
101
77
  #
102
- # @note
103
- # - NilClass :to_s returns an empty String
78
+ # @note NilClass :to_s returns an empty String
104
79
  #
105
80
  # @params [Hash] args
106
- # <code>
107
- # args = {
108
- # id: [String]
109
- # class: [String]
110
- # data: [Hash]
111
- # }
112
- # </code>
81
+ # @option opts [String] :id
82
+ # @option opts [String] :class
83
+ # @option opts [Hash] :data
84
+ # @yieldreturn [String]
113
85
  #
114
- # @yields [Accordion] self
115
- # @return [nilClass]
116
- #
117
- #
118
- # rubocop:disable Metrics/MethodLength
119
- def body(args = {})
86
+ def body(args = {}, &block)
120
87
  klass = 'panel-collapse collapse '
121
- data = args.fetch(:data, {})
122
- klass += args.fetch(:class, '')
123
88
  klass += ' in' if @expanded
124
89
 
125
- @body = content_tag(
90
+ content_tag(
126
91
  :div,
127
92
  id: @collapse_id,
128
93
  role: 'tabpanel',
129
94
  class: klass,
130
95
  aria: { labelledby: "##{@collapse_id}" }
131
96
  ) do
132
- content_tag :div, class: 'panel-body', data: data do
133
- content = yield if block_given?
134
- content.to_s.html_safe
135
- end
97
+ @panel.body(args, &block)
136
98
  end
137
99
  end
138
100
  # rubocop:enable Metrics/MethodLength
139
101
 
140
- # @description
141
- # - Creates the footer element for the accordion
102
+ # Creates the footer element for the accordion
142
103
  #
143
104
  # @params [Hash] args
144
- # <code>
145
- # args = {
146
- # id: [String]
147
- # class: [String]
148
- # data: [Hash]
149
- # }
150
- # </code>
151
- #
152
- # @yields [Accordion] self
153
- # @return [nilClass]
105
+ # @option opts [String] :id
106
+ # @option opts [String] :class
107
+ # @option opts [Hash] :data
108
+ # @yieldreturn [String]
154
109
  #
155
- #
156
- def footer(args = {})
157
- id = args.fetch(:id, nil)
158
- klass = args.fetch(:class, '')
159
- data = args.fetch(:data, {})
160
-
161
- @footer = content_tag :div, id: id, class: 'panel-footer ' + klass, data: data do
162
- content = yield if block_given?
163
- content.to_s.html_safe
164
- end
110
+ def footer(args = {}, &block)
111
+ @panel.footer(args, &block)
165
112
  end
166
113
 
167
- # @description
168
- # - The to string method here is what is responsible for rendering out the
114
+ # The to string method here is what is responsible for rendering out the
169
115
  # accordion element. As long as the main method is rendered out in the
170
116
  # helper, you will get the entire accordion.
171
117
  #
@@ -173,16 +119,13 @@ module Bootstrap3Helper
173
119
  #
174
120
  def to_s
175
121
  content = content_tag :div, id: @id, class: container_classes do
176
- @header + @body + @footer
122
+ @content.call(self)
177
123
  end
178
-
179
- content
180
124
  end
181
125
 
182
126
  private
183
127
 
184
- # @description
185
- # - Used to get the container element classes
128
+ # Used to get the container element classes
186
129
  #
187
130
  # @return [String]
188
131
  #