Inversion::Template::
ElsifTag
class
Inversion
‘elsif’ tag.
This tag adds a conditional logical switch to an IfTag. If the IfTag’s condition was false, but the attribute or methodchain of the elsif is true, start rendering.
Syntax
<?if attr ?>
...
<?elsif attr ?>
...
<?elsif attr.methodchain ?>
...
<?end?>
- inverted RW
Invert the tag’s renderstate if created with the ‘not’ operator.
new( body, linenum=nil, colnum=nil )
Create a new ElsifTag
.
def initialize( body, linenum=nil, colnum=nil )
@inverted = false
super
end
before_appending( parsestate )
Parsing callback – check to be sure the node tree can have an ‘elsif’ tag appended to it (i.e., it has an opening ‘if’ tag).
def before_appending( parsestate )
condtag = parsestate.node_stack.reverse.find do |node|
case node
when Inversion::Template::IfTag,
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
unless condtag
raise Inversion::ParseError, "orphaned '%s' tag" % [ self.tagname.downcase ]
end
end
before_rendering( renderstate )
Toggle rendering for the elsiftag’s container if rendering hasn’t yet been toggled.
def before_rendering( renderstate )
evaluated_state = self.evaluate( renderstate )
evaluated_state = ! evaluated_state if self.inverted
if renderstate.tag_data[ :rendering_was_enabled ]
self.log.debug "Rendering was previously enabled; disabling"
renderstate.disable_rendering
elsif evaluated_state
self.log.debug "Rendering was previously disabled, and condition is true; enabling"
renderstate.tag_data[ :rendering_was_enabled ] = true
renderstate.enable_rendering
end
return nil
end
Always render as an empty string.