Class: Temple::Engine
- Inherits:
-
Object
- Object
- Temple::Engine
- Extended by:
- Mixins::EngineDSL
- Includes:
- Mixins::EngineDSL, Mixins::Options
- Defined in:
- lib/temple/engine.rb
Overview
An engine is simply a chain of compilers (that often includes a parser, some filters and a generator).
class MyEngine < Temple::Engine
# First run MyParser, passing the :strict option
use MyParser, :strict
# Then a custom filter
use MyFilter
# Then some general optimizations filters
filter :MultiFlattener
filter :StaticMerger
filter :DynamicInliner
# Finally the generator
generator :ArrayBuffer, :buffer
end
class SpecialEngine < MyEngine
append MyCodeOptimizer
before :ArrayBuffer, Temple::Filters::Validator
replace :ArrayBuffer, Temple::Generators::RailsOutputBuffer
end
engine = MyEngine.new(:strict => "For MyParser")
engine.call(something)
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- (Object) chain
readonly
Returns the value of attribute chain.
Attributes included from Mixins::Options
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) call(input)
-
- (Engine) initialize(o = {})
constructor
A new instance of Engine.
Methods included from Mixins::EngineDSL
after, append, before, filter, generator, prepend, remove, replace
Methods included from Mixins::Options
Constructor Details
- (Engine) initialize(o = {})
A new instance of Engine
42 43 44 45 46 |
# File 'lib/temple/engine.rb', line 42 def initialize(o = {}) super @chain = self.class.chain.dup [*[:chain]].compact.each {|block| block.call(self) } end |
Instance Attribute Details
- (Object) chain (readonly)
Returns the value of attribute chain
36 37 38 |
# File 'lib/temple/engine.rb', line 36 def chain @chain end |
Class Method Details
+ (Object) chain
38 39 40 |
# File 'lib/temple/engine.rb', line 38 def self.chain @chain ||= superclass.respond_to?(:chain) ? superclass.chain.dup : [] end |
Instance Method Details
- (Object) call(input)
48 49 50 |
# File 'lib/temple/engine.rb', line 48 def call(input) call_chain.inject(input) {|m, e| e.call(m) } end |