Class: HtmlCom::Tabs

Inherits:
Object
  • Object
show all
Defined in:
lib/htmlcom.rb

Defined Under Namespace

Classes: Tab

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type = :tabs, headings: %w(tab1 tab2 tab3))) ⇒ Tabs

current options for type:

:tabs, :full_page_tabs


48
49
50
51
52
53
54
55
56
57
# File 'lib/htmlcom.rb', line 48

def initialize(type=:tabs, headings: %w(tab1 tab2 tab3))

  @type = type
  @build = JsMenuBuilder.new(type, headings: headings)

  @tab = headings.map do |heading|
    Tab.new heading, content: "<h3>#{heading}</h3>", callback: self
  end

end

Instance Attribute Details

#activeObject

Returns the value of attribute active.



43
44
45
# File 'lib/htmlcom.rb', line 43

def active
  @active
end

#tabObject (readonly)

Returns the value of attribute tab.



43
44
45
# File 'lib/htmlcom.rb', line 43

def tab
  @tab
end

Instance Method Details

#add_tab(title, content: '', index: nil) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/htmlcom.rb', line 64

def add_tab(title, content: '', index: nil)

  tab = Tab.new(title, content: content)

  if index then
    @tab.insert index, tab
  else
    @tab << tab
  end

  refresh()

end

#delete_tab(i) ⇒ Object



78
79
80
81
# File 'lib/htmlcom.rb', line 78

def delete_tab(i)
  @tab.delete i
  refresh()
end

#pingObject Also known as: refresh



83
84
85
86
87
88
89
90
91
# File 'lib/htmlcom.rb', line 83

def ping()

  tabs = @tab.map do |tab|
    tab.title ? tab.to_a : nil
  end.compact.to_h

  @build = JsMenuBuilder.new(@type, tabs: tabs, active: @active_tab)

end

#to_htmlObject



95
96
97
# File 'lib/htmlcom.rb', line 95

def to_html()
  @build.to_html
end

#to_webpageObject



99
100
101
# File 'lib/htmlcom.rb', line 99

def to_webpage()
  @build.to_webpage
end