Class: Arrow::Template::IncludeDirective
- Includes:
- Parser::Patterns
- Defined in:
- lib/arrow/template/include.rb
Overview
The Arrow::Template::IncludeDirective class, a derivative of Arrow::Template::Directive. This is the class which defines the behaviour of the ‘include’ template directive.
Syntax
<!-- Include a subtemplate directly -->
<?include subtemplate.tmpl ?>
<!-- Include a subtemplate as a callable sub-entity -->
<?include subtemplate.tmpl as sub ?>
Example
If ‘subtemplate.tmpl’ contains:
<?attr foo?>
and the main template contains:
<?include subtemplate.tmpl?>
<?include subtemplate.tmpl as sub?>
and the code (template
is the Template object) looks like:
template.foo = "argle"
template.sub.foo = "bargle"
the template will render as:
argle
Authors
-
Michael Granger <[email protected]>
Please see the file LICENSE in the top-level directory for licensing details.
Constant Summary collapse
- SVNRev =
SVN Revision
%q$Rev$
- SVNId =
SVN Id
%q$Id$
Constants included from Parser::Patterns
Parser::Patterns::ALTERNATION, Parser::Patterns::ARGDEFAULT, Parser::Patterns::ARGUMENT, Parser::Patterns::CAPTURE, Parser::Patterns::COMMA, Parser::Patterns::DBLQSTRING, Parser::Patterns::DOT, Parser::Patterns::EQUALS, Parser::Patterns::IDENTIFIER, Parser::Patterns::INFIX, Parser::Patterns::LBRACKET, Parser::Patterns::NUMBER, Parser::Patterns::PATHNAME, Parser::Patterns::QUOTEDSTRING, Parser::Patterns::RBRACKET, Parser::Patterns::REBINDOP, Parser::Patterns::REGEXP, Parser::Patterns::SLASHQSTRING, Parser::Patterns::SYMBOL, Parser::Patterns::TAGCLOSE, Parser::Patterns::TAGMIDDLE, Parser::Patterns::TAGOPEN, Parser::Patterns::TICKQSTRING, Parser::Patterns::VARIABLE, Parser::Patterns::WHITESPACE
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
-
#identifier ⇒ Object
(also: #name)
The identifier associated with an include that has an ‘as <name>’ part.
-
#subtemplate ⇒ Object
The template object associated with an include that has an ‘as <name>’ part.
Attributes inherited from Node
Instance Method Summary collapse
-
#add_to_template(template) ⇒ Object
Add the nodes that were included to the given
template
object. -
#initialize(type, parser, state) ⇒ IncludeDirective
constructor
Initialize a new IncludeDirective object.
-
#render(template, scope) ⇒ Object
Render the include.
-
#to_html ⇒ Object
Return an HTML fragment that can be used to represent the node symbolically in a web-based introspection interface.
Methods inherited from Directive
create, derivativeDirs, #inspect
Methods inherited from Node
#inspect, #is_rendering_node?, #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) ⇒ IncludeDirective
Initialize a new IncludeDirective object.
54 55 56 57 58 59 60 61 |
# File 'lib/arrow/template/include.rb', line 54 def initialize( type, parser, state ) # :notnew: @nodes = nil @identifier = nil @subtemplate = nil state[:includeStack] ||= [] super end |
Instance Attribute Details
#identifier ⇒ Object Also known as: name
The identifier associated with an include that has an ‘as <name>’ part.
70 71 72 |
# File 'lib/arrow/template/include.rb', line 70 def identifier @identifier end |
#subtemplate ⇒ Object
The template object associated with an include that has an ‘as <name>’ part.
76 77 78 |
# File 'lib/arrow/template/include.rb', line 76 def subtemplate @subtemplate end |
Instance Method Details
#add_to_template(template) ⇒ Object
Add the nodes that were included to the given template
object.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/arrow/template/include.rb', line 80 def add_to_template( template ) #self.log.debug "Installing an include's subnodes" if @identifier template.install_node( self ) template.send( "#{@identifier}=", @subtemplate ) targetTemplate = @subtemplate else targetTemplate = template end @nodes.each do |node| targetTemplate.install_node( node ) end end |
#render(template, scope) ⇒ Object
Render the include.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/arrow/template/include.rb', line 98 def render( template, scope ) rary = super # Render the included nodes if @subtemplate #self.log.debug "Rendering an include's subtemplate" rary.push( *(@subtemplate.render) ) else #self.log.debug "Rendering an include's subnodes" rary.push( *(template.render( @nodes, scope )) ) end return rary end |
#to_html ⇒ Object
Return an HTML fragment that can be used to represent the node symbolically in a web-based introspection interface.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/arrow/template/include.rb', line 116 def to_html nodeclass = self.css_class if @subtemplate subtree = @subtemplate._syntax_tree html = '' html << %q{<strong>#%s</strong> } % @identifier html << %q{<div class="node-subtemplate %s-node-subtemplate"> <div class="node-subtemplate-head %s-node-subtemplate-head" >Subtemplate</div>%s</div>} % [ nodeclass, nodeclass, subtree.collect {|node| node.to_html}.join(''), ] super { html } else super { %q{<div class="node-subtree %s-node-subtree"> <div class="node-subtree-head %s-node-subtree-head" >Subnodes</div>%s</div>} % [ nodeclass, nodeclass, @nodes.collect {|node| node.to_html}.join ] } end end |