Class: Cadenza::BaseRenderer
- Inherits:
-
Object
- Object
- Cadenza::BaseRenderer
- Defined in:
- lib/cadenza/base_renderer.rb
Overview
BaseRenderer is a class you can use to more easily and cleanly implement your own rendering class. To use this then subclass BaseRenderer and implement the appropriate render_xyz methods (see #render for details).
Direct Known Subclasses
Instance Attribute Summary collapse
-
#output ⇒ IO
readonly
The io object that is being written to.
Instance Method Summary collapse
-
#initialize(output_io) ⇒ BaseRenderer
constructor
creates a new renderer and assigns the given output io object to it.
-
#render(node, context, blocks = {}) ⇒ Object
renders the given document node to the output stream given in the constructor.
Constructor Details
#initialize(output_io) ⇒ BaseRenderer
creates a new renderer and assigns the given output io object to it
11 12 13 |
# File 'lib/cadenza/base_renderer.rb', line 11 def initialize(output_io) @output = output_io end |
Instance Attribute Details
#output ⇒ IO (readonly)
Returns the io object that is being written to.
7 8 9 |
# File 'lib/cadenza/base_renderer.rb', line 7 def output @output end |
Instance Method Details
#render(node, context, blocks = {}) ⇒ Object
renders the given document node to the output stream given in the constructor. this method will call the render_xyz method for the node given, where xyz is the demodulized underscored version of the node’s class name. for example: given a Cadenza::DocumentNode this method will call render_document_node
26 27 28 29 30 31 32 |
# File 'lib/cadenza/base_renderer.rb', line 26 def render(node, context, blocks={}) node_type = node.class.name.split("::").last node_name = underscore(node_type).gsub!(/_node$/, '') send("render_#{node_name}", node, context, blocks) end |