Class: Coradoc::AsciiDoc::Model::Block::Core

Inherits:
Attached show all
Includes:
Anchorable
Defined in:
lib/coradoc/asciidoc/model/block/core.rb

Overview

Base class for block elements in AsciiDoc documents.

Block elements are delimited content sections that can contain multiple lines, titles, attributes, and attached blocks.

Specific block types (Literal, Example, Listing, Quote, etc.) inherit from this class and define their delimiter characters.

Examples:

Create a custom block

block = Coradoc::AsciiDoc::Model::Block::Core.new
block.delimiter_char = "-"
block.delimiter_len = 4
block.lines = ["Line 1", "Line 2"]

See Also:

Direct Known Subclasses

Example, Listing, Literal, Open, Pass, Quote, ReviewerComment, Side, SourceCode

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Anchorable

#default_anchor, #gen_anchor, included

Methods inherited from Attached

#block_level?

Methods inherited from Coradoc::AsciiDoc::Model::Base

#block_level?, #inline?, #serialize_content, #simplify_block_content, #to_adoc, #to_h, visit, #visit

Constructor Details

#initialize(**attributes) ⇒ Core

Returns a new instance of Core.



85
86
87
88
89
90
91
92
# File 'lib/coradoc/asciidoc/model/block/core.rb', line 85

def initialize(**attributes)
  # Extract title and lines before super to avoid coercion
  title_value = attributes.delete(:title)
  lines_value = attributes.delete(:lines)
  super
  self.title = title_value if title_value
  self.lines = lines_value if lines_value
end

Instance Attribute Details

#attributesCoradoc::AsciiDoc::Model::AttributeList (readonly)

Returns Block attributes.

Returns:



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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/coradoc/asciidoc/model/block/core.rb', line 53

class Core < Attached
  include Coradoc::AsciiDoc::Model::Anchorable

  attribute :id, :string
  attribute :title, :string, default: -> { nil } # Polymorphic: string or array of Model objects
  attribute :attributes, Coradoc::AsciiDoc::Model::AttributeList, default: lambda {
    Coradoc::AsciiDoc::Model::AttributeList.new
  }
  attribute :lines,
            Lutaml::Model::Serializable,
            collection: true,
            initialize_empty: true,
            polymorphic: [
              Lutaml::Model::Type::String,
              Coradoc::AsciiDoc::Model::TextElement
            ]
  attribute :delimiter, :string
  attribute :delimiter_char, :string
  attribute :delimiter_len, :integer
  attribute :lang, :string
  attribute :type_str, :string

  # Override title and lines setters to accept polymorphic content without coercion

  attr_accessor :title

  attr_writer :lines

  def lines
    @lines || []
  end

  def initialize(**attributes)
    # Extract title and lines before super to avoid coercion
    title_value = attributes.delete(:title)
    lines_value = attributes.delete(:lines)
    super
    self.title = title_value if title_value
    self.lines = lines_value if lines_value
  end

  # NOTE: This module provides core block functionality.
  # Additional methods may be added as needed for specific block types.

  # Generate the title string for this block
  #
  # @return [String] The formatted title (e.g., ".Title\n")
  def gen_title
    t = serialize_content(title)
    return '' if t.nil? || t.empty?

    ".#{t}\n"
  end

  # Generate the attributes string for this block
  #
  # @return [String] The formatted attributes
  def gen_attributes
    attrs = attributes.to_adoc(show_empty: false)
    return "#{attrs}\n" unless attrs.empty?

    ''
  end

  # Generate the delimiter string for this block
  #
  # @return [String] The delimiter (e.g., "----", "====")
  # @return [String] Empty string if delimiter_char or delimiter_len is nil
  def gen_delimiter
    return '' if delimiter_char.nil? || delimiter_len.nil?

    delimiter_char * delimiter_len
  end

  # Generate the lines content for this block
  #
  # @return [String] The serialized lines
  def gen_lines
    lines.map do |line|
      serialize_content(line)
    end.join
  end
end

#delimiterString? (readonly)

Returns Full delimiter string.

Returns:

  • (String, nil)

    Full delimiter string



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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/coradoc/asciidoc/model/block/core.rb', line 53

class Core < Attached
  include Coradoc::AsciiDoc::Model::Anchorable

  attribute :id, :string
  attribute :title, :string, default: -> { nil } # Polymorphic: string or array of Model objects
  attribute :attributes, Coradoc::AsciiDoc::Model::AttributeList, default: lambda {
    Coradoc::AsciiDoc::Model::AttributeList.new
  }
  attribute :lines,
            Lutaml::Model::Serializable,
            collection: true,
            initialize_empty: true,
            polymorphic: [
              Lutaml::Model::Type::String,
              Coradoc::AsciiDoc::Model::TextElement
            ]
  attribute :delimiter, :string
  attribute :delimiter_char, :string
  attribute :delimiter_len, :integer
  attribute :lang, :string
  attribute :type_str, :string

  # Override title and lines setters to accept polymorphic content without coercion

  attr_accessor :title

  attr_writer :lines

  def lines
    @lines || []
  end

  def initialize(**attributes)
    # Extract title and lines before super to avoid coercion
    title_value = attributes.delete(:title)
    lines_value = attributes.delete(:lines)
    super
    self.title = title_value if title_value
    self.lines = lines_value if lines_value
  end

  # NOTE: This module provides core block functionality.
  # Additional methods may be added as needed for specific block types.

  # Generate the title string for this block
  #
  # @return [String] The formatted title (e.g., ".Title\n")
  def gen_title
    t = serialize_content(title)
    return '' if t.nil? || t.empty?

    ".#{t}\n"
  end

  # Generate the attributes string for this block
  #
  # @return [String] The formatted attributes
  def gen_attributes
    attrs = attributes.to_adoc(show_empty: false)
    return "#{attrs}\n" unless attrs.empty?

    ''
  end

  # Generate the delimiter string for this block
  #
  # @return [String] The delimiter (e.g., "----", "====")
  # @return [String] Empty string if delimiter_char or delimiter_len is nil
  def gen_delimiter
    return '' if delimiter_char.nil? || delimiter_len.nil?

    delimiter_char * delimiter_len
  end

  # Generate the lines content for this block
  #
  # @return [String] The serialized lines
  def gen_lines
    lines.map do |line|
      serialize_content(line)
    end.join
  end
end

#delimiter_charString? (readonly)

Returns Delimiter character (e.g., “=”, “-”, “*”, “_”, “+”).

Returns:

  • (String, nil)

    Delimiter character (e.g., “=”, “-”, “*”, “_”, “+”)



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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/coradoc/asciidoc/model/block/core.rb', line 53

class Core < Attached
  include Coradoc::AsciiDoc::Model::Anchorable

  attribute :id, :string
  attribute :title, :string, default: -> { nil } # Polymorphic: string or array of Model objects
  attribute :attributes, Coradoc::AsciiDoc::Model::AttributeList, default: lambda {
    Coradoc::AsciiDoc::Model::AttributeList.new
  }
  attribute :lines,
            Lutaml::Model::Serializable,
            collection: true,
            initialize_empty: true,
            polymorphic: [
              Lutaml::Model::Type::String,
              Coradoc::AsciiDoc::Model::TextElement
            ]
  attribute :delimiter, :string
  attribute :delimiter_char, :string
  attribute :delimiter_len, :integer
  attribute :lang, :string
  attribute :type_str, :string

  # Override title and lines setters to accept polymorphic content without coercion

  attr_accessor :title

  attr_writer :lines

  def lines
    @lines || []
  end

  def initialize(**attributes)
    # Extract title and lines before super to avoid coercion
    title_value = attributes.delete(:title)
    lines_value = attributes.delete(:lines)
    super
    self.title = title_value if title_value
    self.lines = lines_value if lines_value
  end

  # NOTE: This module provides core block functionality.
  # Additional methods may be added as needed for specific block types.

  # Generate the title string for this block
  #
  # @return [String] The formatted title (e.g., ".Title\n")
  def gen_title
    t = serialize_content(title)
    return '' if t.nil? || t.empty?

    ".#{t}\n"
  end

  # Generate the attributes string for this block
  #
  # @return [String] The formatted attributes
  def gen_attributes
    attrs = attributes.to_adoc(show_empty: false)
    return "#{attrs}\n" unless attrs.empty?

    ''
  end

  # Generate the delimiter string for this block
  #
  # @return [String] The delimiter (e.g., "----", "====")
  # @return [String] Empty string if delimiter_char or delimiter_len is nil
  def gen_delimiter
    return '' if delimiter_char.nil? || delimiter_len.nil?

    delimiter_char * delimiter_len
  end

  # Generate the lines content for this block
  #
  # @return [String] The serialized lines
  def gen_lines
    lines.map do |line|
      serialize_content(line)
    end.join
  end
end

#delimiter_lenInteger? (readonly)

Returns Delimiter length (number of repeated characters).

Returns:

  • (Integer, nil)

    Delimiter length (number of repeated characters)



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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/coradoc/asciidoc/model/block/core.rb', line 53

class Core < Attached
  include Coradoc::AsciiDoc::Model::Anchorable

  attribute :id, :string
  attribute :title, :string, default: -> { nil } # Polymorphic: string or array of Model objects
  attribute :attributes, Coradoc::AsciiDoc::Model::AttributeList, default: lambda {
    Coradoc::AsciiDoc::Model::AttributeList.new
  }
  attribute :lines,
            Lutaml::Model::Serializable,
            collection: true,
            initialize_empty: true,
            polymorphic: [
              Lutaml::Model::Type::String,
              Coradoc::AsciiDoc::Model::TextElement
            ]
  attribute :delimiter, :string
  attribute :delimiter_char, :string
  attribute :delimiter_len, :integer
  attribute :lang, :string
  attribute :type_str, :string

  # Override title and lines setters to accept polymorphic content without coercion

  attr_accessor :title

  attr_writer :lines

  def lines
    @lines || []
  end

  def initialize(**attributes)
    # Extract title and lines before super to avoid coercion
    title_value = attributes.delete(:title)
    lines_value = attributes.delete(:lines)
    super
    self.title = title_value if title_value
    self.lines = lines_value if lines_value
  end

  # NOTE: This module provides core block functionality.
  # Additional methods may be added as needed for specific block types.

  # Generate the title string for this block
  #
  # @return [String] The formatted title (e.g., ".Title\n")
  def gen_title
    t = serialize_content(title)
    return '' if t.nil? || t.empty?

    ".#{t}\n"
  end

  # Generate the attributes string for this block
  #
  # @return [String] The formatted attributes
  def gen_attributes
    attrs = attributes.to_adoc(show_empty: false)
    return "#{attrs}\n" unless attrs.empty?

    ''
  end

  # Generate the delimiter string for this block
  #
  # @return [String] The delimiter (e.g., "----", "====")
  # @return [String] Empty string if delimiter_char or delimiter_len is nil
  def gen_delimiter
    return '' if delimiter_char.nil? || delimiter_len.nil?

    delimiter_char * delimiter_len
  end

  # Generate the lines content for this block
  #
  # @return [String] The serialized lines
  def gen_lines
    lines.map do |line|
      serialize_content(line)
    end.join
  end
end

#idString? (readonly)

Returns Optional identifier for the block.

Returns:

  • (String, nil)

    Optional identifier for the block



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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/coradoc/asciidoc/model/block/core.rb', line 53

class Core < Attached
  include Coradoc::AsciiDoc::Model::Anchorable

  attribute :id, :string
  attribute :title, :string, default: -> { nil } # Polymorphic: string or array of Model objects
  attribute :attributes, Coradoc::AsciiDoc::Model::AttributeList, default: lambda {
    Coradoc::AsciiDoc::Model::AttributeList.new
  }
  attribute :lines,
            Lutaml::Model::Serializable,
            collection: true,
            initialize_empty: true,
            polymorphic: [
              Lutaml::Model::Type::String,
              Coradoc::AsciiDoc::Model::TextElement
            ]
  attribute :delimiter, :string
  attribute :delimiter_char, :string
  attribute :delimiter_len, :integer
  attribute :lang, :string
  attribute :type_str, :string

  # Override title and lines setters to accept polymorphic content without coercion

  attr_accessor :title

  attr_writer :lines

  def lines
    @lines || []
  end

  def initialize(**attributes)
    # Extract title and lines before super to avoid coercion
    title_value = attributes.delete(:title)
    lines_value = attributes.delete(:lines)
    super
    self.title = title_value if title_value
    self.lines = lines_value if lines_value
  end

  # NOTE: This module provides core block functionality.
  # Additional methods may be added as needed for specific block types.

  # Generate the title string for this block
  #
  # @return [String] The formatted title (e.g., ".Title\n")
  def gen_title
    t = serialize_content(title)
    return '' if t.nil? || t.empty?

    ".#{t}\n"
  end

  # Generate the attributes string for this block
  #
  # @return [String] The formatted attributes
  def gen_attributes
    attrs = attributes.to_adoc(show_empty: false)
    return "#{attrs}\n" unless attrs.empty?

    ''
  end

  # Generate the delimiter string for this block
  #
  # @return [String] The delimiter (e.g., "----", "====")
  # @return [String] Empty string if delimiter_char or delimiter_len is nil
  def gen_delimiter
    return '' if delimiter_char.nil? || delimiter_len.nil?

    delimiter_char * delimiter_len
  end

  # Generate the lines content for this block
  #
  # @return [String] The serialized lines
  def gen_lines
    lines.map do |line|
      serialize_content(line)
    end.join
  end
end

#langString? (readonly)

Returns Language identifier for syntax highlighting.

Returns:

  • (String, nil)

    Language identifier for syntax highlighting



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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/coradoc/asciidoc/model/block/core.rb', line 53

class Core < Attached
  include Coradoc::AsciiDoc::Model::Anchorable

  attribute :id, :string
  attribute :title, :string, default: -> { nil } # Polymorphic: string or array of Model objects
  attribute :attributes, Coradoc::AsciiDoc::Model::AttributeList, default: lambda {
    Coradoc::AsciiDoc::Model::AttributeList.new
  }
  attribute :lines,
            Lutaml::Model::Serializable,
            collection: true,
            initialize_empty: true,
            polymorphic: [
              Lutaml::Model::Type::String,
              Coradoc::AsciiDoc::Model::TextElement
            ]
  attribute :delimiter, :string
  attribute :delimiter_char, :string
  attribute :delimiter_len, :integer
  attribute :lang, :string
  attribute :type_str, :string

  # Override title and lines setters to accept polymorphic content without coercion

  attr_accessor :title

  attr_writer :lines

  def lines
    @lines || []
  end

  def initialize(**attributes)
    # Extract title and lines before super to avoid coercion
    title_value = attributes.delete(:title)
    lines_value = attributes.delete(:lines)
    super
    self.title = title_value if title_value
    self.lines = lines_value if lines_value
  end

  # NOTE: This module provides core block functionality.
  # Additional methods may be added as needed for specific block types.

  # Generate the title string for this block
  #
  # @return [String] The formatted title (e.g., ".Title\n")
  def gen_title
    t = serialize_content(title)
    return '' if t.nil? || t.empty?

    ".#{t}\n"
  end

  # Generate the attributes string for this block
  #
  # @return [String] The formatted attributes
  def gen_attributes
    attrs = attributes.to_adoc(show_empty: false)
    return "#{attrs}\n" unless attrs.empty?

    ''
  end

  # Generate the delimiter string for this block
  #
  # @return [String] The delimiter (e.g., "----", "====")
  # @return [String] Empty string if delimiter_char or delimiter_len is nil
  def gen_delimiter
    return '' if delimiter_char.nil? || delimiter_len.nil?

    delimiter_char * delimiter_len
  end

  # Generate the lines content for this block
  #
  # @return [String] The serialized lines
  def gen_lines
    lines.map do |line|
      serialize_content(line)
    end.join
  end
end

#linesArray<Lutaml::Model::Type::String, Coradoc::AsciiDoc::Model::TextElement>

Returns Block content lines.

Returns:



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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/coradoc/asciidoc/model/block/core.rb', line 53

class Core < Attached
  include Coradoc::AsciiDoc::Model::Anchorable

  attribute :id, :string
  attribute :title, :string, default: -> { nil } # Polymorphic: string or array of Model objects
  attribute :attributes, Coradoc::AsciiDoc::Model::AttributeList, default: lambda {
    Coradoc::AsciiDoc::Model::AttributeList.new
  }
  attribute :lines,
            Lutaml::Model::Serializable,
            collection: true,
            initialize_empty: true,
            polymorphic: [
              Lutaml::Model::Type::String,
              Coradoc::AsciiDoc::Model::TextElement
            ]
  attribute :delimiter, :string
  attribute :delimiter_char, :string
  attribute :delimiter_len, :integer
  attribute :lang, :string
  attribute :type_str, :string

  # Override title and lines setters to accept polymorphic content without coercion

  attr_accessor :title

  attr_writer :lines

  def lines
    @lines || []
  end

  def initialize(**attributes)
    # Extract title and lines before super to avoid coercion
    title_value = attributes.delete(:title)
    lines_value = attributes.delete(:lines)
    super
    self.title = title_value if title_value
    self.lines = lines_value if lines_value
  end

  # NOTE: This module provides core block functionality.
  # Additional methods may be added as needed for specific block types.

  # Generate the title string for this block
  #
  # @return [String] The formatted title (e.g., ".Title\n")
  def gen_title
    t = serialize_content(title)
    return '' if t.nil? || t.empty?

    ".#{t}\n"
  end

  # Generate the attributes string for this block
  #
  # @return [String] The formatted attributes
  def gen_attributes
    attrs = attributes.to_adoc(show_empty: false)
    return "#{attrs}\n" unless attrs.empty?

    ''
  end

  # Generate the delimiter string for this block
  #
  # @return [String] The delimiter (e.g., "----", "====")
  # @return [String] Empty string if delimiter_char or delimiter_len is nil
  def gen_delimiter
    return '' if delimiter_char.nil? || delimiter_len.nil?

    delimiter_char * delimiter_len
  end

  # Generate the lines content for this block
  #
  # @return [String] The serialized lines
  def gen_lines
    lines.map do |line|
      serialize_content(line)
    end.join
  end
end

#titleObject

Override title and lines setters to accept polymorphic content without coercion



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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/coradoc/asciidoc/model/block/core.rb', line 53

class Core < Attached
  include Coradoc::AsciiDoc::Model::Anchorable

  attribute :id, :string
  attribute :title, :string, default: -> { nil } # Polymorphic: string or array of Model objects
  attribute :attributes, Coradoc::AsciiDoc::Model::AttributeList, default: lambda {
    Coradoc::AsciiDoc::Model::AttributeList.new
  }
  attribute :lines,
            Lutaml::Model::Serializable,
            collection: true,
            initialize_empty: true,
            polymorphic: [
              Lutaml::Model::Type::String,
              Coradoc::AsciiDoc::Model::TextElement
            ]
  attribute :delimiter, :string
  attribute :delimiter_char, :string
  attribute :delimiter_len, :integer
  attribute :lang, :string
  attribute :type_str, :string

  # Override title and lines setters to accept polymorphic content without coercion

  attr_accessor :title

  attr_writer :lines

  def lines
    @lines || []
  end

  def initialize(**attributes)
    # Extract title and lines before super to avoid coercion
    title_value = attributes.delete(:title)
    lines_value = attributes.delete(:lines)
    super
    self.title = title_value if title_value
    self.lines = lines_value if lines_value
  end

  # NOTE: This module provides core block functionality.
  # Additional methods may be added as needed for specific block types.

  # Generate the title string for this block
  #
  # @return [String] The formatted title (e.g., ".Title\n")
  def gen_title
    t = serialize_content(title)
    return '' if t.nil? || t.empty?

    ".#{t}\n"
  end

  # Generate the attributes string for this block
  #
  # @return [String] The formatted attributes
  def gen_attributes
    attrs = attributes.to_adoc(show_empty: false)
    return "#{attrs}\n" unless attrs.empty?

    ''
  end

  # Generate the delimiter string for this block
  #
  # @return [String] The delimiter (e.g., "----", "====")
  # @return [String] Empty string if delimiter_char or delimiter_len is nil
  def gen_delimiter
    return '' if delimiter_char.nil? || delimiter_len.nil?

    delimiter_char * delimiter_len
  end

  # Generate the lines content for this block
  #
  # @return [String] The serialized lines
  def gen_lines
    lines.map do |line|
      serialize_content(line)
    end.join
  end
end

#type_strString? (readonly)

Returns Block type string.

Returns:

  • (String, nil)

    Block type string



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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/coradoc/asciidoc/model/block/core.rb', line 53

class Core < Attached
  include Coradoc::AsciiDoc::Model::Anchorable

  attribute :id, :string
  attribute :title, :string, default: -> { nil } # Polymorphic: string or array of Model objects
  attribute :attributes, Coradoc::AsciiDoc::Model::AttributeList, default: lambda {
    Coradoc::AsciiDoc::Model::AttributeList.new
  }
  attribute :lines,
            Lutaml::Model::Serializable,
            collection: true,
            initialize_empty: true,
            polymorphic: [
              Lutaml::Model::Type::String,
              Coradoc::AsciiDoc::Model::TextElement
            ]
  attribute :delimiter, :string
  attribute :delimiter_char, :string
  attribute :delimiter_len, :integer
  attribute :lang, :string
  attribute :type_str, :string

  # Override title and lines setters to accept polymorphic content without coercion

  attr_accessor :title

  attr_writer :lines

  def lines
    @lines || []
  end

  def initialize(**attributes)
    # Extract title and lines before super to avoid coercion
    title_value = attributes.delete(:title)
    lines_value = attributes.delete(:lines)
    super
    self.title = title_value if title_value
    self.lines = lines_value if lines_value
  end

  # NOTE: This module provides core block functionality.
  # Additional methods may be added as needed for specific block types.

  # Generate the title string for this block
  #
  # @return [String] The formatted title (e.g., ".Title\n")
  def gen_title
    t = serialize_content(title)
    return '' if t.nil? || t.empty?

    ".#{t}\n"
  end

  # Generate the attributes string for this block
  #
  # @return [String] The formatted attributes
  def gen_attributes
    attrs = attributes.to_adoc(show_empty: false)
    return "#{attrs}\n" unless attrs.empty?

    ''
  end

  # Generate the delimiter string for this block
  #
  # @return [String] The delimiter (e.g., "----", "====")
  # @return [String] Empty string if delimiter_char or delimiter_len is nil
  def gen_delimiter
    return '' if delimiter_char.nil? || delimiter_len.nil?

    delimiter_char * delimiter_len
  end

  # Generate the lines content for this block
  #
  # @return [String] The serialized lines
  def gen_lines
    lines.map do |line|
      serialize_content(line)
    end.join
  end
end

Instance Method Details

#gen_attributesString

Generate the attributes string for this block

Returns:

  • (String)

    The formatted attributes



110
111
112
113
114
115
# File 'lib/coradoc/asciidoc/model/block/core.rb', line 110

def gen_attributes
  attrs = attributes.to_adoc(show_empty: false)
  return "#{attrs}\n" unless attrs.empty?

  ''
end

#gen_delimiterString

Generate the delimiter string for this block

Returns:

  • (String)

    The delimiter (e.g., “—-”, “====”)

  • (String)

    Empty string if delimiter_char or delimiter_len is nil



121
122
123
124
125
# File 'lib/coradoc/asciidoc/model/block/core.rb', line 121

def gen_delimiter
  return '' if delimiter_char.nil? || delimiter_len.nil?

  delimiter_char * delimiter_len
end

#gen_linesString

Generate the lines content for this block

Returns:

  • (String)

    The serialized lines



130
131
132
133
134
# File 'lib/coradoc/asciidoc/model/block/core.rb', line 130

def gen_lines
  lines.map do |line|
    serialize_content(line)
  end.join
end

#gen_titleString

Generate the title string for this block

Returns:

  • (String)

    The formatted title (e.g., “.Titlen”)



100
101
102
103
104
105
# File 'lib/coradoc/asciidoc/model/block/core.rb', line 100

def gen_title
  t = serialize_content(title)
  return '' if t.nil? || t.empty?

  ".#{t}\n"
end