Class: LesliView::Components::Tabs::TabComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
lib/lesli_view/components/tabs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, title: nil, icon: nil) ⇒ TabComponent

Returns a new instance of TabComponent.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/lesli_view/components/tabs.rb', line 29

def initialize(id:nil, title: nil, icon: nil)

    @tab_id = nil

    if title 
        @tab_id = title
        .downcase                           # string to lowercase
        .gsub(/[^0-9A-Za-z\s\-\_]/, '')     # remove special characters from string
        .gsub(/_/, '-')                     # replace underscores with dashes 
        .gsub(/\s+/, '-')                   # replace spaces or spaces with single dash
    end

    if id 
        @tab_id = id
    end 

    @title = title
    @icon = icon
end

Instance Attribute Details

#iconObject (readonly)

Returns the value of attribute icon.



27
28
29
# File 'lib/lesli_view/components/tabs.rb', line 27

def icon
  @icon
end

#tab_idObject (readonly)

Returns the value of attribute tab_id.



27
28
29
# File 'lib/lesli_view/components/tabs.rb', line 27

def tab_id
  @tab_id
end

#titleObject (readonly)

Returns the value of attribute title.



27
28
29
# File 'lib/lesli_view/components/tabs.rb', line 27

def title
  @title
end

Instance Method Details

#callObject



53
54
55
# File 'lib/lesli_view/components/tabs.rb', line 53

def call
     :div, content
end

#set_tab_id(tab_id, index) ⇒ Object



49
50
51
# File 'lib/lesli_view/components/tabs.rb', line 49

def set_tab_id(tab_id, index)
    @tab_id = tab_id || "tab-#{index}"
end