class Opmac2html::ListBuilder
Builder for lists (items)
Public Class Methods
new(style)
click to toggle source
# File lib/opmac2html/list_builder.rb, line 4 def initialize(style) @list = [] @list_stack = [] begitems style end
Public Instance Methods
add_item(text, id = nil)
click to toggle source
# File lib/opmac2html/list_builder.rb, line 39 def add_item(text, id = nil) if @first @first = false else end_tag end start_tag(id ? "li id=\"#{id}\"" : 'li') @list << text end
begitems(style)
click to toggle source
# File lib/opmac2html/list_builder.rb, line 30 def begitems(style) start_tag get_type style @first = true end
end_tag()
click to toggle source
# File lib/opmac2html/list_builder.rb, line 26 def end_tag @list << "</#{@list_stack.pop}>\n" end
enditems()
click to toggle source
# File lib/opmac2html/list_builder.rb, line 35 def enditems 2.times { end_tag } end
get_type(style)
click to toggle source
# File lib/opmac2html/list_builder.rb, line 10 def get_type(style) case style when 'n', 'N' 'ol type="1"' when 'i', 'I', 'a', 'A' "ol type=\"#{style}\"" else 'ul' end end
start_tag(text)
click to toggle source
# File lib/opmac2html/list_builder.rb, line 21 def start_tag(text) @list << "<#{text}>\n" @list_stack << text.partition(' ')[0] end
to_s()
click to toggle source
# File lib/opmac2html/list_builder.rb, line 49 def to_s enditems until @list_stack.empty? @list.join end