Class: Arrow::Template::AttributeDirective

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

Overview

The attribute directive superclass. Attribute directives are those that present an exterior interface to the controlling system for message-passing and content-injection (e.g., <?attr?>, <?set?>, <?config?>, etc.)

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 Node

#type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Directive

create, derivativeDirs

Methods inherited from Node

#add_to_template, #to_a, #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) ⇒ AttributeDirective

Initialize a new AttributeDirective with the given tag name, template parser, and parser state.



369
370
371
372
373
374
# File 'lib/arrow/template/nodes.rb', line 369

def initialize( type, parser, state ) # :notnew:
	@name = nil
	@format = nil
	@methodchain = nil
	super
end

Instance Attribute Details

#formatObject

The format string that was specified with the directive, if any



386
387
388
# File 'lib/arrow/template/nodes.rb', line 386

def format
  @format
end

#methodchainObject

The source code for the methodchain that will be used to render the attribute.



383
384
385
# File 'lib/arrow/template/nodes.rb', line 383

def methodchain
  @methodchain
end

#nameObject (readonly)

The name of the directive, which is used to associate it with a attribute in the template the node belongs to.



390
391
392
# File 'lib/arrow/template/nodes.rb', line 390

def name
  @name
end

Class Method Details

.allows_format?Boolean

Returns true for classes that support a prepended format. (e.g., <?call “%15s” % foo ?>).

Returns:

  • (Boolean)


358
359
360
# File 'lib/arrow/template/nodes.rb', line 358

def self::allows_format?
	true
end

Instance Method Details

#before_rendering(template) ⇒ Object

Try to pre-render any attributes which correspond to this node.



402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'lib/arrow/template/nodes.rb', line 402

def before_rendering( template )
	if attrib = template[ self.name ]
		# self.log.debug "  got %s attribute in #before_rendering for %p" %
			# [ attrib.class.name, self.name ]

		if attrib.respond_to?( :before_rendering )
			# self.log.debug "  pre-rendering attribute %p" % [attrib]
			attrib.before_rendering( template )
		elsif attrib.respond_to?( :each )
			# self.log.debug "  iterating over attribute %p" % [attrib]
			attrib.each do |obj|
				obj.before_rendering if obj.respond_to?( :before_rendering )
			end
		end
	else
		# No-op
		# self.log.debug "  no value for node %p in #before_rendering" %
			# self.name
	end
end

#inspectObject

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



436
437
438
439
440
441
442
443
# File 'lib/arrow/template/nodes.rb', line 436

def inspect
	%Q{<%s %s%s (Format: %p)>} % [
		@type.capitalize,
		@name,
		@methodchain.strip.empty? ? "" : @methodchain,
		@format,
	]
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)


396
397
398
# File 'lib/arrow/template/nodes.rb', line 396

def is_rendering_node?
	true
end

#render(template, scope) ⇒ Object

Render the directive node’s contents as a String and return it.



425
426
427
428
429
430
431
# File 'lib/arrow/template/nodes.rb', line 425

def render( template, scope )
	# self.log.debug "Rendering %p" % self
	rary = super

	rary.push( *(self.render_contents( template, scope )) )
	return rary
end

#to_htmlObject

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



448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
# File 'lib/arrow/template/nodes.rb', line 448

def to_html
	html = ''
	if @format
		html << %q{"%s" %% } % self.escape_html( @format )
	end
	html << %q{<strong>#%s</strong>} % @name
	if @methodchain
		html << self.escape_html( @methodchain )
	end

	if block_given?
		html << " " << yield
	end

	super { html }
end