Module: Flott
- Defined in:
- lib/flott.rb,
lib/flott/cache.rb,
lib/flott/version.rb
Overview
This module includes the Flott::Parser class, that can be used to compile Flott template files to Flott::Template objects, which can then be evaluted in a Flott::Environment.
Defined Under Namespace
Modules: EnvironmentMixin, FilenameMixin Classes: Cache, CallError, CompileError, Environment, EvalError, FlottException, Parser, ParserError, SecurityViolation, Template
Constant Summary collapse
- VERSION =
Flott version
'1.0.1'
- VERSION_ARRAY =
:nodoc:
VERSION.split(/\./).map { |x| x.to_i }
- VERSION_MAJOR =
:nodoc:
VERSION_ARRAY[0]
- VERSION_MINOR =
:nodoc:
VERSION_ARRAY[1]
- VERSION_BUILD =
:nodoc:
VERSION_ARRAY[2]
Class Attribute Summary collapse
-
.debug ⇒ Object
True switches debugging mode on, false off.
Class Method Summary collapse
-
.compile(source, workdir = nil, rootdir = nil, filename = nil) ⇒ Object
Return the compiled template of
source
while passing the remaining arguments through to Flott::Parser.new. -
.evaluate(compiled, env = Environment.new, &block) ⇒ Object
The already compiled ruby code is evaluated in the environment env.
-
.evaluate_file(filename, env = Environment.new, &block) ⇒ Object
Evaluate the template file filename in environment env and with the block block.
-
.evaluate_source(source, env = Environment.new, &block) ⇒ Object
Evaluate the template source source in environment env and with the block block.
-
.string_from_file(filename, env = Environment.new, &block) ⇒ Object
Create an output string from the template file filename, evaluated in the Environment env.
-
.string_from_source(source, env = Environment.new, &block) ⇒ Object
Create an output string from template source source, evaluated in the Environment env.
Class Attribute Details
.debug ⇒ Object
True switches debugging mode on, false off. Defaults to false.
35 36 37 |
# File 'lib/flott.rb', line 35 def debug @debug end |
Class Method Details
.compile(source, workdir = nil, rootdir = nil, filename = nil) ⇒ Object
Return the compiled template of source
while passing the remaining arguments through to Flott::Parser.new.
39 40 41 42 |
# File 'lib/flott.rb', line 39 def compile(source, workdir = nil, rootdir = nil, filename = nil) parser = Flott::Parser.new(source, workdir, rootdir, filename) parser.compile end |
.evaluate(compiled, env = Environment.new, &block) ⇒ Object
The already compiled ruby code is evaluated in the environment env. If no environment is given, a newly created environment is used. This method doesn’t return the result directly, only via the effects on the environment.
47 48 49 50 51 52 53 54 |
# File 'lib/flott.rb', line 47 def evaluate(compiled, env = Environment.new, &block) if !(EnvironmentMixin === env) and env.respond_to? :to_hash env = Environment.new.update(env.to_hash) end env.instance_eval(&block) if block compiled.evaluate(env) self end |
.evaluate_file(filename, env = Environment.new, &block) ⇒ Object
Evaluate the template file filename in environment env and with the block block. If no environment is given, a newly created environment is used. This method doesn’t return the result directly, only via the effects on the environment.
74 75 76 77 78 79 80 81 82 |
# File 'lib/flott.rb', line 74 def evaluate_file(filename, env = Environment.new, &block) if !(EnvironmentMixin === env) and env.respond_to? :to_hash env = Environment.new.update(env.to_hash) end env.instance_eval(&block) if block parser = Parser.from_filename(filename) parser.evaluate(env) self end |
.evaluate_source(source, env = Environment.new, &block) ⇒ Object
Evaluate the template source source in environment env and with the block block. If no environment is given, a newly created environment is used. This method doesn’t return the result directly, only via the effects on the environment.
60 61 62 63 64 65 66 67 68 |
# File 'lib/flott.rb', line 60 def evaluate_source(source, env = Environment.new, &block) if !(EnvironmentMixin === env) and env.respond_to? :to_hash env = Environment.new.update(env.to_hash) end env.instance_eval(&block) if block parser = Parser.new(source) parser.evaluate(env) self end |
.string_from_file(filename, env = Environment.new, &block) ⇒ Object
Create an output string from the template file filename, evaluated in the Environment env. If block is given it is evaluated in the env context as well. This will set the rootdir and workdir attributes, in order to dynamic include other templates into this one.
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/flott.rb', line 103 def string_from_file(filename, env = Environment.new, &block) if !(EnvironmentMixin === env) and env.respond_to? :to_hash env = Environment.new.update(env.to_hash) end output = '' env.output = output env.instance_eval(&block) if block parser = Parser.from_filename(filename) parser.evaluate(env) env.output end |
.string_from_source(source, env = Environment.new, &block) ⇒ Object
Create an output string from template source source, evaluated in the Environment env. If block is given it is evaluated in the env context as well.
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/flott.rb', line 87 def string_from_source(source, env = Environment.new, &block) if !(EnvironmentMixin === env) and env.respond_to? :to_hash env = Environment.new.update(env.to_hash) end output = '' env.output = output env.instance_eval(&block) if block parser = Parser.new(source) parser.evaluate(env) env.output end |