class Inversion::Template::ElsifTag
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?>
Attributes
inverted[RW]
Invert the tag’s renderstate if created with the ‘not’ operator.
Public Class Methods
new( body, linenum=nil, colnum=nil )
click to toggle source
Create a new ElsifTag
.
Calls superclass method
Inversion::Template::AttrTag::new
# File lib/inversion/template/elsiftag.rb, line 43 def initialize( body, linenum=nil, colnum=nil ) @inverted = false super end
Public Instance Methods
before_appending( parsestate )
click to toggle source
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).
# File lib/inversion/template/elsiftag.rb, line 54 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 )
click to toggle source
Toggle rendering for the elsiftag’s container if rendering hasn’t yet been toggled.
# File lib/inversion/template/elsiftag.rb, line 80 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
render( * )
click to toggle source
Always render as an empty string.
# File lib/inversion/template/elsiftag.rb, line 73 def render( * ) nil end