Class: Inversion::Template::Node

Inherits:
Object
  • Object
show all
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.

Direct Known Subclasses

Tag, TextNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AbstractClass

included

Methods included from AbstractClass::ClassMethods

#inherited, #pure_virtual

Constructor Details

#initialize(body, linenum = nil, colnum = nil) ⇒ Node

Create a new TextNode with the specified source.



25
26
27
28
29
# File 'lib/inversion/template/node.rb', line 25

def initialize( body, linenum=nil, colnum=nil )
	@body    = body
	@linenum = linenum
	@colnum  = colnum
end

Instance Attribute Details

#colnumObject (readonly)

The column number the node was parsed from in the template source (if known)



40
41
42
# File 'lib/inversion/template/node.rb', line 40

def colnum
  @colnum
end

#linenumObject (readonly)

The line number the node was parsed from in the template source (if known)



37
38
39
# File 'lib/inversion/template/node.rb', line 37

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.



84
85
86
87
# File 'lib/inversion/template/node.rb', line 84

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.



102
103
104
105
# File 'lib/inversion/template/node.rb', line 102

def after_rendering( state=nil )
	# Nothing to do
	return nil
end

#as_comment_bodyObject

Render the node as a comment



51
52
53
# File 'lib/inversion/template/node.rb', line 51

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.



75
76
77
78
# File 'lib/inversion/template/node.rb', line 75

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.



93
94
95
96
# File 'lib/inversion/template/node.rb', line 93

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.

Returns:

  • (Boolean)


57
58
59
# File 'lib/inversion/template/node.rb', line 57

def is_container?
	return false
end

#locationObject

Return the location of the tag in the template, if it was parsed from one (i.e., if it was created with a StringScanner)



65
66
67
68
69
70
# File 'lib/inversion/template/node.rb', line 65

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.



45
46
47
# File 'lib/inversion/template/node.rb', line 45

def render( render_state )
	return nil
end