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., <?foreach?>, <?if?>).

Constant Summary collapse

SVNRev =

SVN Revision

%q$Rev$
SVNId =

SVN Id

%q$Id$

Constants included from HTMLUtilities

HTMLUtilities::ARRAY_HTML_CONTAINER, HTMLUtilities::HASH_HTML_CONTAINER, HTMLUtilities::HASH_PAIR_HTML, HTMLUtilities::IMMEDIATE_OBJECT_HTML_CONTAINER, HTMLUtilities::IVAR_HTML_FRAGMENT, HTMLUtilities::OBJECT_HTML_CONTAINER, HTMLUtilities::THREAD_DUMP_KEY

Instance Attribute Summary collapse

Attributes inherited from AttributeDirective

#format, #methodchain, #name

Attributes inherited from Node

#type

Instance Method Summary collapse

Methods inherited from AttributeDirective

allows_format?, #before_rendering, #render

Methods inherited from Directive

create, derivativeDirs, #render

Methods inherited from Node

#render, #to_s

Methods included from HTMLUtilities

escape_html, make_html_for_object, make_object_html_wrapper

Methods inherited from Object

deprecate_class_method, deprecate_method, inherited

Constructor Details

#initialize(type, parser, state) ⇒ BracketingDirective

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

#subnodesObject (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

#add_to_template(template) ⇒ Object

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

#inspectObject

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

#is_rendering_node?Boolean

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

#to_aObject

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

#to_htmlObject

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