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

#autoObject

Turn on or off auto scrolling carousel



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

def auto
  options.fetch(:auto, true)
end

#component_familyObject



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

def component_family
  :carousel
end

#controlsObject



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

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

#dataObject



22
23
24
25
26
27
# File 'lib/nfg_ui/bootstrap/components/carousel.rb', line 22

def data
  # false on auto means that the carousel should not automatically rotate.
  data_val = auto == false ? { interval: 'false' } : { ride: 'carousel' }

  super.merge!(**data_val)
end

#indicatorsObject



29
30
31
# File 'lib/nfg_ui/bootstrap/components/carousel.rb', line 29

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

#renderObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/nfg_ui/bootstrap/components/carousel.rb', line 33

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