Class: Eskimo::Components::Spacer
- Inherits:
-
Object
- Object
- Eskimo::Components::Spacer
- Defined in:
- lib/eskimo/components/spacer.rb
Overview
Space consecutive components with soft breaks.
Spacer.new([
"Hello",
"World!"
])
# => "Hello"
# "World!"
The soft breaks for each conditional component will be preserved only if they do render some content.
Instance Method Summary collapse
-
#initialize(children) ⇒ Spacer
constructor
A new instance of Spacer.
- #render(**props) ⇒ Object
Constructor Details
#initialize(children) ⇒ Spacer
Returns a new instance of Spacer
17 18 19 20 21 22 23 |
# File 'lib/eskimo/components/spacer.rb', line 17 def initialize(children) if !children.is_a?(Array) || block_given? raise ArgumentError.new("Spacer works only with an Array of components") end @children = children end |
Instance Method Details
#render(**props) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/eskimo/components/spacer.rb', line 25 def render(**props) rendered = @children.map(&props[:render]) without_blanks = rendered.reject(&:empty?) without_blanks.join("\n") end |