Class: Coradoc::AsciiDoc::Model::Section
- Includes:
- Anchorable
- Defined in:
- lib/coradoc/asciidoc/model/section.rb
Overview
Section element for organizing document content hierarchically.
Sections represent the hierarchical structure of an AsciiDoc document. They can contain nested subsections, paragraphs, and other content.
Instance Attribute Summary collapse
-
#attrs ⇒ Array<NamedAttribute>
readonly
Additional named attributes.
-
#content ⇒ String?
readonly
Optional string content (typically unused, see contents).
-
#contents ⇒ Array<Paragraph>
readonly
Paragraph content within this section.
-
#id ⇒ String?
readonly
Optional identifier for the section.
-
#sections ⇒ Array<Section>
readonly
Nested subsections.
-
#title ⇒ Title
readonly
Section title.
Instance Method Summary collapse
- #block_level? ⇒ Boolean
-
#initialize(**attributes) ⇒ Section
constructor
Allow setting level directly during initialization.
-
#level ⇒ Integer?
Get the section level from the title.
-
#level=(value) ⇒ Object
Set the section level on the title.
- #safe_to_collapse? ⇒ Boolean
-
#style ⇒ Object
Style hint derived from the first positional in ‘attribute_list`.
- #validate ⇒ Object
Methods included from Anchorable
#default_anchor, #gen_anchor, included
Methods inherited from Base
#inline?, #serialize_content, #simplify_block_content, #to_adoc, #to_h, visit, #visit
Constructor Details
#initialize(**attributes) ⇒ Section
Allow setting level directly during initialization
77 78 79 80 81 82 83 84 85 |
# File 'lib/coradoc/asciidoc/model/section.rb', line 77 def initialize(**attributes) level_value = attributes.delete(:level) super if level_value && title title.level_int = level_value elsif level_value self.title = Coradoc::AsciiDoc::Model::Title.new(content: '', level_int: level_value) end end |
Instance Attribute Details
#attrs ⇒ Array<NamedAttribute> (readonly)
Returns Additional named attributes.
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/coradoc/asciidoc/model/section.rb', line 39 class Section < Base include Coradoc::AsciiDoc::Model::Anchorable def block_level? true end attribute :id, :string attribute :content, :string attribute :title, Coradoc::AsciiDoc::Model::Title attribute :attrs, Coradoc::AsciiDoc::Model::NamedAttribute, collection: true, initialize_empty: true attribute :contents, Coradoc::AsciiDoc::Model::Paragraph, collection: true, initialize_empty: true attribute :sections, Coradoc::AsciiDoc::Model::Section, collection: true, initialize_empty: true # Block-header attribute list (e.g. `[appendix]`, `[bibliography]`). # Single source of truth for the AsciiDoc `[style]` hint; downstream # consumers (coradoc-mirror) read `style` from SectionElement#attributes # to dispatch JS section types (annex, references, ...). attribute :attribute_list, Coradoc::AsciiDoc::Model::AttributeList # attribute :anchor, Coradoc::AsciiDoc::Model::Inline::Anchor # Style hint derived from the first positional in `attribute_list`. # Returns nil when no list is attached. Kept here so callers don't # need to know the AttributeList shape. def style first_positional = attribute_list&.positional&.first first_positional&.value end # Allow setting level directly during initialization def initialize(**attributes) level_value = attributes.delete(:level) super if level_value && title title.level_int = level_value elsif level_value self.title = Coradoc::AsciiDoc::Model::Title.new(content: '', level_int: level_value) end end def validate validate_title_type super end # Get the section level from the title # @return [Integer, nil] The section level (0-5 for standard sections) def level title&.level_int end # Set the section level on the title # @param value [Integer] The section level def level=(value) if title title.level_int = value else self.title = Coradoc::AsciiDoc::Model::Title.new(content: '', level_int: value) end end def safe_to_collapse? title.nil? && sections.empty? end private def validate_title_type return if title.nil? || title.is_a?(Coradoc::AsciiDoc::Model::Title) raise TypeError, "title must be a Coradoc::AsciiDoc::Model::Title, got #{title.class}" end end |
#content ⇒ String? (readonly)
Returns Optional string content (typically unused, see contents).
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/coradoc/asciidoc/model/section.rb', line 39 class Section < Base include Coradoc::AsciiDoc::Model::Anchorable def block_level? true end attribute :id, :string attribute :content, :string attribute :title, Coradoc::AsciiDoc::Model::Title attribute :attrs, Coradoc::AsciiDoc::Model::NamedAttribute, collection: true, initialize_empty: true attribute :contents, Coradoc::AsciiDoc::Model::Paragraph, collection: true, initialize_empty: true attribute :sections, Coradoc::AsciiDoc::Model::Section, collection: true, initialize_empty: true # Block-header attribute list (e.g. `[appendix]`, `[bibliography]`). # Single source of truth for the AsciiDoc `[style]` hint; downstream # consumers (coradoc-mirror) read `style` from SectionElement#attributes # to dispatch JS section types (annex, references, ...). attribute :attribute_list, Coradoc::AsciiDoc::Model::AttributeList # attribute :anchor, Coradoc::AsciiDoc::Model::Inline::Anchor # Style hint derived from the first positional in `attribute_list`. # Returns nil when no list is attached. Kept here so callers don't # need to know the AttributeList shape. def style first_positional = attribute_list&.positional&.first first_positional&.value end # Allow setting level directly during initialization def initialize(**attributes) level_value = attributes.delete(:level) super if level_value && title title.level_int = level_value elsif level_value self.title = Coradoc::AsciiDoc::Model::Title.new(content: '', level_int: level_value) end end def validate validate_title_type super end # Get the section level from the title # @return [Integer, nil] The section level (0-5 for standard sections) def level title&.level_int end # Set the section level on the title # @param value [Integer] The section level def level=(value) if title title.level_int = value else self.title = Coradoc::AsciiDoc::Model::Title.new(content: '', level_int: value) end end def safe_to_collapse? title.nil? && sections.empty? end private def validate_title_type return if title.nil? || title.is_a?(Coradoc::AsciiDoc::Model::Title) raise TypeError, "title must be a Coradoc::AsciiDoc::Model::Title, got #{title.class}" end end |
#contents ⇒ Array<Paragraph> (readonly)
Returns Paragraph content within this section.
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/coradoc/asciidoc/model/section.rb', line 39 class Section < Base include Coradoc::AsciiDoc::Model::Anchorable def block_level? true end attribute :id, :string attribute :content, :string attribute :title, Coradoc::AsciiDoc::Model::Title attribute :attrs, Coradoc::AsciiDoc::Model::NamedAttribute, collection: true, initialize_empty: true attribute :contents, Coradoc::AsciiDoc::Model::Paragraph, collection: true, initialize_empty: true attribute :sections, Coradoc::AsciiDoc::Model::Section, collection: true, initialize_empty: true # Block-header attribute list (e.g. `[appendix]`, `[bibliography]`). # Single source of truth for the AsciiDoc `[style]` hint; downstream # consumers (coradoc-mirror) read `style` from SectionElement#attributes # to dispatch JS section types (annex, references, ...). attribute :attribute_list, Coradoc::AsciiDoc::Model::AttributeList # attribute :anchor, Coradoc::AsciiDoc::Model::Inline::Anchor # Style hint derived from the first positional in `attribute_list`. # Returns nil when no list is attached. Kept here so callers don't # need to know the AttributeList shape. def style first_positional = attribute_list&.positional&.first first_positional&.value end # Allow setting level directly during initialization def initialize(**attributes) level_value = attributes.delete(:level) super if level_value && title title.level_int = level_value elsif level_value self.title = Coradoc::AsciiDoc::Model::Title.new(content: '', level_int: level_value) end end def validate validate_title_type super end # Get the section level from the title # @return [Integer, nil] The section level (0-5 for standard sections) def level title&.level_int end # Set the section level on the title # @param value [Integer] The section level def level=(value) if title title.level_int = value else self.title = Coradoc::AsciiDoc::Model::Title.new(content: '', level_int: value) end end def safe_to_collapse? title.nil? && sections.empty? end private def validate_title_type return if title.nil? || title.is_a?(Coradoc::AsciiDoc::Model::Title) raise TypeError, "title must be a Coradoc::AsciiDoc::Model::Title, got #{title.class}" end end |
#id ⇒ String? (readonly)
Returns Optional identifier for the section.
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/coradoc/asciidoc/model/section.rb', line 39 class Section < Base include Coradoc::AsciiDoc::Model::Anchorable def block_level? true end attribute :id, :string attribute :content, :string attribute :title, Coradoc::AsciiDoc::Model::Title attribute :attrs, Coradoc::AsciiDoc::Model::NamedAttribute, collection: true, initialize_empty: true attribute :contents, Coradoc::AsciiDoc::Model::Paragraph, collection: true, initialize_empty: true attribute :sections, Coradoc::AsciiDoc::Model::Section, collection: true, initialize_empty: true # Block-header attribute list (e.g. `[appendix]`, `[bibliography]`). # Single source of truth for the AsciiDoc `[style]` hint; downstream # consumers (coradoc-mirror) read `style` from SectionElement#attributes # to dispatch JS section types (annex, references, ...). attribute :attribute_list, Coradoc::AsciiDoc::Model::AttributeList # attribute :anchor, Coradoc::AsciiDoc::Model::Inline::Anchor # Style hint derived from the first positional in `attribute_list`. # Returns nil when no list is attached. Kept here so callers don't # need to know the AttributeList shape. def style first_positional = attribute_list&.positional&.first first_positional&.value end # Allow setting level directly during initialization def initialize(**attributes) level_value = attributes.delete(:level) super if level_value && title title.level_int = level_value elsif level_value self.title = Coradoc::AsciiDoc::Model::Title.new(content: '', level_int: level_value) end end def validate validate_title_type super end # Get the section level from the title # @return [Integer, nil] The section level (0-5 for standard sections) def level title&.level_int end # Set the section level on the title # @param value [Integer] The section level def level=(value) if title title.level_int = value else self.title = Coradoc::AsciiDoc::Model::Title.new(content: '', level_int: value) end end def safe_to_collapse? title.nil? && sections.empty? end private def validate_title_type return if title.nil? || title.is_a?(Coradoc::AsciiDoc::Model::Title) raise TypeError, "title must be a Coradoc::AsciiDoc::Model::Title, got #{title.class}" end end |
#sections ⇒ Array<Section> (readonly)
Returns Nested subsections.
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/coradoc/asciidoc/model/section.rb', line 39 class Section < Base include Coradoc::AsciiDoc::Model::Anchorable def block_level? true end attribute :id, :string attribute :content, :string attribute :title, Coradoc::AsciiDoc::Model::Title attribute :attrs, Coradoc::AsciiDoc::Model::NamedAttribute, collection: true, initialize_empty: true attribute :contents, Coradoc::AsciiDoc::Model::Paragraph, collection: true, initialize_empty: true attribute :sections, Coradoc::AsciiDoc::Model::Section, collection: true, initialize_empty: true # Block-header attribute list (e.g. `[appendix]`, `[bibliography]`). # Single source of truth for the AsciiDoc `[style]` hint; downstream # consumers (coradoc-mirror) read `style` from SectionElement#attributes # to dispatch JS section types (annex, references, ...). attribute :attribute_list, Coradoc::AsciiDoc::Model::AttributeList # attribute :anchor, Coradoc::AsciiDoc::Model::Inline::Anchor # Style hint derived from the first positional in `attribute_list`. # Returns nil when no list is attached. Kept here so callers don't # need to know the AttributeList shape. def style first_positional = attribute_list&.positional&.first first_positional&.value end # Allow setting level directly during initialization def initialize(**attributes) level_value = attributes.delete(:level) super if level_value && title title.level_int = level_value elsif level_value self.title = Coradoc::AsciiDoc::Model::Title.new(content: '', level_int: level_value) end end def validate validate_title_type super end # Get the section level from the title # @return [Integer, nil] The section level (0-5 for standard sections) def level title&.level_int end # Set the section level on the title # @param value [Integer] The section level def level=(value) if title title.level_int = value else self.title = Coradoc::AsciiDoc::Model::Title.new(content: '', level_int: value) end end def safe_to_collapse? title.nil? && sections.empty? end private def validate_title_type return if title.nil? || title.is_a?(Coradoc::AsciiDoc::Model::Title) raise TypeError, "title must be a Coradoc::AsciiDoc::Model::Title, got #{title.class}" end end |
#title ⇒ Title (readonly)
Returns Section title.
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/coradoc/asciidoc/model/section.rb', line 39 class Section < Base include Coradoc::AsciiDoc::Model::Anchorable def block_level? true end attribute :id, :string attribute :content, :string attribute :title, Coradoc::AsciiDoc::Model::Title attribute :attrs, Coradoc::AsciiDoc::Model::NamedAttribute, collection: true, initialize_empty: true attribute :contents, Coradoc::AsciiDoc::Model::Paragraph, collection: true, initialize_empty: true attribute :sections, Coradoc::AsciiDoc::Model::Section, collection: true, initialize_empty: true # Block-header attribute list (e.g. `[appendix]`, `[bibliography]`). # Single source of truth for the AsciiDoc `[style]` hint; downstream # consumers (coradoc-mirror) read `style` from SectionElement#attributes # to dispatch JS section types (annex, references, ...). attribute :attribute_list, Coradoc::AsciiDoc::Model::AttributeList # attribute :anchor, Coradoc::AsciiDoc::Model::Inline::Anchor # Style hint derived from the first positional in `attribute_list`. # Returns nil when no list is attached. Kept here so callers don't # need to know the AttributeList shape. def style first_positional = attribute_list&.positional&.first first_positional&.value end # Allow setting level directly during initialization def initialize(**attributes) level_value = attributes.delete(:level) super if level_value && title title.level_int = level_value elsif level_value self.title = Coradoc::AsciiDoc::Model::Title.new(content: '', level_int: level_value) end end def validate validate_title_type super end # Get the section level from the title # @return [Integer, nil] The section level (0-5 for standard sections) def level title&.level_int end # Set the section level on the title # @param value [Integer] The section level def level=(value) if title title.level_int = value else self.title = Coradoc::AsciiDoc::Model::Title.new(content: '', level_int: value) end end def safe_to_collapse? title.nil? && sections.empty? end private def validate_title_type return if title.nil? || title.is_a?(Coradoc::AsciiDoc::Model::Title) raise TypeError, "title must be a Coradoc::AsciiDoc::Model::Title, got #{title.class}" end end |
Instance Method Details
#block_level? ⇒ Boolean
42 43 44 |
# File 'lib/coradoc/asciidoc/model/section.rb', line 42 def block_level? true end |
#level ⇒ Integer?
Get the section level from the title
94 95 96 |
# File 'lib/coradoc/asciidoc/model/section.rb', line 94 def level title&.level_int end |
#level=(value) ⇒ Object
Set the section level on the title
100 101 102 103 104 105 106 |
# File 'lib/coradoc/asciidoc/model/section.rb', line 100 def level=(value) if title title.level_int = value else self.title = Coradoc::AsciiDoc::Model::Title.new(content: '', level_int: value) end end |
#safe_to_collapse? ⇒ Boolean
108 109 110 |
# File 'lib/coradoc/asciidoc/model/section.rb', line 108 def safe_to_collapse? title.nil? && sections.empty? end |
#style ⇒ Object
Style hint derived from the first positional in ‘attribute_list`. Returns nil when no list is attached. Kept here so callers don’t need to know the AttributeList shape.
71 72 73 74 |
# File 'lib/coradoc/asciidoc/model/section.rb', line 71 def style first_positional = attribute_list&.positional&.first first_positional&.value end |
#validate ⇒ Object
87 88 89 90 |
# File 'lib/coradoc/asciidoc/model/section.rb', line 87 def validate validate_title_type super end |