Class: Coradoc::AsciiDoc::Model::Title
- Includes:
- Anchorable
- Defined in:
- lib/coradoc/asciidoc/model/title.rb
Overview
Title element for sections and document headers.
Represents a title with optional level information. Titles are used by sections to define their heading level and text content.
Instance Attribute Summary collapse
-
#content ⇒ Array<TextElement>
(also: #text)
readonly
Title text content (can include inline formatting).
-
#id ⇒ String?
readonly
Optional identifier for the title.
-
#level_int ⇒ Integer?
readonly
Heading level (0-5 for standard, 6+ uses style attribute).
-
#line_break ⇒ String
readonly
Line break character after title (default: newline).
-
#style ⇒ String?
readonly
Optional style attribute for title formatting.
Instance Method Summary collapse
- #level_str ⇒ Object
- #style_str ⇒ Object
-
#to_s ⇒ String
Convert title content to string.
Methods included from Anchorable
#default_anchor, #gen_anchor, included, #initialize
Methods inherited from Base
#block_level?, #inline?, #serialize_content, #simplify_block_content, #to_adoc, #to_h, visit, #visit
Instance Attribute Details
#content ⇒ Array<TextElement> (readonly) Also known as: text
Returns Title text content (can include inline formatting).
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/coradoc/asciidoc/model/title.rb', line 36 class Title < Base include Coradoc::AsciiDoc::Model::Anchorable attribute :id, :string attribute :content, Coradoc::AsciiDoc::Model::TextElement, collection: true # attribute :level, :string attribute :level_int, :integer attribute :line_break, :string, default: -> { "\n" } attribute :style, :string alias text content # Convert title content to string # @return [String] The title text def to_s case content when String content when Array content.map do |item| item.is_a?(Coradoc::AsciiDoc::Model::TextElement) ? item.content.to_s : item.to_s end.join else content.to_s end end def level_str return '' if level_int.nil? if level_int <= 5 '=' * (level_int + 1) else '======' end end def style_str return '' if level_int.nil? _style = [style] _style << "level=#{level_int}" if level_int > 5 _style = _style.compact.join(',') _style.empty? ? '' : "[#{_style}]\n" end end |
#id ⇒ String? (readonly)
Returns Optional identifier for the title.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/coradoc/asciidoc/model/title.rb', line 36 class Title < Base include Coradoc::AsciiDoc::Model::Anchorable attribute :id, :string attribute :content, Coradoc::AsciiDoc::Model::TextElement, collection: true # attribute :level, :string attribute :level_int, :integer attribute :line_break, :string, default: -> { "\n" } attribute :style, :string alias text content # Convert title content to string # @return [String] The title text def to_s case content when String content when Array content.map do |item| item.is_a?(Coradoc::AsciiDoc::Model::TextElement) ? item.content.to_s : item.to_s end.join else content.to_s end end def level_str return '' if level_int.nil? if level_int <= 5 '=' * (level_int + 1) else '======' end end def style_str return '' if level_int.nil? _style = [style] _style << "level=#{level_int}" if level_int > 5 _style = _style.compact.join(',') _style.empty? ? '' : "[#{_style}]\n" end end |
#level_int ⇒ Integer? (readonly)
Returns Heading level (0-5 for standard, 6+ uses style attribute).
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/coradoc/asciidoc/model/title.rb', line 36 class Title < Base include Coradoc::AsciiDoc::Model::Anchorable attribute :id, :string attribute :content, Coradoc::AsciiDoc::Model::TextElement, collection: true # attribute :level, :string attribute :level_int, :integer attribute :line_break, :string, default: -> { "\n" } attribute :style, :string alias text content # Convert title content to string # @return [String] The title text def to_s case content when String content when Array content.map do |item| item.is_a?(Coradoc::AsciiDoc::Model::TextElement) ? item.content.to_s : item.to_s end.join else content.to_s end end def level_str return '' if level_int.nil? if level_int <= 5 '=' * (level_int + 1) else '======' end end def style_str return '' if level_int.nil? _style = [style] _style << "level=#{level_int}" if level_int > 5 _style = _style.compact.join(',') _style.empty? ? '' : "[#{_style}]\n" end end |
#line_break ⇒ String (readonly)
Returns Line break character after title (default: newline).
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/coradoc/asciidoc/model/title.rb', line 36 class Title < Base include Coradoc::AsciiDoc::Model::Anchorable attribute :id, :string attribute :content, Coradoc::AsciiDoc::Model::TextElement, collection: true # attribute :level, :string attribute :level_int, :integer attribute :line_break, :string, default: -> { "\n" } attribute :style, :string alias text content # Convert title content to string # @return [String] The title text def to_s case content when String content when Array content.map do |item| item.is_a?(Coradoc::AsciiDoc::Model::TextElement) ? item.content.to_s : item.to_s end.join else content.to_s end end def level_str return '' if level_int.nil? if level_int <= 5 '=' * (level_int + 1) else '======' end end def style_str return '' if level_int.nil? _style = [style] _style << "level=#{level_int}" if level_int > 5 _style = _style.compact.join(',') _style.empty? ? '' : "[#{_style}]\n" end end |
#style ⇒ String? (readonly)
Returns Optional style attribute for title formatting.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/coradoc/asciidoc/model/title.rb', line 36 class Title < Base include Coradoc::AsciiDoc::Model::Anchorable attribute :id, :string attribute :content, Coradoc::AsciiDoc::Model::TextElement, collection: true # attribute :level, :string attribute :level_int, :integer attribute :line_break, :string, default: -> { "\n" } attribute :style, :string alias text content # Convert title content to string # @return [String] The title text def to_s case content when String content when Array content.map do |item| item.is_a?(Coradoc::AsciiDoc::Model::TextElement) ? item.content.to_s : item.to_s end.join else content.to_s end end def level_str return '' if level_int.nil? if level_int <= 5 '=' * (level_int + 1) else '======' end end def style_str return '' if level_int.nil? _style = [style] _style << "level=#{level_int}" if level_int > 5 _style = _style.compact.join(',') _style.empty? ? '' : "[#{_style}]\n" end end |
Instance Method Details
#level_str ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/coradoc/asciidoc/model/title.rb', line 63 def level_str return '' if level_int.nil? if level_int <= 5 '=' * (level_int + 1) else '======' end end |
#style_str ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/coradoc/asciidoc/model/title.rb', line 73 def style_str return '' if level_int.nil? _style = [style] _style << "level=#{level_int}" if level_int > 5 _style = _style.compact.join(',') _style.empty? ? '' : "[#{_style}]\n" end |
#to_s ⇒ String
Convert title content to string
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/coradoc/asciidoc/model/title.rb', line 50 def to_s case content when String content when Array content.map do |item| item.is_a?(Coradoc::AsciiDoc::Model::TextElement) ? item.content.to_s : item.to_s end.join else content.to_s end end |