Class: Arrolio::Content::Preformatted

Inherits:
Object
  • Object
show all
Defined in:
lib/arrolio/content/preformatted.rb

Overview

A preformatted text block. Preserves whitespace (spaces, tabs, newlines) and renders in monospace font without justification. Used for code blocks, ASCII art, and any content where the visual layout of whitespace matters.

Each line becomes a separate inline run in the paragraph so the renderer can apply line-by-line font metrics without the greedy line breaker collapsing internal whitespace.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lines, language: nil, style_id: :preformatted, id: nil) ⇒ Preformatted

Returns a new instance of Preformatted.



16
17
18
19
20
21
22
# File 'lib/arrolio/content/preformatted.rb', line 16

def initialize(lines, language: nil, style_id: :preformatted, id: nil)
  @lines = Array(lines).map(&:to_s).freeze
  @language = language&.to_s
  @style_id = style_id.to_sym
  @id = id&.to_s
  freeze
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/arrolio/content/preformatted.rb', line 14

def id
  @id
end

#languageObject (readonly)

Returns the value of attribute language.



14
15
16
# File 'lib/arrolio/content/preformatted.rb', line 14

def language
  @language
end

#linesObject (readonly)

Returns the value of attribute lines.



14
15
16
# File 'lib/arrolio/content/preformatted.rb', line 14

def lines
  @lines
end

#style_idObject (readonly)

Returns the value of attribute style_id.



14
15
16
# File 'lib/arrolio/content/preformatted.rb', line 14

def style_id
  @style_id
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



32
33
34
35
36
37
38
# File 'lib/arrolio/content/preformatted.rb', line 32

def ==(other)
  other.is_a?(self.class) &&
    lines == other.lines &&
    language == other.language &&
    style_id == other.style_id &&
    id == other.id
end

#empty?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/arrolio/content/preformatted.rb', line 28

def empty?
  @lines.empty? || @lines.all?(&:empty?)
end

#hashObject



42
43
44
# File 'lib/arrolio/content/preformatted.rb', line 42

def hash
  [self.class, lines, language, style_id, id].hash
end

#textObject



24
25
26
# File 'lib/arrolio/content/preformatted.rb', line 24

def text
  @lines.join("\n")
end