bootstrap3_helper 1.0.1 → 2.0.0
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 +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,77 +1,70 @@
|
|
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
|
+
# @eample 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
51
|
# @param [NilClass|String|Symbol|Hash] - Bootstrap class context, or options hash.
|
49
52
|
# @param [Hash] opts
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
# class: [String]
|
54
|
-
# }
|
55
|
-
# </code>
|
53
|
+
# @option args [String] id The ID, if you want one, for the parent container
|
54
|
+
# @option args [String] class Custom class for the parent container
|
55
|
+
# @yieldparam 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
|
#
|
@@ -79,10 +72,8 @@ module Bootstrap3Helper
|
|
79
72
|
#
|
80
73
|
def to_s
|
81
74
|
content = content_tag :div, id: @id, class: "panel-group #{@class}" do
|
82
|
-
@
|
75
|
+
@content.call(self)
|
83
76
|
end
|
84
|
-
|
85
|
-
content
|
86
77
|
end
|
87
78
|
end
|
88
79
|
end
|
@@ -1,11 +1,8 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
module Bootstrap3Helper
|
5
|
-
# @description
|
6
|
-
# - The Alert helper is meant to help you rapidly build Bootstrap Alert
|
1
|
+
module Bootstrap3Helper # :nodoc:
|
2
|
+
# The Alert helper is meant to help you rapidly build Bootstrap Alert
|
7
3
|
# components quickly and easily. The dissmiss button is optional.
|
8
4
|
#
|
5
|
+
# @example Rendering a Bootstrap Alert Component in a view:
|
9
6
|
# <code>
|
10
7
|
# <%= alert_helper :warning, dismissable: true do %>
|
11
8
|
# <% if @model.errors.present? %>
|
@@ -17,33 +14,26 @@ module Bootstrap3Helper
|
|
17
14
|
# </code>
|
18
15
|
#
|
19
16
|
class Alert < Component
|
20
|
-
#
|
21
|
-
# - Used to generate Bootstrap alert components quickly.
|
17
|
+
# Used to generate Bootstrap alert components quickly.
|
22
18
|
#
|
23
|
-
# @param
|
24
|
-
# @param
|
25
|
-
# @param
|
26
|
-
#
|
27
|
-
#
|
28
|
-
# id: [String] - ID of the alert box
|
29
|
-
# class: [String] - Additional classes for the alert box
|
30
|
-
# }
|
31
|
-
# </code>
|
32
|
-
# @param [Proc] &block
|
19
|
+
# @param [Class] template Template in which your are binding too.
|
20
|
+
# @param [NilClass|String|Symbol|Hash] Bootstrap class context, or options hash.
|
21
|
+
# @param [Hash] opts
|
22
|
+
# @option opts [String] :id The ID of the element
|
23
|
+
# @option opts [String] :class Custom class for the component.
|
33
24
|
# @return [Alert]
|
34
25
|
#
|
35
26
|
def initialize(template, context_or_options = nil, opts = {}, &block)
|
36
27
|
super(template)
|
37
28
|
@context, args = parse_arguments(context_or_options, opts)
|
38
29
|
|
39
|
-
@id
|
40
|
-
@class
|
30
|
+
@id = args.fetch(:id, nil)
|
31
|
+
@class = args.fetch(:class, '')
|
41
32
|
@dismissible = args.fetch(:dismissible, false)
|
42
|
-
@content
|
33
|
+
@content = block || proc { '' }
|
43
34
|
end
|
44
35
|
|
45
|
-
#
|
46
|
-
# - The dissmiss button, if the element has one.
|
36
|
+
# The dissmiss button, if the element has one.
|
47
37
|
#
|
48
38
|
# @return [String]
|
49
39
|
#
|
@@ -53,28 +43,26 @@ module Bootstrap3Helper
|
|
53
43
|
end
|
54
44
|
end
|
55
45
|
|
56
|
-
#
|
57
|
-
# - Used to render out the Alert component.
|
46
|
+
# Used to render out the Alert component.
|
58
47
|
#
|
59
|
-
# @note
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
#
|
64
|
-
# buffer in order to get it to persist after the block call.
|
48
|
+
# @note Concat needs to be used to add the content of the button to the output
|
49
|
+
# buffer. For some reason, if though the block returns a String, trying to
|
50
|
+
# add that string to the dismiss button string, returns with the dismiss
|
51
|
+
# button missing. Was forced to caoncat the button to the current output
|
52
|
+
# buffer in order to get it to persist after the block call.
|
65
53
|
#
|
66
54
|
# @return [String]
|
67
55
|
#
|
68
56
|
def to_s
|
69
57
|
content_tag :div, id: @id, class: container_class do
|
70
|
-
concat(@dismissible ? close_button : '')
|
58
|
+
concat(@dismissible ? close_button : '')
|
59
|
+
@content.call(self)
|
71
60
|
end
|
72
61
|
end
|
73
62
|
|
74
63
|
private
|
75
64
|
|
76
|
-
#
|
77
|
-
# - Used to get the container classes.
|
65
|
+
# Used to get the container classes.
|
78
66
|
#
|
79
67
|
# @return [String]
|
80
68
|
#
|
@@ -1,47 +1,37 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
module Bootstrap3Helper
|
5
|
-
# @description
|
6
|
-
# - Used to generate Bootstrap callout component quickly.
|
1
|
+
module Bootstrap3Helper # :nodoc:
|
2
|
+
# Used to generate Bootstrap callout component quickly.
|
7
3
|
#
|
8
|
-
# @param [Class] template - Template in which your are binding too.
|
9
|
-
# @param [NilClass|String|Symbol|Hash] - Bootstrap class context, or options hash.
|
10
|
-
# @param [Hash] opts
|
11
|
-
# <code>
|
12
|
-
# opts = {
|
13
|
-
# id: [String] - ID of the alert box
|
14
|
-
# class: [String] - Additional classes for the alert box
|
15
|
-
# }
|
16
|
-
# </code>
|
17
|
-
# @param [Proc] &block
|
18
|
-
# @return [Callout]
|
19
4
|
#
|
20
5
|
class Callout < Component
|
6
|
+
# @param [Class] template - Template in which your are binding too.
|
7
|
+
# @param [NilClass|String|Symbol|Hash] - Bootstrap class context, or options hash.
|
8
|
+
# @param [Hash] opts
|
9
|
+
# @option opts [String] :id The ID of the element
|
10
|
+
# @option opts [String] :class Custom class for the component.
|
11
|
+
# @return [Callout]
|
12
|
+
#
|
21
13
|
def initialize(template, context_or_options = nil, opts = {}, &block)
|
22
14
|
super(template)
|
23
15
|
@context, args = parse_arguments(context_or_options, opts)
|
24
16
|
|
25
|
-
@id
|
26
|
-
@class
|
17
|
+
@id = args.fetch(:id, nil)
|
18
|
+
@class = args.fetch(:class, '')
|
27
19
|
@content = block || proc { '' }
|
28
20
|
end
|
29
21
|
|
30
|
-
#
|
31
|
-
# - Returns a string representation of the component.
|
22
|
+
# Returns a string representation of the component.
|
32
23
|
#
|
33
24
|
# @return [String]
|
34
25
|
#
|
35
26
|
def to_s
|
36
27
|
content_tag :div, id: @id, class: container_class do
|
37
|
-
@content.call
|
28
|
+
@content.call(self)
|
38
29
|
end
|
39
30
|
end
|
40
31
|
|
41
32
|
private
|
42
33
|
|
43
|
-
#
|
44
|
-
# - Used to get the container classes.
|
34
|
+
# Used to get the container classes.
|
45
35
|
#
|
46
36
|
# @return [String]
|
47
37
|
#
|
@@ -1,25 +1,18 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
module Bootstrap3Helper
|
5
|
-
# @description
|
6
|
-
# - This super class is meant to contain commonly used methods that
|
1
|
+
module Bootstrap3Helper # :nodoc
|
2
|
+
# This super class is meant to contain commonly used methods that
|
7
3
|
# all sub classes can leverage.
|
8
4
|
#
|
9
|
-
# @note
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
# in the template.
|
5
|
+
# @note Every component that inherits from this class, needs to call the parent
|
6
|
+
# initialization method! In order to properly render erb blocks within the
|
7
|
+
# proper context, we need the template. The only way to get this, is to pass
|
8
|
+
# in the template.
|
14
9
|
#
|
15
|
-
# @note
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# `@context` refers to the Bootstrap class context of the component.
|
10
|
+
# @note The `context` mentioned above, refers to the context of `@template` and
|
11
|
+
# not to be confused with `@context` that can be found in the sub classes.
|
12
|
+
# `@context` refers to the Bootstrap class context of the component.
|
19
13
|
#
|
20
14
|
class Component
|
21
|
-
#
|
22
|
-
# - Used to ensure that the helpers always have the propert context for
|
15
|
+
# Used to ensure that the helpers always have the propert context for
|
23
16
|
# rendering and bindings.
|
24
17
|
#
|
25
18
|
# @param [Class] template - the context of the bindings
|
@@ -28,8 +21,7 @@ module Bootstrap3Helper
|
|
28
21
|
@template = template
|
29
22
|
end
|
30
23
|
|
31
|
-
#
|
32
|
-
# - Used to pass all context of content_tag to the template. This ensures
|
24
|
+
# Used to pass all context of content_tag to the template. This ensures
|
33
25
|
# proper template binding of variables and methods!
|
34
26
|
#
|
35
27
|
# @return [String]
|
@@ -50,8 +42,7 @@ module Bootstrap3Helper
|
|
50
42
|
)
|
51
43
|
end
|
52
44
|
|
53
|
-
#
|
54
|
-
# - Used to pass all concat references to the template. This ensures proper
|
45
|
+
# Used to pass all concat references to the template. This ensures proper
|
55
46
|
# binding. Concat adds a String to the template Output buffer. Useful when
|
56
47
|
# trying to add a String with no block.
|
57
48
|
#
|
@@ -61,8 +52,7 @@ module Bootstrap3Helper
|
|
61
52
|
@template.concat(text)
|
62
53
|
end
|
63
54
|
|
64
|
-
#
|
65
|
-
# - Used to parse method arguments. If the first argument is
|
55
|
+
# Used to parse method arguments. If the first argument is
|
66
56
|
# a Hash, then it is assumed that the user left off the bootstrap
|
67
57
|
# contectual class. So we will assign it to `default` and
|
68
58
|
# return the Hash to be used as options.
|
@@ -80,8 +70,7 @@ module Bootstrap3Helper
|
|
80
70
|
end
|
81
71
|
end
|
82
72
|
|
83
|
-
#
|
84
|
-
# - Used to generate a (hopefully) unique ID for DOM elements. Used as a
|
73
|
+
# Used to generate a (hopefully) unique ID for DOM elements. Used as a
|
85
74
|
# fallback if the user doesn't specify one.
|
86
75
|
#
|
87
76
|
# @return [String]
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# @root
|
2
|
+
#
|
3
|
+
#
|
4
|
+
module Bootstrap3Helper
|
5
|
+
# @description
|
6
|
+
#
|
7
|
+
#
|
8
|
+
class Configuration
|
9
|
+
SETTINGS = %i[
|
10
|
+
autoload_in_all_views
|
11
|
+
].freeze
|
12
|
+
|
13
|
+
attr_accessor(*SETTINGS)
|
14
|
+
|
15
|
+
# @description
|
16
|
+
# -
|
17
|
+
#
|
18
|
+
# @params [Hash] args
|
19
|
+
# @return [ClassName]
|
20
|
+
#
|
21
|
+
def initialize(args = {})
|
22
|
+
@autoload_in_all_views = true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,11 +1,7 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
module Bootstrap3Helper
|
5
|
-
# @description
|
6
|
-
# - Used to rapidly build Bootstrap Panel Components.
|
1
|
+
module Bootstrap3Helper # :nodoc:
|
2
|
+
# Used to rapidly build Bootstrap Panel Components.
|
7
3
|
#
|
8
|
-
#
|
4
|
+
# @example Rendering a Bootstrap Panel Component in a view:
|
9
5
|
# <%= panel_helper class: 'panel-primary' do |p| %>
|
10
6
|
# <%= p.header { "Some Title" }
|
11
7
|
# <%= p.body class: 'custom-class', id: 'custom-id' do %>
|
@@ -15,88 +11,85 @@ module Bootstrap3Helper
|
|
15
11
|
# //HTML or Ruby
|
16
12
|
# <% end %>
|
17
13
|
# <% end %>
|
18
|
-
# </code>
|
19
14
|
#
|
20
15
|
class Panel < Component
|
21
|
-
#
|
22
|
-
# - Creates a new Panel object.
|
16
|
+
# Creates a new Panel object.
|
23
17
|
#
|
24
18
|
# @param [Class] template - Template in which your are binding too.
|
25
19
|
# @param [NilClass|String|Symbol|Hash] - Bootstrap class context, or options hash.
|
26
20
|
# @param [Hash] opts
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
# class: [String|NilClass] - Custom class for the element.
|
31
|
-
# }
|
32
|
-
# </code>
|
21
|
+
# @option opts [String] :id The ID of the element
|
22
|
+
# @option opts [String] :class Custom class for the component.
|
23
|
+
# @option opts [Hash] :data Any data attributes for the element.
|
33
24
|
# @return [Panel]
|
34
25
|
#
|
35
|
-
def initialize(template, context_or_options = nil, opts = {})
|
26
|
+
def initialize(template, context_or_options = nil, opts = {}, &block)
|
36
27
|
super(template)
|
37
28
|
@context, args = parse_arguments(context_or_options, opts)
|
38
29
|
|
39
30
|
@id = args.fetch(:id, '')
|
40
31
|
@class = args.fetch(:class, '')
|
41
32
|
@data = args.fetch(:data, nil)
|
33
|
+
@content = block || proc { '' }
|
42
34
|
end
|
43
35
|
|
44
|
-
#
|
45
|
-
# - Used to generate the header component for the panel.
|
36
|
+
# Used to generate the header component for the panel.
|
46
37
|
#
|
47
38
|
# @param [Hash] args
|
39
|
+
# @option args [String] :id The ID of the element
|
40
|
+
# @option args [String] :class Custom class for the component.
|
41
|
+
# @yieldreturn [String]
|
48
42
|
#
|
49
|
-
def header(args = {})
|
50
|
-
id
|
43
|
+
def header(args = {}, &block)
|
44
|
+
id = args.fetch(:id, '')
|
51
45
|
klass = args.fetch(:class, '')
|
52
|
-
|
53
|
-
|
46
|
+
|
47
|
+
content_tag(:div, id: id, class: 'panel-heading ' + klass) do
|
48
|
+
content_tag(:h3, class: 'panel-title', &block)
|
54
49
|
end
|
55
50
|
end
|
56
51
|
|
57
|
-
#
|
58
|
-
# - Used to generate the body component for the panel.
|
52
|
+
# Used to generate the body component for the panel.
|
59
53
|
#
|
60
54
|
# @param [Hash] args
|
55
|
+
# @option args [String] :id The ID of the element
|
56
|
+
# @option args [String] :class Custom class for the component.
|
57
|
+
# @yieldreturn [String]
|
61
58
|
#
|
62
|
-
def body(args = {})
|
63
|
-
id
|
59
|
+
def body(args = {}, &block)
|
60
|
+
id = args.fetch(:id, '')
|
64
61
|
klass = args.fetch(:class, '')
|
65
|
-
|
66
|
-
|
67
|
-
end
|
62
|
+
|
63
|
+
content_tag(:div, id: id, class: 'panel-body ' + klass, &block)
|
68
64
|
end
|
69
65
|
|
70
|
-
#
|
71
|
-
# - Used to generate the footer component for the panel.
|
66
|
+
# Used to generate the footer component for the panel.
|
72
67
|
#
|
73
68
|
# @param [Hash] args
|
69
|
+
# @option args [String] :id The ID of the element
|
70
|
+
# @option args [String] :class Custom class for the component.
|
71
|
+
# @yieldreturn [String]
|
74
72
|
#
|
75
|
-
def footer(args = {})
|
76
|
-
id
|
73
|
+
def footer(args = {}, &block)
|
74
|
+
id = args.fetch(:id, '')
|
77
75
|
klass = args.fetch(:class, '')
|
78
|
-
|
79
|
-
|
80
|
-
end
|
76
|
+
|
77
|
+
content_tag(:div, id: id, class: 'panel-footer ' + klass, &block)
|
81
78
|
end
|
82
79
|
|
83
|
-
#
|
84
|
-
# - Used to render the html for the entire panel object.
|
80
|
+
# Used to render the html for the entire panel object.
|
85
81
|
#
|
86
82
|
# @return [String]
|
87
83
|
#
|
88
84
|
def to_s
|
89
|
-
|
90
|
-
@
|
85
|
+
content_tag :div, id: @id, class: container_classes, data: @data do
|
86
|
+
@content.call(self)
|
91
87
|
end
|
92
|
-
|
93
|
-
content
|
94
88
|
end
|
95
89
|
|
96
90
|
private
|
97
91
|
|
98
|
-
#
|
99
|
-
# - Used to get the container css classes.
|
92
|
+
# Used to get the container css classes.
|
100
93
|
#
|
101
94
|
# @return [String]
|
102
95
|
#
|