class Inversion::Template::IfTag
Inversion
‘if’ tag.
This tag causes a section of the template to be rendered only if its methodchain or attribute is a true value.
Syntax¶ ↑
<?if attr ?>...<?end?> <?if obj.method ?>...<?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 IfTag
.
Calls superclass method
Inversion::Template::ContainerTag::new
# File lib/inversion/template/iftag.rb, line 41 def initialize( body, linenum=nil, colnum=nil ) @inverted = false super end
Public Instance Methods
render( renderstate )
click to toggle source
Render the tag’s contents if the condition is true, or any else or elsif sections if the condition isn’t true.
Calls superclass method
Inversion::Template::ContainerTag#render
# File lib/inversion/template/iftag.rb, line 52 def render( renderstate ) evaluated_state = self.evaluate( renderstate ) evaluated_state = ! evaluated_state if self.inverted # Start out with rendering enabled if the tag body evaluates trueishly if evaluated_state self.log.debug "Initial state was TRUE; enabling rendering" renderstate.enable_rendering else self.log.debug "Initial state was FALSE; disabling rendering" renderstate.disable_rendering end # Set the tag state to track whether or not rendering has been enabled during the # 'if' for an 'else' or 'elsif' tag. renderstate.with_tag_data( rendering_was_enabled: renderstate.rendering_enabled? ) do super end renderstate.enable_rendering return nil end