Class: Eskimo::Component
- Inherits:
-
Object
- Object
- Eskimo::Component
- Defined in:
- lib/eskimo/component.rb
Overview
A base component class that renders child components defined in a block into a String for further formatting.
class MyComponent < Eskimo::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:
-
Component maintains a reference to the Proc passed to #initialize. That Proc can potentially return a list of child components to render.
-
#render (called via "super" from sub-classes) invokes the
render
prop provided by Renderer#apply with the tracked children which converts them to a String and returns them.
Direct Known Subclasses
Eskimo::Components::DidYouMean, Eskimo::Components::Gutter, Eskimo::Components::Highlight, Eskimo::Components::HighlightColumn, Eskimo::Components::Indent, Eskimo::Components::Strip, Eskimo::Components::StripLeft, Eskimo::Components::StripRight, Eskimo::Components::Style, Eskimo::Components::Truncate, Eskimo::Components::Wrap
Instance Method Summary collapse
-
#initialize(&children_gen) ⇒ Component
constructor
A new instance of Component.
- #render(render:) ⇒ Object
Constructor Details
#initialize(&children_gen) ⇒ Component
Returns a new instance of Component
23 24 25 |
# File 'lib/eskimo/component.rb', line 23 def initialize(*, **, &children_gen) @children = children_gen end |
Instance Method Details
#render(render:) ⇒ Object
27 28 29 |
# File 'lib/eskimo/component.rb', line 27 def render(render:, **) render[@children] end |