Class: Marker::ItemBuilder
- Inherits:
-
Object
- Object
- Marker::ItemBuilder
- Defined in:
- lib/marker/lists.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#sublists ⇒ Object
readonly
Returns the value of attribute sublists.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #can_merge?(other) ⇒ Boolean
-
#initialize(type, content_or_sublist) ⇒ ItemBuilder
constructor
A new instance of ItemBuilder.
- #merge!(item) ⇒ Object
- #to_html(options = {}) ⇒ Object
- #to_s(options = {}) ⇒ Object
Constructor Details
#initialize(type, content_or_sublist) ⇒ ItemBuilder
Returns a new instance of ItemBuilder.
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/marker/lists.rb', line 78 def initialize( type, content_or_sublist ) @type = type if content_or_sublist.respond_to? :items @content = nil @sublists = ListBuilder.new(:sublist, content_or_sublist) else @content = content_or_sublist @sublists = ListBuilder.new(:sublist) end end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
75 76 77 |
# File 'lib/marker/lists.rb', line 75 def content @content end |
#sublists ⇒ Object (readonly)
Returns the value of attribute sublists.
76 77 78 |
# File 'lib/marker/lists.rb', line 76 def sublists @sublists end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
74 75 76 |
# File 'lib/marker/lists.rb', line 74 def type @type end |
Instance Method Details
#can_merge?(other) ⇒ Boolean
90 91 92 |
# File 'lib/marker/lists.rb', line 90 def can_merge?( other ) other.content.nil? end |
#merge!(item) ⇒ Object
94 95 96 |
# File 'lib/marker/lists.rb', line 94 def merge!( item ) sublists.merge! item.sublists end |
#to_html(options = {}) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/marker/lists.rb', line 98 def to_html( ={} ) case type when :bulleted, :numbered "<li>" + ( content ? content.to_html() : "" ) + sublists.to_html() + "</li>" when :indented "<div class='indented_item'>" + ( content ? content.to_html() : "" ) + sublists.to_html() + "</div>" when :definition if content term, definition = content "<dt>#{term.to_html()}</dt><dd>#{definition.to_html()}#{sublists.to_html()}</dd>" else "<dd>#{sublists.to_html()}</dd>" end end end |
#to_s(options = {}) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/marker/lists.rb', line 120 def to_s( ={} ) if content indent = ' ' * [:indent] item_str = case type when :bulleted ' * ' + content.to_s() when :numbered "#{'%2d' % ([:num]+1)}. " + content.to_s() when :indented ' ' + content.to_s() when :definition term, definition = content ' ' + term.to_s() + ( definition ? ' :: ' + definition.to_s() : '' ) end sublist_str = ( sublists.empty? ? '' : "\n#{sublists.to_s()}" ) "#{indent}#{item_str}#{sublist_str}" else sublists.to_s() end end |