Inversion::Template::

RescueTag class

Inversion ‘rescue’ tag.

This tag adds a logical switch to a BeginTag. If rendering any of the BeginTag’s nodes raises an exception of the type specified by the RescueTag, the nodes following the RescueTag are rendered instead.

Syntax

<?begin ?>
    <?for employee in employees.all ?>
        <?attr employee.name ?> --> <?attr employee.title ?>
    <?end for?>
<?rescue DatabaseError => err ?>
    Oh no!! I can't talk to the database for some reason.  The
    error was as follows:

        <?attr err.message ?>

<?end?>

Attributes

exception_types R

The exception classes the rescue will handle (an Array of Class objects)

Public Instance Methods

before_appending( parsestate )

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

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

                # If there was a previous 'begin', the 'rescue' belongs to it. Also
                # allow it to be appended to a 'comment' section so you can comment out a
                # rescue clause without commenting out the begin
                when Inversion::Template::BeginTag,
                     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

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/rescuetag.rb, line 30
def initialize( body='', linenum=nil, colnum=nil ) # :notnew:
        super
        @exception_types = parse_exception_types( self.body )
end