Class: PageTemplate::Template

Inherits:
BlockCommand show all
Includes:
NamespaceItem
Defined in:
lib/PageTemplate/commands.rb

Overview

Template is the top-level blockcommand object It is what is returned on Template.load() or Template.parse()

Template should only be called by the Parser, and never by anything else.

Instance Attribute Summary

Attributes included from NamespaceItem

#object, #parent

Attributes inherited from Command

#called_as

Instance Method Summary collapse

Methods included from NamespaceItem

#clear, #delete, #get, #parser, #set, #true?

Methods inherited from BlockCommand

#add, #length

Constructor Details

#initialize(parser) ⇒ Template

Template must know about the parser so it can access its namespace.



159
160
161
162
# File 'lib/PageTemplate/commands.rb', line 159

def initialize(parser)
  @parser = parser
  super()
end

Instance Method Details

#output(object = nil) ⇒ Object

Template#output is a special case for a Command. Because Template is what’s returned by Parser.load() or Parser.parse(), the programmer may well call Template#output(anything).

If object is a Namespace, then treat output as a typical BlockCommand. If object is nil, then namespace is child of @namespace, and is assigned object as its namespace



178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/PageTemplate/commands.rb', line 178

def output(object=nil)
  @parent = @parser
  case
  when object.nil?
    super(self)
  when object.is_a?(NamespaceItem)
    @parent = object
    super(self)
  else
    namespace = Namespace.new(self)
    namespace.object = object
    super(namespace)
  end
end

#to_sObject



163
164
165
# File 'lib/PageTemplate/commands.rb', line 163

def to_s
  '[ Template: ' + @commandBlock.map{ |i| "[#{i.to_s}]" }.join(' ') + ']'
end