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.
<?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?>
Parsing callback -- check to be sure the node tree can have the 'else' tag appended to it.
# File lib/inversion/template/rescuetag.rb, line 48 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
Overridden to default body to nothing, and raise an error if it has one.
# File lib/inversion/template/rescuetag.rb, line 32 def initialize( body='', linenum=nil, colnum=nil ) # :notnew: super @exception_types = parse_exception_types( self.body ) end
Generated with the Darkfish Rdoc Generator 2.