Class: Trestle::Tab

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TagHelper
Defined in:
lib/trestle/tab.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, **options) ⇒ Tab

Returns a new instance of Tab.



9
10
11
# File 'lib/trestle/tab.rb', line 9

def initialize(name, **options)
  @name, @options = name, options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/trestle/tab.rb', line 7

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/trestle/tab.rb', line 7

def options
  @options
end

Instance Method Details

#badgeObject



21
22
23
# File 'lib/trestle/tab.rb', line 21

def badge
  tag.span(options[:badge], class: "badge") if options[:badge]
end

#id(tag = nil) ⇒ Object



13
14
15
# File 'lib/trestle/tab.rb', line 13

def id(tag=nil)
  ["tab", tag, name].compact.join("-")
end

#labelObject



17
18
19
# File 'lib/trestle/tab.rb', line 17

def label
  safe_join([options[:label] || I18n.t("admin.tabs.#{name}", default: name.to_s.titleize), badge].compact, " ")
end