Class: Eskimo::ASCII::Spacer

Inherits:
Object
  • Object
show all
Defined in:
gems/eskimo-ascii/lib/eskimo/ascii/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

Constructor Details

#initialize(children) ⇒ Spacer

Returns a new instance of Spacer



16
17
18
19
20
21
22
# File 'gems/eskimo-ascii/lib/eskimo/ascii/components/spacer.rb', line 16

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



24
25
26
27
28
29
# File 'gems/eskimo-ascii/lib/eskimo/ascii/components/spacer.rb', line 24

def render(**props)
  rendered = @children.map(&props[:render])

  without_blanks = rendered.reject(&:empty?)
  without_blanks.join("\n")
end