Class: Eskimo::ASCII::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/eskimo/ascii/component.rb

Overview

A base component class that renders child components defined in a block into a String for further formatting.

class MyComponent < Eskimo::ASCII::Component
  def render(**)
    text = super
    text.is_a?(String) # => true
  end
end

Use of this class is optional. What’s happening under the hood is:

  1. Component maintains a reference to the Proc passed to #initialize. That Proc can potentially return a list of child components to render.

  2. #render (called via “super” from sub-classes) invokes the ‘render` prop provided by Core::Renderer#apply with the tracked children which converts them to a String and returns them.

Instance Method Summary collapse

Constructor Details

#initialize(&children_gen) ⇒ Component

Returns a new instance of Component.



23
24
25
# File 'lib/eskimo/ascii/component.rb', line 23

def initialize(*, **, &children_gen)
  @children = children_gen
end

Instance Method Details

#render(render:) ⇒ Object



27
28
29
# File 'lib/eskimo/ascii/component.rb', line 27

def render(render:, **)
  render[@children]
end