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


159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/htmlcom.rb', line 159

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.



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

def active
  @active
end

#tabObject (readonly)

Returns the value of attribute tab.



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

def tab
  @tab
end

Instance Method Details

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



179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/htmlcom.rb', line 179

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



193
194
195
196
# File 'lib/htmlcom.rb', line 193

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

#pingObject Also known as: refresh



198
199
200
201
202
203
204
205
206
# File 'lib/htmlcom.rb', line 198

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



216
217
218
219
# File 'lib/htmlcom.rb', line 216

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

#to_htmlObject



210
211
212
# File 'lib/htmlcom.rb', line 210

def to_html()
  @build.to_html
end

#to_webpageObject



221
222
223
# File 'lib/htmlcom.rb', line 221

def to_webpage()
  @build.to_webpage
end