Class: Inversion::Template::Node
- Inherits:
-
Object
- Object
- Inversion::Template::Node
- Extended by:
- Loggability
- Includes:
- AbstractClass
- Defined in:
- lib/inversion/template/node.rb
Overview
Inversion template node base class. Template text is parsed by the Inversion::Parser into nodes, and appended to a tree that is later walked when the template is rendered.
This class is abstract; it just defines the API that other nodes are expected to implement.
Instance Attribute Summary collapse
-
#colnum ⇒ Object
readonly
The column number the node was parsed from in the template source (if known).
-
#linenum ⇒ Object
readonly
The line number the node was parsed from in the template source (if known).
Instance Method Summary collapse
-
#after_appending(state) ⇒ Object
(also: #after_append)
Default (no-op) implementation of the after_appending callback.
-
#after_rendering(state = nil) ⇒ Object
(also: #after_render)
Default (no-op) implementation of the after_rendering callback.
-
#as_comment_body ⇒ Object
Render the node as a comment.
-
#before_appending(state) ⇒ Object
(also: #before_append)
Default (no-op) implementation of the before_appending callback.
-
#before_rendering(state = nil) ⇒ Object
(also: #before_render)
Default (no-op) implementation of the before_rendering callback.
-
#initialize(body, linenum = nil, colnum = nil) ⇒ Node
constructor
Create a new TextNode with the specified ‘source`.
-
#is_container? ⇒ Boolean
(also: #container?)
Returns ‘true` if the node introduces a new parsing/rendering scope.
-
#location ⇒ Object
Return the location of the tag in the template, if it was parsed from one (i.e., if it was created with a StringScanner).
-
#render(render_state) ⇒ Object
Render the node using the given ‘render_state`.
Methods included from AbstractClass
Methods included from AbstractClass::ClassMethods
Constructor Details
#initialize(body, linenum = nil, colnum = nil) ⇒ Node
Create a new TextNode with the specified ‘source`.
24 25 26 27 28 |
# File 'lib/inversion/template/node.rb', line 24 def initialize( body, linenum=nil, colnum=nil ) @body = body @linenum = linenum @colnum = colnum end |
Instance Attribute Details
#colnum ⇒ Object (readonly)
The column number the node was parsed from in the template source (if known)
39 40 41 |
# File 'lib/inversion/template/node.rb', line 39 def colnum @colnum end |
#linenum ⇒ Object (readonly)
The line number the node was parsed from in the template source (if known)
36 37 38 |
# File 'lib/inversion/template/node.rb', line 36 def linenum @linenum end |
Instance Method Details
#after_appending(state) ⇒ Object Also known as: after_append
Default (no-op) implementation of the after_appending callback. This exists so defining the append callbacks are optional for Node’s subclasses.
83 84 85 86 |
# File 'lib/inversion/template/node.rb', line 83 def after_appending( state ) # Nothing to do return nil end |
#after_rendering(state = nil) ⇒ Object Also known as: after_render
Default (no-op) implementation of the after_rendering callback. This exists so defining the rendering callbacks are optional for Node’s subclasses.
101 102 103 104 |
# File 'lib/inversion/template/node.rb', line 101 def after_rendering( state=nil ) # Nothing to do return nil end |
#as_comment_body ⇒ Object
Render the node as a comment
50 51 52 |
# File 'lib/inversion/template/node.rb', line 50 def as_comment_body return self.inspect end |
#before_appending(state) ⇒ Object Also known as: before_append
Default (no-op) implementation of the before_appending callback. This exists so defining the append callbacks are optional for Node’s subclasses.
74 75 76 77 |
# File 'lib/inversion/template/node.rb', line 74 def before_appending( state ) # Nothing to do return nil end |
#before_rendering(state = nil) ⇒ Object Also known as: before_render
Default (no-op) implementation of the before_rendering callback. This exists so defining the rendering callbacks are optional for Node’s subclasses.
92 93 94 95 |
# File 'lib/inversion/template/node.rb', line 92 def before_rendering( state=nil ) # Nothing to do return nil end |
#is_container? ⇒ Boolean Also known as: container?
Returns ‘true` if the node introduces a new parsing/rendering scope.
56 57 58 |
# File 'lib/inversion/template/node.rb', line 56 def is_container? return false end |
#location ⇒ Object
Return the location of the tag in the template, if it was parsed from one (i.e., if it was created with a StringScanner)
64 65 66 67 68 69 |
# File 'lib/inversion/template/node.rb', line 64 def location return "line %s, column %s" % [ self.linenum || '??', self.colnum || '??', ] end |
#render(render_state) ⇒ Object
Render the node using the given ‘render_state`. By default, rendering a node returns `nil`.
44 45 46 |
# File 'lib/inversion/template/node.rb', line 44 def render( render_state ) return nil end |