Class: Card::Tab

Inherits:
Object show all
Defined in:
mod/tabs/lib/card/tab.rb

Overview

tab object, handles tab configuration for view :tabs

Direct Known Subclasses

LazyTab

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format, name, active_name, config) ⇒ Tab

Returns a new instance of Tab.



25
26
27
28
29
30
# File 'mod/tabs/lib/card/tab.rb', line 25

def initialize format, name, active_name, config
  @format = format
  @name = name
  @active_name = active_name
  @config = config
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



4
5
6
# File 'mod/tabs/lib/card/tab.rb', line 4

def format
  @format
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'mod/tabs/lib/card/tab.rb', line 4

def name
  @name
end

Class Method Details

.tab_objects(format, tab_hash, active_name, klass = nil) ⇒ Object



7
8
9
10
11
12
13
# File 'mod/tabs/lib/card/tab.rb', line 7

def tab_objects format, tab_hash, active_name, klass=nil
  klass ||= Card::Tab
  active_name = active active_name, tab_hash.keys
  tab_hash.map do |name, config|
    klass.new format, name, active_name, config
  end
end

Instance Method Details

#button_attribObject



47
48
49
# File 'mod/tabs/lib/card/tab.rb', line 47

def button_attrib
  @button_attrib ||= (config_hash? && @config[:button_attr]) || {}
end

#contentObject



51
52
53
# File 'mod/tabs/lib/card/tab.rb', line 51

def content
  @content ||= config_hash? ? @config[:content] : @config
end

#labelObject



55
56
57
# File 'mod/tabs/lib/card/tab.rb', line 55

def label
  @label ||= (config_hash? && @config[:title]) || name
end

#tab_buttonObject



32
33
34
35
36
37
# File 'mod/tabs/lib/card/tab.rb', line 32

def tab_button
  add_class button_attrib, "active" if active?
  wrap_with :li, tab_button_link,
            role: :presentation,
            class: "nav-item tab-li-#{name.to_name.key}"
end

#tab_pane(args = nil) ⇒ Object



39
40
41
42
43
44
45
# File 'mod/tabs/lib/card/tab.rb', line 39

def tab_pane args=nil
  pane_attr = { role: :tabpanel, id: tab_id }
  pane_attr.merge! args if args.present?
  add_class pane_attr, "tab-pane tab-pane-#{name}"
  add_class pane_attr, "active" if active?
  wrap_with :div, content, pane_attr
end