Inversion::Template::

UnlessTag class

Inversion ‘unless’ tag.

This tag causes a section of the template to be rendered only if its methodchain or attribute is a false value.

Syntax

<?unless attr ?>...<?end?>
<?unless 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 )

Create a new UnlessTag.

# File lib/inversion/template/unlesstag.rb, line 39
def initialize( body, linenum=nil, colnum=nil )
        @inverted = false
        super
end

Public Instance Methods

render( state )

Render the tag’s contents if the condition is true, or any else or elsif sections if the condition isn’t true.

# File lib/inversion/template/unlesstag.rb, line 50
def render( state )

        evaluated_state = self.evaluate( state )
        evaluated_state = ! evaluated_state if self.inverted

        # Start out with rendering *disabled* if the tag body evaluates trueishly
        if evaluated_state
                self.log.debug "Initial state was TRUE; disabling rendering"
                state.disable_rendering
        else
                self.log.debug "Initial state was FALSE; enabling rendering"
                state.enable_rendering
        end

        # Set the tag state to track whether or not rendering has been enabled during the
        # 'unless' for an 'else' tag.
        state.with_tag_data( :rendering_was_enabled => state.rendering_enabled? ) do
                self.render_subnodes( state )
        end

        state.enable_rendering
        return nil
end