class Eskimo::ASCII::Squeeze
Squeeze
immediate consecutive soft breaks.
Squeeze.new do [ SoftBreak.new, ConditionalComponent.new, SoftBreak.new, false && SomeOtherComponent.new, SoftBreak.new, 'hello', ] end # => "" # "hello"
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/squeeze.rb, line 24 def initialize(children) if !children.is_a?(Array) || block_given? raise ArgumentError.new("Squeeze 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/squeeze.rb, line 32 def render(**props) rendered = @children.map(&props[:render]) without_blanks = rendered.reject(&:empty?) without_blanks.reject.with_index do |element, index| element == "\n" && without_blanks[index+1] == "\n" end end