Class: Eskimo::Components::Gutter

Inherits:
Eskimo::Component show all
Defined in:
lib/eskimo/components/gutter.rb

Overview

Prepend each line with a character or symbol.

Gutter.new(char: '| ') do
  [ "Hello", "\n", "World!" ]
end
# => "| Hello"
#    "| World!"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(char:, spacing: 0, &children) ⇒ Gutter

Returns a new instance of Gutter



15
16
17
18
19
20
# File 'lib/eskimo/components/gutter.rb', line 15

def initialize(char:, spacing: 0, &children)
  @char = char
  @spacing = spacing

  super
end

Instance Attribute Details

#charObject (readonly)

Returns the value of attribute char



13
14
15
# File 'lib/eskimo/components/gutter.rb', line 13

def char
  @char
end

#spacingObject (readonly)

Returns the value of attribute spacing



13
14
15
# File 'lib/eskimo/components/gutter.rb', line 13

def spacing
  @spacing
end

Instance Method Details

#renderObject



22
23
24
25
26
27
28
29
30
# File 'lib/eskimo/components/gutter.rb', line 22

def render(**)
  spacer = Array.new(spacing, char)

  [
    *spacer,
    super.lines.map { |s| s.prepend(char) }.join,
    *spacer
  ].join("\n")
end