IfTag

class
Superclass
Inversion::Template::AttrTag
Included Modules
Inversion::Template::ContainerTag

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?>

Public Instance Methods

anchor
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/iftag.rb, line 25
def render( state )

        # Start out with rendering enabled if the tag body evaluates trueishly
        if self.evaluate( state )
                self.log.debug "Initial state was TRUE; enabling rendering"
                state.enable_rendering
        else
                self.log.debug "Initial state was FALSE; disabling rendering"
                state.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.
        state.with_tag_data( rendering_was_enabled: state.rendering_enabled? ) do
                super
        end

        state.enable_rendering
        return nil
end