Class: Inversion::Template::TextNode

Inherits:
Node
  • Object
show all
Defined in:
lib/inversion/template/textnode.rb

Overview

Inversion text node class – container for static content in templates between tags.

Instance Attribute Summary collapse

Attributes inherited from Node

#colnum, #linenum

Instance Method Summary collapse

Methods inherited from Node

#after_appending, #after_rendering, #before_appending, #before_rendering, #is_container?, #location

Methods included from AbstractClass

included

Methods included from AbstractClass::ClassMethods

#inherited, #pure_virtual

Constructor Details

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

Create a new TextNode with the specified ‘source`.


11
12
13
14
# File 'lib/inversion/template/textnode.rb', line 11

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

Instance Attribute Details

#bodyObject (readonly)

The node body


22
23
24
# File 'lib/inversion/template/textnode.rb', line 22

def body
  @body
end

Instance Method Details

#as_comment_bodyObject

Render the text node as the body of a comment.


35
36
37
38
39
# File 'lib/inversion/template/textnode.rb', line 35

def as_comment_body
	comment_body = self.body[0,40].dump
	comment_body[-1,0] = '...' unless comment_body == self.body.dump
	return "Text (%d bytes): %s" % [ self.body.length, comment_body ]
end

#render(renderstate) ⇒ Object

Render the node.


26
27
28
29
30
31
# File 'lib/inversion/template/textnode.rb', line 26

def render( renderstate )
	body = self.body.dup
	body.sub!( /\A\r?\n/, '' ) if renderstate && renderstate.options[:strip_tag_lines]

	return body
end