Inversion::Template::

ElseTag class

Inversion ‘else’ tag.

This tag adds a logical switch to an IfTag. If the IfTag’s condition was false, start rendering.

Syntax

<?if attr ?>
    ...
<?else ?>
    ...
<?end?>

Public Instance Methods

before_appending( parsestate )

Parsing callback – check to be sure the node tree can have an ‘else’ tag appended to it.

# File lib/inversion/template/elsetag.rb, line 36
def before_appending( parsestate )
        condtag = parsestate.node_stack.reverse.find do |node|
                case node

                # If there was a previous 'if' or 'unless', the else belongs to it. Also
                # allow it to be appended to a 'comment' section so you can comment out an
                # else clause
                when Inversion::Template::IfTag,
                     Inversion::Template::UnlessTag,
                     Inversion::Template::CommentTag
                        break node

                # If it's some other kind of container, it's an error
                when Inversion::Template::ContainerTag
                        raise Inversion::ParseError, "'%s' tags can't have '%s' clauses" %
                                [ node.tagname.downcase, self.tagname.downcase ]
                end
        end

        # If there wasn't a valid container, it's an error too
        raise Inversion::ParseError, "orphaned '%s' tag" % [ self.tagname.downcase ] unless condtag
end
before_rendering( renderstate )

Toggle rendering for the iftag’s container if rendering hasn’t yet been toggled.

# File lib/inversion/template/elsetag.rb, line 68
def before_rendering( renderstate )
        if renderstate.tag_data[ :rendering_was_enabled ]
                self.log.debug "  rendering was previously enabled: disabling"
                renderstate.disable_rendering
        else
                self.log.debug "  rendering was previously disabled: enabling"
                renderstate.tag_data[ :rendering_was_enabled ] = true
                renderstate.enable_rendering
        end

        return nil
end
render( * )

Always remder as an empty string.

# File lib/inversion/template/elsetag.rb, line 61
def render( * )
        nil
end

Protected Instance Methods

initialize( body='', linenum=nil, colnum=nil )

Overridden to default body to nothing, and raise an error if it has one.

# File lib/inversion/template/elsetag.rb, line 23
def initialize( body='', linenum=nil, colnum=nil ) # :notnew:
        raise Inversion::ParseError, "else can't have a condition" unless body.to_s.strip == ''
        super
end