Class: HtmlCom::Tabs
- Inherits:
-
Object
- Object
- HtmlCom::Tabs
- Defined in:
- lib/htmlcom.rb
Defined Under Namespace
Classes: Tab
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
-
#tab ⇒ Object
readonly
Returns the value of attribute tab.
Instance Method Summary collapse
- #add_tab(title, content: '', index: nil) ⇒ Object
- #delete_tab(i) ⇒ Object
-
#initialize(type = :tabs, headings: %w(tab1 tab2 tab3))) ⇒ Tabs
constructor
current options for type: :tabs, :full_page_tabs.
- #ping ⇒ Object (also: #refresh)
- #to_html ⇒ Object
- #to_webpage ⇒ Object
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
#active ⇒ Object
Returns the value of attribute active.
43 44 45 |
# File 'lib/htmlcom.rb', line 43 def active @active end |
#tab ⇒ Object (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 |
#ping ⇒ Object 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_html ⇒ Object
95 96 97 |
# File 'lib/htmlcom.rb', line 95 def to_html() @build.to_html end |
#to_webpage ⇒ Object
99 100 101 |
# File 'lib/htmlcom.rb', line 99 def to_webpage() @build.to_webpage end |