class HashToHTMLList

Public Class Methods

new(hash) click to toggle source
# File lib/twb/hashtohtml.rb, line 2
def initialize(hash)
  @hash      = hash
  @indent    = "  "
  @tag_space = ""
  @level     = 0
  @out       = []
end

Public Instance Methods

append(tag,value=nil) click to toggle source
# File lib/twb/hashtohtml.rb, line 10
def append(tag,value=nil)
  str = @indent * @level + "#{tag}"
  str += @tag_space + value unless value.nil?
  str += "\n"
  @out << str
end
li(hash) click to toggle source
# File lib/twb/hashtohtml.rb, line 21
def li(hash)
  @level += 1
  hash.each do |key,value|
    open_tag('li',key) { ul(value) if value.is_a?(Hash) }
  end
  @level -= 1
end
list() click to toggle source
# File lib/twb/hashtohtml.rb, line 29
def list
  ul(@hash)
  @out.join
end
open_tag(tag,value=nil) { || ... } click to toggle source
# File lib/twb/hashtohtml.rb, line 34
def open_tag(tag,value=nil,&block)
  append("<#{tag}>",value)
  yield if block_given?
  append("</#{tag}>")
end
to_s() click to toggle source
# File lib/twb/util/hashtohtml.rb, line 41
def to_s
  @out
end
ul(hash) click to toggle source
# File lib/twb/hashtohtml.rb, line 17
def ul(hash)
  open_tag('ul') { li(hash) }
end