Class: Arrow::Template::UnlessDirective
- Inherits:
-
BracketingDirective
- Object
- Arrow::Object
- Node
- Directive
- AttributeDirective
- BracketingDirective
- Arrow::Template::UnlessDirective
- Includes:
- ConditionalDirective
- Defined in:
- lib/arrow/template/unless.rb
Overview
The Arrow::Template::UnlessDirective class, a derivative of Arrow::Template::BracketingDirective. Instances of this class represent a section of a template that is rendered conditionally.
The formats the directive supports are:
<?unless <name>?>...<?end unless?> <?unless <name>.<methodchain>?>...<?end unless?> <?unless <name> (matches|=~) <regex>?>...<?end unless?> <?unless <name>.<methodchain> (matches|=~) <regex>?>...<?end unless?>
Note that this directive does not support all possible Ruby expressions in the conditional, and must have a valid associated identifier (the name bit).
Authors
Michael Granger
Please see the file LICENSE in the top-level directory for licensing details.
Constant Summary
Constants included from ConditionalDirective
Constants inherited from BracketingDirective
Constants inherited from AttributeDirective
Constants inherited from Directive
Constants inherited from Node
Constants included from Arrow::HTMLUtilities
ARRAY_HTML_CONTAINER, HASH_HTML_CONTAINER, HASH_PAIR_HTML, IMMEDIATE_OBJECT_HTML_CONTAINER, IVAR_HTML_FRAGMENT, OBJECT_HTML_CONTAINER, THREAD_DUMP_KEY
Instance Method Summary
-
- (Object) render_contents(template, scope)
protected
Render the contents of the conditional if it evaluates to false, or the nodes after ‘elsif’ or ‘else’ subnodes if their conditions are met.
Methods included from ConditionalDirective
#evaluate, #is_rendering_node?
Methods inherited from BracketingDirective
#add_to_template, #initialize, #inspect, #is_rendering_node?, #parse_directive_contents, #render_subnodes, #to_a, #to_html
Methods inherited from AttributeDirective
allows_format?, #before_rendering, #build_rendering_proc, #call_methodchain, #initialize, #inspect, #is_rendering_node?, #parse_directive_contents, #render, #to_html
Methods inherited from Directive
create, derivativeDirs, #initialize, #inspect, #parse_directive_contents, #render, #to_html
Methods inherited from Node
#add_to_template, #css_class, #initialize, #inspect, #is_rendering_node?, #render, #to_a, #to_html, #to_s
Methods included from Arrow::HTMLUtilities
#escape_html, #make_html_for_object, #make_object_html_wrapper
Methods inherited from Arrow::Object
deprecate_class_method, deprecate_method, inherited
Methods included from Arrow::Loggable
Constructor Details
This class inherits a constructor from Arrow::Template::BracketingDirective
Instance Method Details
- (Object) render_contents(template, scope) (protected)
Render the contents of the conditional if it evaluates to false, or the nodes after ‘elsif’ or ‘else’ subnodes if their conditions are met.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/arrow/template/unless.rb', line 45 def render_contents( template, scope ) cond = has_been_true = !self.evaluate( template, scope ) nodes = [] # Now splice out the chunk of nodes that should be rendered based on # the conditional. @subnodes.each do |node| case node when Arrow::Template::ElsifDirective if !has_been_true cond = has_been_true = node.evaluate( template, scope ) else cond = false end when Arrow::Template::ElseDirective if !has_been_true cond = has_been_true = true else cond = false end else nodes.push( node ) if cond end end return template.render( nodes, scope ) end |