Class: Arrolio::Content::Preformatted
- Inherits:
-
Object
- Object
- Arrolio::Content::Preformatted
- 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
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#style_id ⇒ Object
readonly
Returns the value of attribute style_id.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #empty? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(lines, language: nil, style_id: :preformatted, id: nil) ⇒ Preformatted
constructor
A new instance of Preformatted.
- #text ⇒ Object
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
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'lib/arrolio/content/preformatted.rb', line 14 def id @id end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
14 15 16 |
# File 'lib/arrolio/content/preformatted.rb', line 14 def language @language end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
14 15 16 |
# File 'lib/arrolio/content/preformatted.rb', line 14 def lines @lines end |
#style_id ⇒ Object (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
28 29 30 |
# File 'lib/arrolio/content/preformatted.rb', line 28 def empty? @lines.empty? || @lines.all?(&:empty?) end |
#hash ⇒ Object
42 43 44 |
# File 'lib/arrolio/content/preformatted.rb', line 42 def hash [self.class, lines, language, style_id, id].hash end |
#text ⇒ Object
24 25 26 |
# File 'lib/arrolio/content/preformatted.rb', line 24 def text @lines.join("\n") end |