Class: Opmac2html::ListBuilder
- Inherits:
-
Object
- Object
- Opmac2html::ListBuilder
- Defined in:
- lib/opmac2html/list_builder.rb
Overview
Builder for lists (items)
Instance Method Summary collapse
- #add_item(text, id = nil) ⇒ Object
- #begitems(style) ⇒ Object
- #end_tag ⇒ Object
- #enditems ⇒ Object
- #get_type(style) ⇒ Object
-
#initialize(style) ⇒ ListBuilder
constructor
A new instance of ListBuilder.
- #start_tag(text) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(style) ⇒ ListBuilder
Returns a new instance of ListBuilder.
4 5 6 7 8 |
# File 'lib/opmac2html/list_builder.rb', line 4 def initialize(style) @list = [] @list_stack = [] begitems style end |
Instance Method Details
#add_item(text, id = nil) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# 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) ⇒ Object
30 31 32 33 |
# File 'lib/opmac2html/list_builder.rb', line 30 def begitems(style) start_tag get_type style @first = true end |
#end_tag ⇒ Object
26 27 28 |
# File 'lib/opmac2html/list_builder.rb', line 26 def end_tag @list << "</#{@list_stack.pop}>\n" end |
#enditems ⇒ Object
35 36 37 |
# File 'lib/opmac2html/list_builder.rb', line 35 def enditems 2.times { end_tag } end |
#get_type(style) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# 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) ⇒ Object
21 22 23 24 |
# File 'lib/opmac2html/list_builder.rb', line 21 def start_tag(text) @list << "<#{text}>\n" @list_stack << text.partition(' ')[0] end |
#to_s ⇒ Object
49 50 51 52 |
# File 'lib/opmac2html/list_builder.rb', line 49 def to_s enditems until @list_stack.empty? @list.join end |