Class: Inversion::Template::ElseTag
- Defined in:
- lib/inversion/template/elsetag.rb
Overview
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?>
Constant Summary
Constants inherited from Tag
Instance Attribute Summary
Attributes inherited from Tag
Attributes inherited from Node
Instance Method Summary collapse
-
#before_appending(parsestate) ⇒ Object
Parsing callback – check to be sure the node tree can have an ‘else’ tag appended to it.
-
#before_rendering(renderstate) ⇒ Object
Toggle rendering for the iftag’s container if rendering hasn’t yet been toggled.
-
#initialize(body = '', linenum = nil, colnum = nil) ⇒ ElseTag
constructor
Overridden to default body to nothing, and raise an error if it has one.
-
#render ⇒ Object
Always remder as an empty string.
Methods inherited from Tag
#as_comment_body, create, #derivatives, inherited, load, load_all, #tagname, types, #types
Methods included from MethodUtilities
#singleton_attr_accessor, #singleton_attr_reader, #singleton_attr_writer
Methods included from AbstractClass
Methods included from AbstractClass::ClassMethods
Methods inherited from Node
#after_appending, #after_rendering, #as_comment_body, #is_container?, #location
Constructor Details
#initialize(body = '', linenum = nil, colnum = nil) ⇒ ElseTag
Overridden to default body to nothing, and raise an error if it has one.
24 25 26 27 |
# File 'lib/inversion/template/elsetag.rb', line 24 def initialize( body='', linenum=nil, colnum=nil ) # :notnew: raise Inversion::ParseError, "else can't have a condition" unless body.to_s.strip == '' super end |
Instance Method Details
#before_appending(parsestate) ⇒ Object
Parsing callback – check to be sure the node tree can have an ‘else’ tag appended to it.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/inversion/template/elsetag.rb', line 37 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) ⇒ Object
Toggle rendering for the iftag’s container if rendering hasn’t yet been toggled.
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/inversion/template/elsetag.rb', line 69 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 ⇒ Object
Always remder as an empty string.
62 63 64 |
# File 'lib/inversion/template/elsetag.rb', line 62 def render( * ) nil end |