Class: 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
- #chain ⇒ Object readonly
Attributes included from Mixins::Options
Class Method Summary collapse
Instance Method Summary collapse
- #call(input) ⇒ Object
-
#initialize(opts = {}) ⇒ Engine
constructor
A new instance of Engine.
Methods included from Mixins::EngineDSL
after, append, before, prepend, remove, replace
Methods included from Mixins::Options
Constructor Details
#initialize(opts = {}) ⇒ Engine
Returns a new instance of Engine.
45 46 47 48 |
# File 'lib/temple/engine.rb', line 45 def initialize(opts = {}) super @chain = self.class.chain.dup end |
Instance Attribute Details
Class Method Details
.chain ⇒ Object
41 42 43 |
# File 'lib/temple/engine.rb', line 41 def self.chain @chain ||= superclass.respond_to?(:chain) ? superclass.chain.dup : [] end |
Instance Method Details
#call(input) ⇒ Object
50 51 52 |
# File 'lib/temple/engine.rb', line 50 def call(input) call_chain.inject(input) {|m, e| e.call(m) } end |