Sha256: afe60a13b026e04d984830086bd6b5cd3af145d823d2c1276a94c01e763f7392
Contents?: true
Size: 1.51 KB
Versions: 2
Compression:
Stored size: 1.51 KB
Contents
module Temple # 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 # # engine = MyEngine.new(:strict => "For MyParser") # engine.compile(something) # class Engine include Mixins::Options def self.chain @chain ||= [] end def self.use(filter, *options, &block) default_options = Hash === options.last ? options.pop : {} chain << proc do |opts| filter.new(default_options.merge(Hash[*opts.select {|k,v| options.include?(k) }.flatten]), &block) end end # Shortcut for <tt>use Temple::Filters::parser</tt> def self.filter(filter, *options, &block) use(Temple::Filters.const_get(filter), *options, &block) end # Shortcut for <tt>use Temple::Generators::parser</tt> def self.generator(compiler, *options, &block) use(Temple::Generators.const_get(compiler), *options, &block) end def compile(input) chain.inject(input) {|m, e| e.compile(m) } end protected def chain @chain ||= self.class.chain.map { |f| f.call(options) } end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
temple-0.1.8 | lib/temple/engine.rb |
temple-0.1.7 | lib/temple/engine.rb |