Class: Card::Bootstrap::Component::Carousel
Overview
support class for bootstrap carousels
Instance Method Summary
collapse
#append, #card, #initialize, #insert, #prepend, #render, #wrap
#def_div_method, #def_tag_method, #render
Methods included from Delegate
#method_missing, #respond_to_missing?
Methods included from BasicTags
#html
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Card::Bootstrap::Delegate
Instance Method Details
#carousel(id, active_index, &block) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/card/bootstrap/component/carousel.rb', line 10
def carousel id, active_index, &block
@id = id
@active_item_index = active_index
@items = []
instance_exec(&block)
@html.div class: "carousel slide", id: id, "data-bs-ride" => "true" do
indicators
items
control_prev
control_next
end
end
|
#carousel_item(item, html_opts) ⇒ Object
42
43
44
45
46
47
|
# File 'lib/card/bootstrap/component/carousel.rb', line 42
def carousel_item item, html_opts
@html.div html_opts do
item = item.call if item.respond_to?(:call)
@html << item if item.is_a?(String)
end
end
|
#carousel_item_opts(index) ⇒ Object
36
37
38
39
40
|
# File 'lib/card/bootstrap/component/carousel.rb', line 36
def carousel_item_opts index
{ class: "carousel-item" }.tap do |opts|
add_class opts, "active" if index == @active_item_index
end
end
|
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/card/bootstrap/component/carousel.rb', line 57
def control_button direction, description
@html.button class: "carousel-control-#{direction}",
"data-bs-target": "##{@id}", type: "button" do
@html.span class: "carousel-control-#{direction}-icon",
"aria-hidden": "true" do
""
end
@html.span description, class: "visually-hidden"
end
end
|
#control_next ⇒ Object
53
54
55
|
# File 'lib/card/bootstrap/component/carousel.rb', line 53
def control_next
control_button :next, "Next"
end
|
#control_prev ⇒ Object
49
50
51
|
# File 'lib/card/bootstrap/component/carousel.rb', line 49
def control_prev
control_button :prev, "Previous"
end
|
#indicator(index) ⇒ Object
74
75
76
77
78
79
|
# File 'lib/card/bootstrap/component/carousel.rb', line 74
def indicator index
html_opts = { "data-bs-slide-to": index, "data-bs-target": "##{@id}",
type: "button", "aria-label": "Slide #{index + 1}" }
add_class html_opts, "active" if index == @active_item_index
@html.button html_opts
end
|
#indicators ⇒ Object
68
69
70
71
72
|
# File 'lib/card/bootstrap/component/carousel.rb', line 68
def indicators
@html.div class: "carousel-indicators" do
@items.size.times { |i| indicator i }
end
end
|
#item(content = nil, &block) ⇒ Object
24
25
26
|
# File 'lib/card/bootstrap/component/carousel.rb', line 24
def item content=nil, &block
@items << (content || block)
end
|
#items ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/card/bootstrap/component/carousel.rb', line 28
def items
@html.div class: "carousel-inner" do
@items.each_with_index do |item, index|
carousel_item item, carousel_item_opts(index)
end
end
end
|
#render_content ⇒ Object
6
7
8
|
# File 'lib/card/bootstrap/component/carousel.rb', line 6
def render_content
carousel(*@args, &@build_block)
end
|