Class: PageTemplate::ValueCommand
- Defined in:
- lib/PageTemplate/commands.rb
Overview
ValueCommand will print out a variable name, possibly passing its value through a preprocessor.
- % var variable [:processor
-
%]
variable
is first plucked out of the Namespace,
The to_s of the output from Namespace#get is passed through parser’s preprocessor. If :processor is defined, then it is parser.preprocessor.send(:processor,body) is called, allowing the designer to choose a particular format for the output. If :processor is not given, then parser’s default processor is used.
Instance Attribute Summary
Attributes inherited from Command
Instance Method Summary collapse
-
#initialize(value, preprocessor) ⇒ ValueCommand
constructor
Creates the ValueCommand, with
value
as the name of the variable to be inserted during output. -
#output(namespace = nil) ⇒ Object
Requests the value of this object’s saved value name from
namespace
, and returns the string representation of that value to the caller, after passing it through the preprocessor. - #to_s ⇒ Object
Constructor Details
#initialize(value, preprocessor) ⇒ ValueCommand
Creates the ValueCommand, with value
as the name of the variable to be inserted during output. parser
is the Parser object, which we save so we can access its Preprocessor and its default preprocessor
230 231 232 233 |
# File 'lib/PageTemplate/commands.rb', line 230 def initialize(value,preprocessor) @value = value @processor = preprocessor end |
Instance Method Details
#output(namespace = nil) ⇒ Object
Requests the value of this object’s saved value name from namespace
, and returns the string representation of that value to the caller, after passing it through the preprocessor.
238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/PageTemplate/commands.rb', line 238 def output(namespace = nil) parser = namespace.parser if namespace parser = Parser.recent_parser unless parser namespace ||= parser preprocessor = parser.preprocessor processor = @processor || parser.default_processor if preprocessor.respond_to?(processor) preprocessor.send(processor,namespace.get(@value).to_s) else "[ ValueCommand: unknown preprocessor #{@processor} ]" end end |
#to_s ⇒ Object
251 252 253 254 255 256 |
# File 'lib/PageTemplate/commands.rb', line 251 def to_s str = "[ Value: #{@value} " str << ":#{@processor} " if (@processor) str << ']' str end |