Class: PageTemplate::IncludeCommand
- Defined in:
- lib/PageTemplate/commands.rb
Overview
IncludeCommand allows the designer to include a template from another source.
- % include variable %
-
or [% include literal %]
If literal
exists in parser.source, then it is called without passing it to its namespace. If it does not exist, then it is evaluated within the context of its namespace and then passed to parser.source for fetching the body of the file/source.
The body returned by the Source is then passed to Parser for compilation.
Instance Attribute Summary
Attributes inherited from Command
Instance Method Summary collapse
-
#initialize(value) ⇒ IncludeCommand
constructor
A new instance of IncludeCommand.
-
#output(namespace) ⇒ Object
If @value exists in parser.source, then it is called without passing it to its namespace.
- #to_s ⇒ Object
Constructor Details
#initialize(value) ⇒ IncludeCommand
Returns a new instance of IncludeCommand.
523 524 525 |
# File 'lib/PageTemplate/commands.rb', line 523 def initialize(value) @value = value end |
Instance Method Details
#output(namespace) ⇒ Object
If @value exists in parser.source, then it is called without passing it to its namespace. If it does not exist, then it is evaluated within the context of its namespace and then passed to parser.source for fetching the body of the file/source.
The body returned by the Source is then passed to Parser for compilation.
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
# File 'lib/PageTemplate/commands.rb', line 536 def output(namespace) # We don't use parser.compile because we need to know when something # doesn't exist. parser = namespace.parser fn = @value body = parser.source.get(fn) unless body fn = namespace.get(@value) body = parser.source.get(fn) if fn end if body.is_a?(Command) body.output(namespace) elsif body cmds = parser.parse(body) parser.source.cache(fn,cmds) cmds.output(namespace) else "[ Template '#{fn}' not found ]" end end |
#to_s ⇒ Object
526 527 528 |
# File 'lib/PageTemplate/commands.rb', line 526 def to_s "[ Include: #{@value} ]" end |