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: [], xml: nil) ⇒ Tabs

current options for type:

:tabs, :full_page_tabs


121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/htmlcom.rb', line 121

def initialize(type=:tabs, headings: [], xml: nil)

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

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

  if xml then
    @build.import(xml)
  end

end

Instance Attribute Details

#activeObject

Returns the value of attribute active.



116
117
118
# File 'lib/htmlcom.rb', line 116

def active
  @active
end

#tabObject (readonly)

Returns the value of attribute tab.



116
117
118
# File 'lib/htmlcom.rb', line 116

def tab
  @tab
end

Instance Method Details

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



141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/htmlcom.rb', line 141

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



155
156
157
158
# File 'lib/htmlcom.rb', line 155

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

#pingObject Also known as: refresh



160
161
162
163
164
165
166
167
168
# File 'lib/htmlcom.rb', line 160

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_bangtagObject

not yet working properly



178
179
180
181
# File 'lib/htmlcom.rb', line 178

def to_bangtag()
  XmlToSliml.new(@build.to_xml, spacer: '!')\
      .to_s.lines.map {|x| '!' + x }.join
end

#to_htmlObject



172
173
174
# File 'lib/htmlcom.rb', line 172

def to_html()
  @build.to_html
end

#to_webpageObject



183
184
185
# File 'lib/htmlcom.rb', line 183

def to_webpage()
  @build.to_webpage
end