Class: Cadenza::SourceRenderer
- Inherits:
-
BaseRenderer
- Object
- BaseRenderer
- Cadenza::SourceRenderer
- Defined in:
- lib/cadenza/source_renderer.rb
Overview
SourceRenderer is a rendering implementation that turns a Cadenza AST back into Cadenza source code.
This is mainly intended for users who wish to migrate templates stored in databases, or other storage devices, as their product progresses.
For example: if in v1.0 of your app you define a filter X and deprecate it in favour of filter Y you can use this renderer to automatically replace instances of filter X with filter Y
I’m sure there are many other exciting use cases for the imaginitive user, feel free to let me know what else you do with it!
Constant Summary collapse
- IllegalStateError =
This exception is raised when you try to transition to an undefined state
Class.new(RuntimeError)
- IllegalStateTransitionError =
This exception is raised when you try to transition from one state to another which is not allowed
Class.new(RuntimeError)
- ValidStates =
A list of all valid states for the renderer
[:text, :var, :tag]
Instance Attribute Summary collapse
-
#state ⇒ Object
returns the current state of the renderer (see #ValidStates).
Attributes inherited from BaseRenderer
Class Method Summary collapse
-
.render(document_node, context = {}) ⇒ Object
Renders the document given with the given context directly to a string returns.
Instance Method Summary collapse
-
#initialize(*args) ⇒ SourceRenderer
constructor
creates a new SourceRenderer and places it into the :text state.
Methods inherited from BaseRenderer
Constructor Details
#initialize(*args) ⇒ SourceRenderer
creates a new Cadenza::SourceRenderer and places it into the :text state
42 43 44 45 |
# File 'lib/cadenza/source_renderer.rb', line 42 def initialize(*args) @state = :text super end |
Instance Attribute Details
#state ⇒ Object
returns the current state of the renderer (see #ValidStates)
29 30 31 |
# File 'lib/cadenza/source_renderer.rb', line 29 def state @state end |
Class Method Details
.render(document_node, context = {}) ⇒ Object
Renders the document given with the given context directly to a string returns.
35 36 37 38 39 |
# File 'lib/cadenza/source_renderer.rb', line 35 def self.render(document_node, context={}) io = StringIO.new new(io).render(document_node, context) io.string end |