Class: Arrow::Template::BracketingDirective

Inherits:
AttributeDirective show all
Defined in:
lib/arrow/template/nodes.rb

Overview

The base bracketing directive class. Bracketing directives are branching, filtering, and repetition directives in the template’s AST (e.g., , ).

Direct Known Subclasses

ExportDirective, ForDirective, IfDirective, SelectListDirective, UnlessDirective, YieldDirective

Constant Summary

SVNRev =

SVN Revision

%q$Rev$
SVNId =

SVN Id

%q$Id$

Constants inherited from AttributeDirective

SVNId, SVNRev

Constants inherited from Directive

SVNId, SVNRev

Constants inherited from Node

SVNId, SVNRev

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 Attribute Summary

Instance Method Summary

Methods inherited from AttributeDirective

allows_format?, #before_rendering, #build_rendering_proc, #call_methodchain, #render

Methods inherited from Directive

create, derivativeDirs, #render

Methods inherited from Node

#css_class, #render, #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

#log

Constructor Details

- (BracketingDirective) initialize(type, parser, state)

Initialize a new BracketingDirective object with the specified type, parser, and state.



572
573
574
575
# File 'lib/arrow/template/nodes.rb', line 572

def initialize( type, parser, state ) # :notnew:
  @subnodes = []
  super
end

Instance Attribute Details

- (Object) subnodes (readonly)

The node’s contained subnodes tree



583
584
585
# File 'lib/arrow/template/nodes.rb', line 583

def subnodes
  @subnodes
end

Instance Method Details

- (Object) add_to_template(template)

Install the behaviour defined by the directive and its subnodes into the given template object. This by default just installs each of its subnodes.



597
598
599
600
601
602
# File 'lib/arrow/template/nodes.rb', line 597

def add_to_template( template )
  super
  self.subnodes.each do |node|
    template.install_node( node )
  end
end

- (Object) inspect

Return a human-readable version of the object suitable for debugging messages.



607
608
609
610
611
612
613
614
# File 'lib/arrow/template/nodes.rb', line 607

def inspect
  %Q{<%s %s%s: %p>} % [
    @type.capitalize,
    @name,
    @methodchain.strip.empty? ? "" : @methodchain,
    @subnodes,
  ]
end

- (Boolean) is_rendering_node?

Returns true for nodes which generate output themselves (as opposed to ones which generate output through subnodes). This is used for eliding blank lines from the node tree.

Returns:

  • (Boolean)


589
590
591
# File 'lib/arrow/template/nodes.rb', line 589

def is_rendering_node?
  false
end

- (Object) parse_directive_contents(parser, state) (protected)

Parse the contents of the directive. If a block is given (ie., by a subclass’s implementation), call it immediately after parsing an optional format, mandatory identifier, and optional methodchain. Then look for the end of the current directive tag, and recurse into the parser for any nodes contained between this directive and its .



653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
# File 'lib/arrow/template/nodes.rb', line 653

def parse_directive_contents( parser, state )
  super

  # Let subclasses implement further inner-tag parsing if they want
  # to.
  if block_given?
    rval = yield( parser, state )
    return nil if !rval
  end

  # Put the pointer after the closing tag 
  parser.scan_for_tag_ending( state ) or
    raise Arrow::ParseError, "couldn't find tag end for '#@name'"

  # Parse the content between this directive and the next <?end?>.
  @subnodes.replace( parser.scan_for_nodes(state, type, self) )

  return true
end

- (Object) render_contents(template, scope) (protected)

Use the contents of the associated attribute to render the receiver’s subnodes in the specified scope.



676
677
678
679
# File 'lib/arrow/template/nodes.rb', line 676

def render_contents( template, scope )
  res = super
  self.render_subnodes( res, template, scope )
end

- (Object) render_subnodes(item, template, scope) (protected)

Render each of the directive’s bracketed nodes with the given item, template, and evaluation scope.



684
685
686
687
688
# File 'lib/arrow/template/nodes.rb', line 684

def render_subnodes( item, template, scope )
  template.with_overridden_attributes( scope, self.name => item ) do |template|
    template.render( @subnodes, scope )
  end
end

- (Object) to_a

Return the receiver and any subnodes as a flattened Array of nodes.



618
619
620
621
622
623
# File 'lib/arrow/template/nodes.rb', line 618

def to_a
  ary = [self]
  @subnodes.each {|node| ary += node.to_a }

  return ary
end

- (Object) to_html

Return an HTML fragment that can be used to represent the node symbolically in a web-based introspection interface.



628
629
630
631
632
633
634
635
636
637
638
639
# File 'lib/arrow/template/nodes.rb', line 628

def to_html
  nodeclass = self.css_class

  super {
    %q{<div class="node-subtree %s-subtree">
      <div class="node-subtree-head %s-subtree-head"
      >Subnodes</div>%s</div>} % [
      nodeclass, nodeclass,
      @subnodes.collect {|node| node.to_html}.join
    ]
  }
end