Class: Coradoc::Element::List::Core
- Defined in:
- lib/coradoc/element/list/core.rb
Instance Attribute Summary collapse
-
#anchor ⇒ Object
Returns the value of attribute anchor.
-
#id ⇒ Object
Returns the value of attribute id.
-
#items ⇒ Object
Returns the value of attribute items.
-
#ol_count ⇒ Object
Returns the value of attribute ol_count.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
Instance Method Summary collapse
-
#initialize(items, options = {}) ⇒ Core
constructor
A new instance of Core.
- #to_adoc ⇒ Object
Methods inherited from Base
access_children, #children_accessors, children_accessors, declare_children, #simplify_block_content, visit, #visit
Constructor Details
#initialize(items, options = {}) ⇒ Core
Returns a new instance of Core.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/coradoc/element/list/core.rb', line 12 def initialize(items, = {}) @items = items @items = [@items] unless @items.is_a?(Array) @id = .fetch(:id, nil) @anchor = @id.nil? ? nil : Inline::Anchor.new(@id) @ol_count = .fetch(:ol_count, nil) if @ol_count.nil? m = @items.find do |i| i.is_a?(Coradoc::Element::ListItem) && !i.marker.nil? end&.marker.to_s @ol_count = m.size end @ol_count = 1 if @ol_count.nil? @attrs = .fetch(:attrs, AttributeList.new) end |
Instance Attribute Details
#anchor ⇒ Object
Returns the value of attribute anchor.
8 9 10 |
# File 'lib/coradoc/element/list/core.rb', line 8 def anchor @anchor end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/coradoc/element/list/core.rb', line 8 def id @id end |
#items ⇒ Object
Returns the value of attribute items.
8 9 10 |
# File 'lib/coradoc/element/list/core.rb', line 8 def items @items end |
#ol_count ⇒ Object
Returns the value of attribute ol_count.
8 9 10 |
# File 'lib/coradoc/element/list/core.rb', line 8 def ol_count @ol_count end |
#prefix ⇒ Object
Returns the value of attribute prefix.
8 9 10 |
# File 'lib/coradoc/element/list/core.rb', line 8 def prefix @prefix end |
Instance Method Details
#to_adoc ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/coradoc/element/list/core.rb', line 29 def to_adoc anchor = @anchor.nil? ? "" : @anchor.to_adoc.to_s attrs = @attrs.to_adoc(false).to_s content = "\n" @items.each do |item| c = Coradoc::Generator.gen_adoc(item) if !c.empty? # If there's a list inside a list directly, we want to # skip adding an empty list item. # See: https://github.com/metanorma/coradoc/issues/96 unless item.is_a? List::Core content << prefix.to_s content << " " if c[0] != " " end content << c end end "\n#{anchor}#{attrs}" + content end |