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 +4 -4
- data/README.md +4 -4
- data/lib/bootstrap3_helper.rb +95 -117
- data/lib/bootstrap3_helper/accordion.rb +63 -120
- data/lib/bootstrap3_helper/accordion_group.rb +45 -54
- data/lib/bootstrap3_helper/alert.rb +22 -34
- data/lib/bootstrap3_helper/callout.rb +14 -24
- data/lib/bootstrap3_helper/component.rb +14 -25
- data/lib/bootstrap3_helper/configuration.rb +25 -0
- data/lib/bootstrap3_helper/panel.rb +38 -45
- data/lib/bootstrap3_helper/tabs.rb +59 -73
- data/lib/bootstrap3_helper/tabs/content.rb +21 -36
- data/lib/bootstrap3_helper/tabs/dropdown.rb +35 -41
- data/lib/bootstrap3_helper/tabs/menu.rb +42 -59
- data/lib/bootstrap3_helper/version.rb +1 -1
- metadata +6 -6
@@ -1,103 +1,89 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
module Bootstrap3Helper
|
5
|
-
# @description
|
6
|
-
# - Used to rapidly generated Bootstrap Tabs Components.
|
1
|
+
module Bootstrap3Helper # :nodoc:
|
2
|
+
# Used to rapidly generated Bootstrap Tabs Components.
|
7
3
|
#
|
8
|
-
# @note
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# block is present, then it will titleize the symbol or string.
|
4
|
+
# @note On menu items - you can pass in either symbol or string for the link. If
|
5
|
+
# you pass in a block, it will use the block for the title of the li. If no
|
6
|
+
# block is present, then it will titleize the symbol or string.
|
12
7
|
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
8
|
+
# Tabs::Menu will respond to <code>item</code> and <code>dropdown</code>
|
9
|
+
# Each method will yield the corresponding component, either a Tabs::Menu
|
10
|
+
# or a Tabs::Dropdown.
|
16
11
|
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
12
|
+
# @example Rendering out a Bootstrap Tab components in a view:
|
13
|
+
# <%= tabs_helper type: :pills do |menu, content| %>
|
14
|
+
# <%= menu.item(:testing1, class: 'active') { ' Testing 1' } %>
|
15
|
+
# <%= menu.item :testing2 %>
|
16
|
+
# <%= menu.item(:testing3) { ' Testing 3' } %>
|
17
|
+
# <%= menu.dropdown 'Testing Dropdown' do |dropdown| %>
|
18
|
+
# <%= dropdown.item(:testing5 ) { 'Testing 5' } %>
|
19
|
+
# <%= dropdown.item(:testing6 ) { 'Testing 6' } %>
|
20
|
+
# <%= dropdown.item(:testing7 ) { 'Testing 7' } %>
|
21
|
+
# <% end %>
|
22
|
+
#
|
23
|
+
# <%= content.item :testing1, class: 'active' do %>
|
24
|
+
# Testing 1 content
|
25
|
+
# <% end %>
|
26
|
+
# <%= content.item :testing2 do %>
|
27
|
+
# Testing 2 content
|
28
|
+
# <% end %>
|
29
|
+
# <%= content.item :testing3 do %>
|
30
|
+
# Testing 3 content
|
31
|
+
# <% end %>
|
32
|
+
# <%= content.item :testing5 do %>
|
33
|
+
# Testing 5 content
|
34
|
+
# <% end %>
|
35
|
+
# <%= content.item :testing6 do %>
|
36
|
+
# Testing 6 content
|
37
|
+
# <% end %>
|
38
|
+
# <%= content.item :testing7 do %>
|
39
|
+
# Testing 7 content
|
40
|
+
# <% end %>
|
41
|
+
# <% end %>
|
27
42
|
#
|
28
|
-
# <% content.item :testing1, class: 'active' do %>
|
29
|
-
# Testing 1 content
|
30
|
-
# <% end %>
|
31
|
-
# <% content.item :testing2 do %>
|
32
|
-
# Testing 2 content
|
33
|
-
# <% end %>
|
34
|
-
# <% content.item :testing3 do %>
|
35
|
-
# Testing 3 content
|
36
|
-
# <% end %>
|
37
|
-
# <% content.item :testing5 do %>
|
38
|
-
# Testing 5 content
|
39
|
-
# <% end %>
|
40
|
-
# <% content.item :testing6 do %>
|
41
|
-
# Testing 6 content
|
42
|
-
# <% end %>
|
43
|
-
# <% content.item :testing7 do %>
|
44
|
-
# Testing 7 content
|
45
|
-
# <% end %>
|
46
|
-
# <% end %>
|
47
|
-
# </code>
|
48
43
|
class Tabs < Component
|
49
|
-
#
|
50
|
-
# - Creates a new Tabs object.
|
44
|
+
# Creates a new Tabs object.
|
51
45
|
#
|
52
|
-
# @param [
|
46
|
+
# @param [ActionView] template - Template in which your are binding too.
|
53
47
|
# @param [Hash] args
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
# id: [String|nilClass] - The ID, if you want one, for the parent container
|
58
|
-
# class: [String|nilClass] - Custom class for the parent container
|
59
|
-
# }
|
60
|
-
# </code>
|
48
|
+
# @option args [String|Symbol] :type Used to tell the helper which tab version - :tabs|:pills
|
49
|
+
# @option args [String] :id The ID, if you want one, for the parent container
|
50
|
+
# @option args [String] :class Custom class for the parent container.
|
61
51
|
#
|
62
|
-
def initialize(template, args = {})
|
52
|
+
def initialize(template, args = {}, &block)
|
63
53
|
super(template)
|
64
|
-
@type = args.fetch(:type, :tabs)
|
65
|
-
@id = args.fetch(:id, nil)
|
66
|
-
@class = args.fetch(:class, '')
|
67
54
|
|
68
|
-
@
|
69
|
-
@
|
55
|
+
@type = args.fetch(:type, :tabs)
|
56
|
+
@id = args.fetch(:id, nil)
|
57
|
+
@class = args.fetch(:class, '')
|
58
|
+
@content = block || proc { '' }
|
70
59
|
end
|
71
60
|
|
72
|
-
#
|
73
|
-
# - Allows you access the Tabs::Menu object.
|
61
|
+
# Allows you access the Tabs::Menu object.
|
74
62
|
#
|
63
|
+
# @see Tabs::Menu
|
75
64
|
# @return [Tabs::Menu]
|
76
65
|
#
|
77
|
-
def menu
|
78
|
-
@
|
66
|
+
def menu(args = {}, &block)
|
67
|
+
Tabs::Menu.new(@template, args.merge(type: @type), &block)
|
79
68
|
end
|
80
69
|
|
81
|
-
#
|
82
|
-
# - Allows you to access the Tabs::Content object
|
70
|
+
# Allows you to access the Tabs::Content object
|
83
71
|
#
|
72
|
+
# @see Tabs::Content
|
84
73
|
# @return [Tabs::Content]
|
85
74
|
#
|
86
|
-
def content
|
87
|
-
@
|
75
|
+
def content(args = {}, &block)
|
76
|
+
Tabs::Content.new(@template, args, &block)
|
88
77
|
end
|
89
78
|
|
90
|
-
#
|
91
|
-
# - Used to render out the HTML of the Tabs Object
|
79
|
+
# Used to render out the HTML of the Tabs Object
|
92
80
|
#
|
93
81
|
# @return [String]
|
94
82
|
#
|
95
83
|
def to_s
|
96
|
-
|
97
|
-
|
84
|
+
content_tag :div, id: @id, class: @class do
|
85
|
+
@content.call(self)
|
98
86
|
end
|
99
|
-
|
100
|
-
html
|
101
87
|
end
|
102
88
|
end
|
103
89
|
end
|
@@ -1,45 +1,35 @@
|
|
1
|
-
#
|
2
|
-
# - Root Object
|
3
|
-
#
|
4
|
-
module Bootstrap3Helper
|
1
|
+
module Bootstrap3Helper # :nodoc:
|
5
2
|
class Tabs
|
6
|
-
#
|
7
|
-
#
|
3
|
+
# Used to rapidly generated Bootstrap Tabs Content Components.
|
4
|
+
#
|
8
5
|
#
|
9
6
|
class Content < Component
|
10
|
-
#
|
11
|
-
# - Creates a new Tabs::Menu object.
|
7
|
+
# Creates a new Tabs::Menu object.
|
12
8
|
#
|
13
|
-
# @param [
|
9
|
+
# @param [ActionView] template Template in which your are binding too.
|
14
10
|
# @param [Hash] args
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# class: [String|nilClass] - Custom class for the parent container
|
19
|
-
# }
|
20
|
-
# </code>
|
11
|
+
# @option args [String] :id The ID, if you want one, for the parent container.
|
12
|
+
# @option args [String] :class Custom class for the parent container.
|
13
|
+
# @option args [Hash] :data Any data attributes you want on the parent element.
|
21
14
|
#
|
22
|
-
def initialize(template, args = {})
|
15
|
+
def initialize(template, args = {}, &block)
|
23
16
|
super(template)
|
24
17
|
|
25
|
-
@id
|
26
|
-
@class
|
27
|
-
@
|
18
|
+
@id = args.fetch(:id, nil)
|
19
|
+
@class = args.fetch(:class, '')
|
20
|
+
@data = args.fetch(:data, {})
|
21
|
+
@content = block || proc { '' }
|
28
22
|
end
|
29
23
|
|
30
|
-
#
|
31
|
-
# - Adds a new tabe-pane item to the object.
|
24
|
+
# Adds a new tabe pane item to the object.
|
32
25
|
#
|
33
26
|
# @param [String|Symbol] name - Used to link to the nav menu item.
|
34
27
|
# @param [Hash] args
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
# data: [Hash] - Any data attributes you wish to assign to div element.
|
39
|
-
# }
|
40
|
-
# </code>
|
28
|
+
# @option args [String] :class Custom class for the pane.
|
29
|
+
# @option args [Hash] :data Any data attributes you want on the pane element.
|
30
|
+
# @yieldreturn [String]
|
41
31
|
#
|
42
|
-
def
|
32
|
+
def pane(name, args = {})
|
43
33
|
data = args.fetch(:data, nil)
|
44
34
|
klass = args.fetch(:class, '')
|
45
35
|
active = klass.include? 'active'
|
@@ -55,21 +45,16 @@ module Bootstrap3Helper
|
|
55
45
|
) do
|
56
46
|
yield if block_given?
|
57
47
|
end
|
58
|
-
|
59
|
-
@items.push(content)
|
60
48
|
end
|
61
49
|
|
62
|
-
#
|
63
|
-
# - Used to render out the object as HTML
|
50
|
+
# Used to render out the object as HTML
|
64
51
|
#
|
65
52
|
# @return [String]
|
66
53
|
#
|
67
54
|
def to_s
|
68
|
-
|
69
|
-
@
|
55
|
+
content_tag :div, id: @id, class: 'tab-content' + @class do
|
56
|
+
@content.call(self)
|
70
57
|
end
|
71
|
-
|
72
|
-
html
|
73
58
|
end
|
74
59
|
end
|
75
60
|
end
|
@@ -1,57 +1,50 @@
|
|
1
|
-
#
|
2
|
-
# - Root Object
|
3
|
-
#
|
4
|
-
module Bootstrap3Helper
|
1
|
+
module Bootstrap3Helper # :nodoc:
|
5
2
|
class Tabs
|
6
|
-
#
|
7
|
-
# - Used to rapidly build dropdown menus for Bootstrap tabs.
|
3
|
+
# Used to rapidly build dropdown menus for Bootstrap tabs.
|
8
4
|
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
5
|
+
# @example Rendering a Dropdown menu component:
|
6
|
+
# <code>
|
7
|
+
# <%= menu.dropdown 'Testing Dropdown' do |dropdown| %>
|
8
|
+
# <%= dropdown.item(:testing5 ) { 'Testing 5' } %>
|
9
|
+
# <%= dropdown.item(:testing6 ) { 'Testing 6' } %>
|
10
|
+
# <%= dropdown.item(:testing7 ) { 'Testing 7' } %>
|
11
|
+
# <% end %>
|
12
|
+
# </code>
|
16
13
|
#
|
17
14
|
class Dropdown < Component
|
18
|
-
#
|
19
|
-
# - Creates a new Tabs::Dropdown object.
|
15
|
+
# Creates a new Tabs::Dropdown object.
|
20
16
|
#
|
21
|
-
# @param [
|
17
|
+
# @param [ActionView] template Template in which your are binding too.
|
18
|
+
# @param [String] name
|
22
19
|
#
|
23
|
-
def initialize(template, name = '')
|
20
|
+
def initialize(template, name = '', &block)
|
24
21
|
super(template)
|
25
22
|
|
26
|
-
@name
|
27
|
-
@
|
23
|
+
@name = name
|
24
|
+
@content = block || proc { '' }
|
28
25
|
end
|
29
26
|
|
30
|
-
#
|
31
|
-
|
27
|
+
# rubocop:disable Metrics/MethodLength
|
28
|
+
|
29
|
+
# Adds a new item to the dropdown object.
|
32
30
|
#
|
33
|
-
# @note
|
34
|
-
#
|
35
|
-
# for the menu item.
|
31
|
+
# @note You can opt out of passing in a block and the li will use the name attribute
|
32
|
+
# for the menu item.
|
36
33
|
#
|
37
34
|
# @param [String|Symbol] name - Used to link nav li to tab-content
|
38
35
|
# @param [Hash] args
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
# data: [Hash] - Any data attributes you wish to assign to li element.
|
44
|
-
# }
|
45
|
-
# </code>
|
36
|
+
# @option args [String] :id The ID, if you want one, for the li element.
|
37
|
+
# @option args [String] :class Custom class for the li element.
|
38
|
+
# @option args [Hash] :data Any data attributes you want on the li element.
|
39
|
+
# @yieldreturn [String]
|
46
40
|
#
|
47
|
-
# rubocop:disable Metrics/MethodLength
|
48
41
|
def item(name, args = {})
|
49
42
|
id = args.fetch(:id, nil)
|
50
43
|
klass = args.fetch(:class, '')
|
51
44
|
data = args.fetch(:data, nil)
|
52
45
|
active = klass.include? 'active'
|
53
46
|
|
54
|
-
|
47
|
+
content_tag(
|
55
48
|
:li,
|
56
49
|
id: id,
|
57
50
|
class: klass,
|
@@ -67,24 +60,25 @@ module Bootstrap3Helper
|
|
67
60
|
block_given? ? yield : name.to_s.titleize
|
68
61
|
end
|
69
62
|
end
|
70
|
-
|
71
|
-
@items.push(li)
|
72
63
|
end
|
73
64
|
# rubocop:enable Metrics/MethodLength
|
74
65
|
|
75
|
-
#
|
76
|
-
# - Used to render out the object and get the HTML representation.
|
66
|
+
# Used to render out the object and get the HTML representation.
|
77
67
|
#
|
78
68
|
# @return [String]
|
79
69
|
#
|
80
70
|
def to_s
|
81
|
-
content = content_tag
|
71
|
+
content = content_tag(
|
72
|
+
:a,
|
73
|
+
@name,
|
74
|
+
href: '#',
|
75
|
+
class: 'dropdown-toggle',
|
76
|
+
data: { toggle: 'dropdown' }, aria: { expanded: false }
|
77
|
+
)
|
82
78
|
|
83
79
|
content += content_tag :ul, id: @id, class: 'dropdown-menu ' do
|
84
|
-
@
|
80
|
+
@content.call(self)
|
85
81
|
end
|
86
|
-
|
87
|
-
content
|
88
82
|
end
|
89
83
|
end
|
90
84
|
end
|
@@ -1,56 +1,44 @@
|
|
1
|
-
#
|
2
|
-
# - Root Object
|
3
|
-
#
|
4
|
-
module Bootstrap3Helper
|
1
|
+
module Bootstrap3Helper # :nodoc:
|
5
2
|
class Tabs
|
6
|
-
#
|
7
|
-
# - Used to rapidly generated Bootstrap Tabs Menu Components.
|
3
|
+
# Used to rapidly generated Bootstrap Tabs Menu Components.
|
8
4
|
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
5
|
+
# @example Rendering out a Tabs::Menu component:
|
6
|
+
# <code>
|
7
|
+
# <% menu.item(:testing3) { ' Testing 3' } %>
|
8
|
+
# </code>
|
12
9
|
#
|
13
10
|
class Menu < Component
|
14
|
-
#
|
15
|
-
# - Creates a new Tabs::Menu object.
|
11
|
+
# Creates a new Tabs::Menu object.
|
16
12
|
#
|
17
|
-
# @param [
|
13
|
+
# @param [ActionView] template - Template in which your are binding too.
|
18
14
|
# @param [Hash] args
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
# id: [String|nilClass] - The ID, if you want one, for the parent container
|
23
|
-
# class: [String|nilClass] - Custom class for the parent container
|
24
|
-
# }
|
25
|
-
# </code>
|
15
|
+
# @option args [Symbol] type Used to tell the helper which tab version :tabs|:pills
|
16
|
+
# @option args [String] id The ID, if you want one, for the parent container
|
17
|
+
# @option args [String] class Custom class for the parent container
|
26
18
|
#
|
27
|
-
def initialize(template, args = {})
|
19
|
+
def initialize(template, args = {}, &block)
|
28
20
|
super(template)
|
29
21
|
|
30
|
-
@id
|
31
|
-
@class
|
32
|
-
@type
|
33
|
-
@
|
22
|
+
@id = args.fetch(:id, nil)
|
23
|
+
@class = args.fetch(:class, '')
|
24
|
+
@type = args.fetch(:type, :tabs)
|
25
|
+
@content = block || proc { '' }
|
34
26
|
end
|
35
27
|
|
36
|
-
#
|
37
|
-
|
28
|
+
# rubocop:disable Metrics/MethodLength
|
29
|
+
|
30
|
+
# Adds a new menu item to the object.
|
38
31
|
#
|
39
|
-
# @note
|
40
|
-
#
|
41
|
-
# for the menu item.
|
32
|
+
# @note You can opt out of passing in a block and the li will use
|
33
|
+
# the name attribute for the menu item.
|
42
34
|
#
|
43
|
-
# @param [String|Symbol] name
|
35
|
+
# @param [String|Symbol] name Used to link nav li to tab-content
|
44
36
|
# @param [Hash] args
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
# data: [Hash] - Any data attributes you wish to assign to li element.
|
50
|
-
# }
|
51
|
-
# </code>
|
37
|
+
# @option args [String] :id
|
38
|
+
# @option args [String] :class
|
39
|
+
# @option args [Hash] :data
|
40
|
+
# @yieldreturn [String]
|
52
41
|
#
|
53
|
-
# rubocop:disable Metrics/MethodLength
|
54
42
|
def item(name, args = {})
|
55
43
|
id = args.fetch(:id, nil)
|
56
44
|
data = args.fetch(:data, nil)
|
@@ -75,42 +63,37 @@ module Bootstrap3Helper
|
|
75
63
|
block_given? ? yield : name.to_s.titleize
|
76
64
|
end
|
77
65
|
end
|
78
|
-
|
79
|
-
@items.push(li)
|
80
66
|
end
|
81
67
|
# rubocop:enable Metrics/MethodLength
|
82
68
|
|
83
|
-
#
|
84
|
-
# - Used to create menu items that are Dropdowns
|
69
|
+
# Used to create menu items that are Dropdowns
|
85
70
|
#
|
86
|
-
# @param [String|Symbol] name
|
71
|
+
# @param [String|Symbol] name
|
72
|
+
# @param [Hash] args
|
73
|
+
# @option args [String] :id
|
74
|
+
# @option args [String] :class
|
75
|
+
# @option args [Hash] :data
|
76
|
+
# @yieldparam dropdown [Tabs::Dropdown]
|
87
77
|
#
|
88
|
-
def dropdown(name, args = {})
|
89
|
-
id
|
90
|
-
data
|
91
|
-
klass
|
92
|
-
|
93
|
-
dropdown = Tabs::Dropdown.new(@template, name)
|
94
|
-
yield dropdown if block_given?
|
78
|
+
def dropdown(name, args = {}, &block)
|
79
|
+
id = args.fetch(:id, nil)
|
80
|
+
data = args.fetch(:data, nil)
|
81
|
+
klass = args.fetch(:class, '')
|
82
|
+
dropdown = Tabs::Dropdown.new(@template, name, &block)
|
95
83
|
|
96
84
|
content = content_tag :li, id: id, class: 'dropdown' + klass, data: data do
|
97
|
-
dropdown.to_s
|
85
|
+
dropdown.to_s.html_safe
|
98
86
|
end
|
99
|
-
|
100
|
-
@items.push(content)
|
101
87
|
end
|
102
88
|
|
103
|
-
#
|
104
|
-
# - Used to render out the contents of the menu.
|
89
|
+
# Used to render out the contents of the menu.
|
105
90
|
#
|
106
91
|
# @return [String]
|
107
92
|
#
|
108
93
|
def to_s
|
109
|
-
|
110
|
-
@
|
94
|
+
content_tag :ul, id: @id, class: "nav nav-#{@type} " + @class, role: 'tablist' do
|
95
|
+
@content.call(self)
|
111
96
|
end
|
112
|
-
|
113
|
-
html
|
114
97
|
end
|
115
98
|
end
|
116
99
|
end
|