Class: Eskimo::Components::Gutter
- Inherits:
-
Eskimo::Component
- Object
- Eskimo::Component
- Eskimo::Components::Gutter
- 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
-
#char ⇒ Object
readonly
Returns the value of attribute char.
-
#spacing ⇒ Object
readonly
Returns the value of attribute spacing.
Instance Method Summary collapse
-
#initialize(char:, spacing: 0, &children) ⇒ Gutter
constructor
A new instance of Gutter.
- #render ⇒ Object
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
#char ⇒ Object (readonly)
Returns the value of attribute char
13 14 15 |
# File 'lib/eskimo/components/gutter.rb', line 13 def char @char end |
#spacing ⇒ Object (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
#render ⇒ Object
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 |