class Card::Tab

Attributes

button_attrib[R]
content[R]
format[R]
label[R]
name[R]

Public Class Methods

new(format, name, active_name, config) click to toggle source
# File lib/card/tab.rb, line 24
def initialize format, name, active_name, config
  @format = format
  @name = name
  @active_name = active_name
  @config = config
end
tab_objects(format, tab_hash, active_name, klass=nil) click to toggle source
# File lib/card/tab.rb, line 6
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

Private Class Methods

active(requested, keys) click to toggle source
# File lib/card/tab.rb, line 16
def active requested, keys
  r = requested.to_name
  r && keys.find { |k| k.to_name == r } || keys.first
end

Public Instance Methods

tab_button() click to toggle source
# File lib/card/tab.rb, line 31
def tab_button
  add_class button_attrib, "active" if active?
  wrap_with :li, tab_button_link,
            role: :presentation,
            class: "nav-item tab-li-#{name}"
end
tab_pane(args=nil) click to toggle source
# File lib/card/tab.rb, line 38
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

Private Instance Methods

active?() click to toggle source
# File lib/card/tab.rb, line 79
def active?
  name == @active_name
end
config_hash?() click to toggle source
# File lib/card/tab.rb, line 48
def config_hash?
  @config.is_a? Hash
end
tab_id() click to toggle source
# File lib/card/tab.rb, line 75
def tab_id
  @tab_id ||= "#{unique_id}-#{name.to_name.safe_key}"
end