Sha256: faedfeb5981ea47d427efea11d6e1fe92c71069f268dbe01a0e8b200b23303ce
Contents?: true
Size: 1.93 KB
Versions: 50
Compression:
Stored size: 1.93 KB
Contents
class Bootstrap class Component class Carousel < Component def render_content carousel *@args, &@build_block end 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-ride" => "carousel" do indicators items control_prev control_next end end def item content=nil, &block @items << (content || block) end def items @html.div class: "carousel-inner", role: "listbox" do @items.each_with_index do |item, index| html_opts = { class: "carousel-item" } add_class html_opts, "active" if index == @active_item_index @html.div html_opts do item = item.call if item.respond_to?(:call) @html << item if item.is_a?(String) end end end end def control_prev @html.a class: "carousel-control-prev", href: "##{@id}", role: "button", "data-slide" => "prev" do @html.span class: "carousel-control-prev-icon", "aria-hidden" => "true" @html.span "Previous", class: "sr-only" end end def control_next @html.a class: "carousel-control-next", href: "##{@id}", role: "button", "data-slide": "next" do @html.span class: "carousel-control-next-icon", "aria-hidden" => "true" @html.span "Next", class: "sr-only" end end def indicators @html.ol class: "carousel-indicators" do @items.size.times { |i| indicator i } end end def indicator index html_opts = { "data-slide-to" => index, "data-target": "##{@id}" } add_class html_opts, "active" if index == @active_item_index @html.li html_opts end end end end
Version data entries
50 entries across 50 versions & 2 rubygems