Inversion::Template::
ElseTag
class
Inversion
‘else’ tag.
This tag adds a logical switch to an IfTag. If the IfTag’s condition was false, start rendering.
Syntax
<?if attr ?>
...
<?else ?>
...
<?end?>
before_appending( parsestate )
Parsing callback – check to be sure the node tree can have an ‘else’ tag appended to it.
def before_appending( parsestate )
condtag = parsestate.node_stack.reverse.find do |node|
case node
when Inversion::Template::IfTag,
Inversion::Template::UnlessTag,
Inversion::Template::CommentTag
break node
when Inversion::Template::ContainerTag
raise Inversion::ParseError, "'%s' tags can't have '%s' clauses" %
[ node.tagname.downcase, self.tagname.downcase ]
end
end
raise Inversion::ParseError, "orphaned '%s' tag" % [ self.tagname.downcase ] unless condtag
end
before_rendering( renderstate )
Toggle rendering for the iftag’s container if rendering hasn’t yet been toggled.
def before_rendering( renderstate )
if renderstate.tag_data[ :rendering_was_enabled ]
self.log.debug " rendering was previously enabled: disabling"
renderstate.disable_rendering
else
self.log.debug " rendering was previously disabled: enabling"
renderstate.tag_data[ :rendering_was_enabled ] = true
renderstate.enable_rendering
end
return nil
end
Always remder as an empty string.
Protected Instance Methods
initialize( body='', linenum=nil, colnum=nil )
Overridden to default body to nothing, and raise an error if it has one.
def initialize( body='', linenum=nil, colnum=nil )
raise Inversion::ParseError, "else can't have a condition" unless body.to_s.strip == ''
super
end