Class: Coradoc::Element::ListItem
- Defined in:
- lib/coradoc/element/list_item.rb
Instance Attribute Summary collapse
-
#anchor ⇒ Object
Returns the value of attribute anchor.
-
#content ⇒ Object
Returns the value of attribute content.
-
#id ⇒ Object
Returns the value of attribute id.
-
#line_break ⇒ Object
Returns the value of attribute line_break.
-
#marker ⇒ Object
Returns the value of attribute marker.
-
#subitem ⇒ Object
Returns the value of attribute subitem.
Instance Method Summary collapse
-
#initialize(content, options = {}) ⇒ ListItem
constructor
A new instance of ListItem.
- #to_adoc ⇒ Object
Methods inherited from Base
children_accessors, #children_accessors, declare_children, #simplify_block_content, visit, #visit
Constructor Details
#initialize(content, options = {}) ⇒ ListItem
Returns a new instance of ListItem.
8 9 10 11 12 13 14 15 16 |
# File 'lib/coradoc/element/list_item.rb', line 8 def initialize(content, = {}) @marker = .fetch(:marker, nil) @id = .fetch(:id, nil) @anchor = @id.nil? ? nil : Inline::Anchor.new(@id) @content = content @attached = .fetch(:attached, []) @nested = .fetch(:nested, nil) @line_break = .fetch(:line_break, "\n") end |
Instance Attribute Details
#anchor ⇒ Object
Returns the value of attribute anchor.
4 5 6 |
# File 'lib/coradoc/element/list_item.rb', line 4 def anchor @anchor end |
#content ⇒ Object
Returns the value of attribute content.
4 5 6 |
# File 'lib/coradoc/element/list_item.rb', line 4 def content @content end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/coradoc/element/list_item.rb', line 4 def id @id end |
#line_break ⇒ Object
Returns the value of attribute line_break.
4 5 6 |
# File 'lib/coradoc/element/list_item.rb', line 4 def line_break @line_break end |
#marker ⇒ Object
Returns the value of attribute marker.
4 5 6 |
# File 'lib/coradoc/element/list_item.rb', line 4 def marker @marker end |
#subitem ⇒ Object
Returns the value of attribute subitem.
4 5 6 |
# File 'lib/coradoc/element/list_item.rb', line 4 def subitem @subitem end |
Instance Method Details
#to_adoc ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/coradoc/element/list_item.rb', line 18 def to_adoc anchor = @anchor.nil? ? "" : " #{@anchor.to_adoc.to_s} " # text = Coradoc::Generator.gen_adoc(@content) content = Array(@content).map do |subitem| next if subitem.is_a? Inline::HardLineBreak subcontent = Coradoc::Generator.gen_adoc(subitem) # Only try to postprocess elements that are text, # otherwise we could strip markup. if Coradoc.a_single?(subitem, Coradoc::Element::TextElement) subcontent = Coradoc.strip_unicode(subcontent) end subcontent end.compact.join("\n+\n") # attach = Coradoc::Generator.gen_adoc(@attached) attach = @attached.map do |elem| "+\n" + Coradoc::Generator.gen_adoc(elem) end.join nest = Coradoc::Generator.gen_adoc(@nested) out = " #{anchor}#{content}#{@line_break}" out + attach + nest end |