Class: NfgUi::Bootstrap::Components::Carousel

Inherits:
Base
  • Object
show all
Defined in:
lib/nfg_ui/bootstrap/components/carousel.rb

Overview

Bootstrap Carousel Component getbootstrap.com/docs/4.1/components/carousel/

Direct Known Subclasses

Components::Patterns::Carousel

Instance Attribute Summary

Attributes inherited from Base

#body, #options, #view_context

Instance Method Summary collapse

Methods inherited from Base

#href, #html_options, #id, #initialize, #style

Constructor Details

This class inherits a constructor from NfgUi::Bootstrap::Components::Base

Instance Method Details

#component_familyObject



9
10
11
# File 'lib/nfg_ui/bootstrap/components/carousel.rb', line 9

def component_family
  :carousel
end

#controlsObject



13
14
15
# File 'lib/nfg_ui/bootstrap/components/carousel.rb', line 13

def controls
  options.fetch(:controls, false)
end

#dataObject



17
18
19
# File 'lib/nfg_ui/bootstrap/components/carousel.rb', line 17

def data
  super.merge!(ride: 'carousel')
end

#indicatorsObject



21
22
23
# File 'lib/nfg_ui/bootstrap/components/carousel.rb', line 21

def indicators
  options[:indicators] || 0 # return 0 on nil
end

#renderObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/nfg_ui/bootstrap/components/carousel.rb', line 25

def render
  super do
    capture do
      (:div, class: 'carousel-inner') do
        if indicators > 0
          concat(NfgUi::Bootstrap::Components::CarouselIndicators.new({ count: indicators, carousel: "##{id}" }, view_context).render)
        end
        concat(block_given? ? yield : body)
        if controls
          concat(NfgUi::Bootstrap::Components::CarouselControl.new({ control: :next, carousel: "##{id}" }, view_context).render)
          concat(NfgUi::Bootstrap::Components::CarouselControl.new({ control: :prev, carousel: "##{id}" }, view_context).render)
        end
      end
    end
  end
end