Class: Arrow::Template::SetDirective

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

Overview

The Arrow::Template::SetDirective class, a derivative of Arrow::Template::Directive. This is the class which defines the behaviour of the ‘set’ template directive.

Syntax

  <?set foo 1?>

Authors

  • Michael Granger

Please see the file LICENSE in the top-level directory for licensing details.

Constant Summary

SVNRev =

SVN Revision

%q$Rev$
SVNId =

SVN Id

%q$Id$

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 Directive

create, derivativeDirs, #inspect, #to_html

Methods inherited from Node

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

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

Create and return a new Arrow::Template::SetDirective object.



29
30
31
32
33
34
# File 'lib/arrow/template/set.rb', line 29

def initialize( type, parser, state )
  @name = nil
  @value = nil

  super
end

Instance Attribute Details

- (Object) name (readonly)

The name of the definition set by this directive.



42
43
44
# File 'lib/arrow/template/set.rb', line 42

def name
  @name
end

- (Object) value (readonly)

The raw (unevaluated) value of the definition



45
46
47
# File 'lib/arrow/template/set.rb', line 45

def value
  @value
end

Instance Method Details

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

Parse the contents of the directive.



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/arrow/template/set.rb', line 71

def parse_directive_contents( parser, state )
  @name = parser.scan_for_identifier( state )

  state.scanner.skip( /\s*=\s*/ )

  @value = parser.scan_for_identifier( state ) ||
    parser.scan_for_quoted_string( state ) or
    raise Arrow::ParseError, "No value for 'set' directive"

  if (( chain = parser.scan_for_methodchain(state) ))
    @value << chain
  end
end

- (Object) render(template, scope)

Render the directive. This adds the defined variable to the template’s rendering scope and returns an empty string (or a comment if :debuggingComments is turned on in the template.



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/arrow/template/set.rb', line 51

def render( template, scope )
  rval = super

  self.log.debug "Evaling <%s> for 'set' directive." % @value
  template[@name] = eval( @value, scope.get_binding, __FILE__, __LINE__ )

  if template._config[:debuggingComments]
    rval << template.render_comment( "Set '%s' to '%s'" %
      [ @name, template[@name] ] )
  end

  return rval
end