class Eskimo::ASCII::Spacer

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.

Public Class Methods

new(children) click to toggle source
# File 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

Public Instance Methods

render(**props) click to toggle source
# File 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