Class: Eskimo::ASCII::Component
- Inherits:
-
Object
- Object
- Eskimo::ASCII::Component
- Defined in:
- gems/eskimo-ascii/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:
-
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 Core::Renderer#apply with the tracked children which converts them to a String and returns them.
Direct Known Subclasses
DidYouMean, Gutter, Highlight, HighlightColumn, Indent, Strip, StripLeft, StripRight, Style, Truncate, 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 'gems/eskimo-ascii/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 'gems/eskimo-ascii/lib/eskimo/ascii/component.rb', line 27 def render(render:, **) render[@children] end |