Class: Arrow::Template::Directive

Inherits:
Node show all
Includes:
PluginFactory
Defined in:
lib/arrow/template/nodes.rb

Overview

The abstract directive superclass. Instances of derivatives of this class define template behaviour and content.

Direct Known Subclasses

AttributeDirective, ElseDirective, ImportDirective, IncludeDirective, SetDirective

Constant Summary

SVNRev =

SVN Revision

%q$Rev$
SVNId =

SVN Id

%q$Id$

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

Class Method Summary

Instance Method Summary

Methods inherited from Node

#add_to_template, #css_class, #is_rendering_node?, #to_a, #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

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

Initialize a new Directive with the given type (the directive name), parser (Arrow::Template::Parser), and state (Arrow::Template::Parser::State object).



280
281
282
283
# File 'lib/arrow/template/nodes.rb', line 280

def initialize( type, parser, state )
  super( type )
  self.parse_directive_contents( parser, state )
end

Class Method Details

+ (Object) create(tag, parser, state)

Factory method: overridden from PluginFactory.create to pass the name into constructors for parsing context.



268
269
270
# File 'lib/arrow/template/nodes.rb', line 268

def self::create( tag, parser, state )
  super( tag, tag, parser, state )
end

+ (Object) derivativeDirs

Return the list of subdirectories to search for template nodes.



261
262
263
# File 'lib/arrow/template/nodes.rb', line 261

def self::derivativeDirs
  ["arrow/template"]
end

Instance Method Details

- (Object) inspect

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



302
303
304
# File 'lib/arrow/template/nodes.rb', line 302

def inspect
  %Q{<%s Directive>} % [ @type.capitalize ]
end

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

Parse the contents of the directive. This is a no-op for this class; it’s here to allow delegation of this task to subclasses.



332
333
# File 'lib/arrow/template/nodes.rb', line 332

def parse_directive_contents( parser, state )
end

- (Object) render(template, scope)

Render the directive as a String and return it.



291
292
293
294
295
296
297
# File 'lib/arrow/template/nodes.rb', line 291

def render( template, scope )
  rary = []
  rary << template.render_comment( self.inspect ) if
    template._config[:debuggingComments]

  return rary
end

- (Object) to_html

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



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/arrow/template/nodes.rb', line 309

def to_html

  if block_given?
    callback = Proc.new
    super( &callback )
  else
    fields = instance_variables.sort.collect {|ivar|
      val = instance_variable_get( ivar )
      %q{<span class="ivar"><em>%s:</em> %s</span>} %
        [ ivar, self.escape_html(val) ]
    }

    super { fields.join(", ") }
  end
end