The base bracketing directive class. Bracketing directives are branching, filtering, and repetition directives in the template‘s AST (e.g., <?foreach?>, <?if?>).
Install the behaviour defined by the directive and its subnodes into the given template object. This by default just installs each of its subnodes.
# File /Users/ged/source/ruby/Arrow/lib/arrow/template/nodes.rb, line 641 641: def add_to_template( template ) 642: super 643: self.subnodes.each do |node| 644: template.install_node( node ) 645: end 646: end
Return a human-readable version of the object suitable for debugging messages.
# File /Users/ged/source/ruby/Arrow/lib/arrow/template/nodes.rb, line 651 651: def inspect 652: %Q{<%s %s%s: %p>} % [ 653: @type.capitalize, 654: @name, 655: @methodchain.strip.empty? ? "" : @methodchain, 656: @subnodes, 657: ] 658: end
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.
# File /Users/ged/source/ruby/Arrow/lib/arrow/template/nodes.rb, line 633 633: def is_rendering_node? 634: false 635: end
Return the receiver and any subnodes as a flattened Array of nodes.
# File /Users/ged/source/ruby/Arrow/lib/arrow/template/nodes.rb, line 662 662: def to_a 663: ary = [self] 664: @subnodes.each {|node| ary += node.to_a } 665: 666: return ary 667: end
Return an HTML fragment that can be used to represent the node symbolically in a web-based introspection interface.
# File /Users/ged/source/ruby/Arrow/lib/arrow/template/nodes.rb, line 672 672: def to_html 673: nodeclass = self.css_class 674: 675: super { 676: %q{<div class="node-subtree %s-subtree"> 677: <div class="node-subtree-head %s-subtree-head" 678: >Subnodes</div>%s</div>} % [ 679: nodeclass, nodeclass, 680: @subnodes.collect {|node| node.to_html}.join 681: ] 682: } 683: end
Initialize a new BracketingDirective object with the specified type, parser, and state.
# File /Users/ged/source/ruby/Arrow/lib/arrow/template/nodes.rb, line 616 616: def initialize( type, parser, state ) # :notnew: 617: @subnodes = [] 618: super 619: end
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 <?end?>.
# File /Users/ged/source/ruby/Arrow/lib/arrow/template/nodes.rb, line 697 697: def parse_directive_contents( parser, state ) 698: super 699: 700: # Let subclasses implement further inner-tag parsing if they want 701: # to. 702: if block_given? 703: rval = yield( parser, state ) 704: return nil if !rval 705: end 706: 707: # Put the pointer after the closing tag 708: parser.scan_for_tag_ending( state ) or 709: raise Arrow::ParseError, "couldn't find tag end for '#@name'" 710: 711: # Parse the content between this directive and the next <?end?>. 712: @subnodes.replace( parser.scan_for_nodes(state, type, self) ) 713: 714: return true 715: end
Use the contents of the associated attribute to render the receiver‘s subnodes in the specified scope.
# File /Users/ged/source/ruby/Arrow/lib/arrow/template/nodes.rb, line 720 720: def render_contents( template, scope ) 721: res = super 722: self.render_subnodes( res, template, scope ) 723: end
Render each of the directive‘s bracketed nodes with the given item, template, and evaluation scope.
# File /Users/ged/source/ruby/Arrow/lib/arrow/template/nodes.rb, line 728 728: def render_subnodes( item, template, scope ) 729: template.with_overridden_attributes( scope, self.name => item ) do |template| 730: template.render( @subnodes, scope ) 731: end 732: end
--- SEC00157
--- ""
--- - name: subnodes rw: R a_desc: |+ The node‘s contained subnodes tree
--- - methods: - visibility: public aref: M000491 name: add_to_template sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/template/nodes.rb, line 641</span>\n\ 641: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">add_to_template</span>( <span class=\"ruby-identifier\">template</span> )\n\ 642: <span class=\"ruby-keyword kw\">super</span>\n\ 643: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">subnodes</span>.<span class=\"ruby-identifier\">each</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">node</span><span class=\"ruby-operator\">|</span>\n\ 644: <span class=\"ruby-identifier\">template</span>.<span class=\"ruby-identifier\">install_node</span>( <span class=\"ruby-identifier\">node</span> )\n\ 645: <span class=\"ruby-keyword kw\">end</span>\n\ 646: <span class=\"ruby-keyword kw\">end</span>" m_desc: |- <p> Install the behaviour defined by the directive and its subnodes into the given <tt>template</tt> object. This by default just installs each of its subnodes. </p> params: ( template ) - visibility: public aref: M000492 name: inspect sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/template/nodes.rb, line 651</span>\n\ 651: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">inspect</span>\n\ 652: <span class=\"ruby-value str\">%Q{<%s %s%s: %p>}</span> <span class=\"ruby-operator\">%</span> [\n\ 653: <span class=\"ruby-ivar\">@type</span>.<span class=\"ruby-identifier\">capitalize</span>,\n\ 654: <span class=\"ruby-ivar\">@name</span>,\n\ 655: <span class=\"ruby-ivar\">@methodchain</span>.<span class=\"ruby-identifier\">strip</span>.<span class=\"ruby-identifier\">empty?</span> <span class=\"ruby-value\">? </span><span class=\"ruby-value str\">""</span> <span class=\"ruby-operator\">:</span> <span class=\"ruby-ivar\">@methodchain</span>,\n\ 656: <span class=\"ruby-ivar\">@subnodes</span>,\n\ 657: ]\n\ 658: <span class=\"ruby-keyword kw\">end</span>" m_desc: |- <p> Return a human-readable version of the object suitable for debugging messages. </p> params: () - visibility: public aref: M000490 name: is_rendering_node? sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/template/nodes.rb, line 633</span>\n\ 633: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">is_rendering_node?</span>\n\ 634: <span class=\"ruby-keyword kw\">false</span>\n\ 635: <span class=\"ruby-keyword kw\">end</span>" m_desc: |- <p> Returns <tt>true</tt> 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. </p> params: () - visibility: public aref: M000493 name: to_a sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/template/nodes.rb, line 662</span>\n\ 662: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">to_a</span>\n\ 663: <span class=\"ruby-identifier\">ary</span> = [<span class=\"ruby-keyword kw\">self</span>]\n\ 664: <span class=\"ruby-ivar\">@subnodes</span>.<span class=\"ruby-identifier\">each</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">node</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">ary</span> <span class=\"ruby-operator\">+=</span> <span class=\"ruby-identifier\">node</span>.<span class=\"ruby-identifier\">to_a</span> }\n\ 665: \n\ 666: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-identifier\">ary</span>\n\ 667: <span class=\"ruby-keyword kw\">end</span>" m_desc: |- <p> Return the receiver and any subnodes as a flattened Array of nodes. </p> params: () - visibility: public aref: M000494 name: to_html sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/template/nodes.rb, line 672</span>\n\ 672: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">to_html</span>\n\ 673: <span class=\"ruby-identifier\">nodeclass</span> = <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">css_class</span>\n\ 674: \n\ 675: <span class=\"ruby-keyword kw\">super</span> {\n\ 676: <span class=\"ruby-value str\">%q{<div class="node-subtree %s-subtree">\n\ 677: <div class="node-subtree-head %s-subtree-head"\n\ 678: >Subnodes</div>%s</div>}</span> <span class=\"ruby-operator\">%</span> [\n\ 679: <span class=\"ruby-identifier\">nodeclass</span>, <span class=\"ruby-identifier\">nodeclass</span>,\n\ 680: <span class=\"ruby-ivar\">@subnodes</span>.<span class=\"ruby-identifier\">collect</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">node</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">node</span>.<span class=\"ruby-identifier\">to_html</span>}.<span class=\"ruby-identifier\">join</span>\n\ 681: ]\n\ 682: }\n\ 683: <span class=\"ruby-keyword kw\">end</span>" m_desc: |- <p> Return an HTML fragment that can be used to represent the node symbolically in a web-based introspection interface. </p> params: () category: Instance type: Public - methods: - visibility: protected aref: M000489 name: initialize sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/template/nodes.rb, line 616</span>\n\ 616: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">initialize</span>( <span class=\"ruby-identifier\">type</span>, <span class=\"ruby-identifier\">parser</span>, <span class=\"ruby-identifier\">state</span> ) <span class=\"ruby-comment cmt\"># :notnew:</span>\n\ 617: <span class=\"ruby-ivar\">@subnodes</span> = []\n\ 618: <span class=\"ruby-keyword kw\">super</span>\n\ 619: <span class=\"ruby-keyword kw\">end</span>" m_desc: |- <p> Initialize a new <a href="BracketingDirective.html">BracketingDirective</a> object with the specified <tt>type</tt>, <tt>parser</tt>, and <tt>state</tt>. </p> params: ( type, parser, state ) - visibility: protected aref: M000495 name: parse_directive_contents sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/template/nodes.rb, line 697</span>\n\ 697: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">parse_directive_contents</span>( <span class=\"ruby-identifier\">parser</span>, <span class=\"ruby-identifier\">state</span> )\n\ 698: <span class=\"ruby-keyword kw\">super</span>\n\ 699: \n\ 700: <span class=\"ruby-comment cmt\"># Let subclasses implement further inner-tag parsing if they want</span>\n\ 701: <span class=\"ruby-comment cmt\"># to.</span>\n\ 702: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">block_given?</span>\n\ 703: <span class=\"ruby-identifier\">rval</span> = <span class=\"ruby-keyword kw\">yield</span>( <span class=\"ruby-identifier\">parser</span>, <span class=\"ruby-identifier\">state</span> )\n\ 704: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">nil</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-operator\">!</span><span class=\"ruby-identifier\">rval</span>\n\ 705: <span class=\"ruby-keyword kw\">end</span>\n\ 706: \n\ 707: <span class=\"ruby-comment cmt\"># Put the pointer after the closing tag </span>\n\ 708: <span class=\"ruby-identifier\">parser</span>.<span class=\"ruby-identifier\">scan_for_tag_ending</span>( <span class=\"ruby-identifier\">state</span> ) <span class=\"ruby-keyword kw\">or</span>\n\ 709: <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">ParseError</span>, <span class=\"ruby-value str\">"couldn't find tag end for '#@name'"</span>\n\ 710: \n\ 711: <span class=\"ruby-comment cmt\"># Parse the content between this directive and the next <?end?>.</span>\n\ 712: <span class=\"ruby-ivar\">@subnodes</span>.<span class=\"ruby-identifier\">replace</span>( <span class=\"ruby-identifier\">parser</span>.<span class=\"ruby-identifier\">scan_for_nodes</span>(<span class=\"ruby-identifier\">state</span>, <span class=\"ruby-identifier\">type</span>, <span class=\"ruby-keyword kw\">self</span>) )\n\ 713: \n\ 714: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">true</span>\n\ 715: <span class=\"ruby-keyword kw\">end</span>" m_desc: |- <p> 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 <?end?>. </p> params: ( parser, state ) {|parser, state| ...} - visibility: protected aref: M000496 name: render_contents sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/template/nodes.rb, line 720</span>\n\ 720: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">render_contents</span>( <span class=\"ruby-identifier\">template</span>, <span class=\"ruby-identifier\">scope</span> )\n\ 721: <span class=\"ruby-identifier\">res</span> = <span class=\"ruby-keyword kw\">super</span>\n\ 722: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">render_subnodes</span>( <span class=\"ruby-identifier\">res</span>, <span class=\"ruby-identifier\">template</span>, <span class=\"ruby-identifier\">scope</span> )\n\ 723: <span class=\"ruby-keyword kw\">end</span>" m_desc: |- <p> Use the contents of the associated attribute to render the receiver‘s subnodes in the specified <tt>scope</tt>. </p> params: ( template, scope ) - visibility: protected aref: M000497 name: render_subnodes sourcecode: " <span class=\"ruby-comment cmt\"># File /Users/ged/source/ruby/Arrow/lib/arrow/template/nodes.rb, line 728</span>\n\ 728: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">render_subnodes</span>( <span class=\"ruby-identifier\">item</span>, <span class=\"ruby-identifier\">template</span>, <span class=\"ruby-identifier\">scope</span> )\n\ 729: <span class=\"ruby-identifier\">template</span>.<span class=\"ruby-identifier\">with_overridden_attributes</span>( <span class=\"ruby-identifier\">scope</span>, <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">name</span> =<span class=\"ruby-operator\">></span> <span class=\"ruby-identifier\">item</span> ) <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">template</span><span class=\"ruby-operator\">|</span>\n\ 730: <span class=\"ruby-identifier\">template</span>.<span class=\"ruby-identifier\">render</span>( <span class=\"ruby-ivar\">@subnodes</span>, <span class=\"ruby-identifier\">scope</span> )\n\ 731: <span class=\"ruby-keyword kw\">end</span>\n\ 732: <span class=\"ruby-keyword kw\">end</span>" m_desc: |- <p> Render each of the directive‘s bracketed nodes with the given <tt>item</tt>, <tt>template</tt>, and evaluation <tt>scope</tt>. </p> params: ( item, template, scope ) category: Instance type: Protected
---
--- - name: SVNRev desc: |+ SVN Revision value: "%q$Rev: 437 $" - name: SVNId desc: |+ SVN Id value: "%q$Id: nodes.rb 437 2008-03-28 00:49:20Z deveiant $"
Generated with the Darkfish Rdoc Generator.