Class: Coradoc::Element::Section
- Defined in:
- lib/coradoc/element/section.rb
Instance Attribute Summary collapse
-
#anchor ⇒ Object
Returns the value of attribute anchor.
-
#attrs ⇒ Object
Returns the value of attribute attrs.
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#id ⇒ Object
Returns the value of attribute id.
-
#sections ⇒ Object
Returns the value of attribute sections.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #content ⇒ Object
- #glossaries ⇒ Object
-
#initialize(title, options = {}) ⇒ Section
constructor
A new instance of Section.
-
#safe_to_collapse? ⇒ Boolean
Check for cases when Section is simply an equivalent of an empty <DIV> HTML element and if it happens inside some other block element, can be safely collapsed.
- #to_adoc ⇒ Object
Methods inherited from Base
#children_accessors, children_accessors, declare_children, #simplify_block_content, visit, #visit
Constructor Details
#initialize(title, options = {}) ⇒ Section
Returns a new instance of Section.
8 9 10 11 12 13 14 15 16 |
# File 'lib/coradoc/element/section.rb', line 8 def initialize(title, = {}) @title = title @id = .fetch(:id, nil) @id = nil if @id == "" @anchor = @id.nil? ? nil : Inline::Anchor.new(@id) @attrs = .fetch(:attribute_list, "") @contents = .fetch(:contents, []) @sections = .fetch(:sections, []) end |
Instance Attribute Details
#anchor ⇒ Object
Returns the value of attribute anchor.
4 5 6 |
# File 'lib/coradoc/element/section.rb', line 4 def anchor @anchor end |
#attrs ⇒ Object
Returns the value of attribute attrs.
4 5 6 |
# File 'lib/coradoc/element/section.rb', line 4 def attrs @attrs end |
#contents ⇒ Object
Returns the value of attribute contents.
4 5 6 |
# File 'lib/coradoc/element/section.rb', line 4 def contents @contents end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/coradoc/element/section.rb', line 4 def id @id end |
#sections ⇒ Object
Returns the value of attribute sections.
4 5 6 |
# File 'lib/coradoc/element/section.rb', line 4 def sections @sections end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/coradoc/element/section.rb', line 4 def title @title end |
Instance Method Details
#content ⇒ Object
22 23 24 25 26 |
# File 'lib/coradoc/element/section.rb', line 22 def content if contents.count == 1 && contents.first.is_a?(Coradoc::Element::Paragraph) contents.first end end |
#glossaries ⇒ Object
18 19 20 |
# File 'lib/coradoc/element/section.rb', line 18 def glossaries @glossaries ||= extract_glossaries end |
#safe_to_collapse? ⇒ Boolean
Check for cases when Section is simply an equivalent of an empty <DIV> HTML element and if it happens inside some other block element, can be safely collapsed.
51 52 53 |
# File 'lib/coradoc/element/section.rb', line 51 def safe_to_collapse? @title.nil? && @sections.empty? end |
#to_adoc ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/coradoc/element/section.rb', line 28 def to_adoc anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n" title = Coradoc::Generator.gen_adoc(@title) attrs = @attrs.to_s.empty? ? "" : "#{@attrs.to_adoc}\n" content = Coradoc::Generator.gen_adoc(@contents) sections = Coradoc::Generator.gen_adoc(@sections) # A block of " +\n"s isn't parsed correctly. It needs to start # with something. content = " #{content}" if content.start_with?(" +\n") # Only try to postprocess elements that are text, # otherwise we could strip markup. if Coradoc.a_single?(@contents, Coradoc::Element::TextElement) content = Coradoc.strip_unicode(content) end "\n#{anchor}" << attrs << title << content << sections << "\n" end |