Class: Inversion::Template::UnlessTag
- Includes:
- ContainerTag
- Defined in:
- lib/inversion/template/unlesstag.rb
Overview
Inversion ‘unless’ tag.
This tag causes a section of the template to be rendered only if its methodchain or attribute is a false value.
Syntax
<?unless attr ?>...<?end?>
<?unless obj.method ?>...<?end?>
Constant Summary
Constants inherited from Tag
Instance Attribute Summary collapse
-
#inverted ⇒ Object
Invert the tag’s renderstate if created with the ‘not’ operator.
Attributes included from ContainerTag
Attributes inherited from AttrTag
Attributes inherited from CodeTag
Attributes inherited from Tag
Attributes inherited from Node
Instance Method Summary collapse
-
#initialize(body, linenum = nil, colnum = nil) ⇒ UnlessTag
constructor
Create a new UnlessTag.
-
#render(state) ⇒ Object
Render the tag’s contents if the condition is true, or any else or elsif sections if the condition isn’t true.
Methods included from ContainerTag
#<<, #is_container?, #render_subnodes
Methods inherited from AttrTag
Methods inherited from CodeTag
inherit_tag_patterns, tag_pattern, tag_patterns
Methods included from AbstractClass
Methods included from AbstractClass::ClassMethods
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 inherited from Node
#after_appending, #after_rendering, #as_comment_body, #before_appending, #before_rendering, #is_container?, #location
Constructor Details
#initialize(body, linenum = nil, colnum = nil) ⇒ UnlessTag
Create a new UnlessTag.
40 41 42 43 |
# File 'lib/inversion/template/unlesstag.rb', line 40 def initialize( body, linenum=nil, colnum=nil ) @inverted = false super end |
Instance Attribute Details
#inverted ⇒ Object
Invert the tag’s renderstate if created with the ‘not’ operator.
46 47 48 |
# File 'lib/inversion/template/unlesstag.rb', line 46 def inverted @inverted end |
Instance Method Details
#render(state) ⇒ Object
Render the tag’s contents if the condition is true, or any else or elsif sections if the condition isn’t true.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/inversion/template/unlesstag.rb', line 51 def render( state ) evaluated_state = self.evaluate( state ) evaluated_state = ! evaluated_state if self.inverted # Start out with rendering *disabled* if the tag body evaluates trueishly if evaluated_state self.log.debug "Initial state was TRUE; disabling rendering" state.disable_rendering else self.log.debug "Initial state was FALSE; enabling rendering" state.enable_rendering end # Set the tag state to track whether or not rendering has been enabled during the # 'unless' for an 'else' tag. state.with_tag_data( :rendering_was_enabled => state.rendering_enabled? ) do self.render_subnodes( state ) end state.enable_rendering return nil end |