class Temple::Generator
Abstract generator base class Generators
should inherit this class and compile the Core Abstraction to ruby code.
@api public
Public Instance Methods
Source
# File lib/temple/generator.rb, line 18 def call(exp) [preamble, compile(exp), postamble].flatten.compact.join('; ') end
Source
# File lib/temple/generator.rb, line 45 def on(*exp) raise InvalidExpression, "Generator supports only core expressions - found #{exp.inspect}" end
Source
# File lib/temple/generator.rb, line 57 def on_capture(name, exp) capture_generator.new(capture_generator: options[:capture_generator], freeze_static: options[:freeze_static], buffer: name).call(exp) end
Source
# File lib/temple/generator.rb, line 67 def on_dynamic(code) concat(code) end
Source
# File lib/temple/generator.rb, line 49 def on_multi(*exp) exp.map {|e| compile(e) }.join('; '.freeze) end
Source
# File lib/temple/generator.rb, line 63 def on_static(text) concat(options[:freeze_static] ? "#{text.inspect}.freeze" : text.inspect) end
Source
# File lib/temple/generator.rb, line 26 def postamble [return_buffer, restore_buffer] end
Source
# File lib/temple/generator.rb, line 22 def preamble [save_buffer, create_buffer] end
Source
# File lib/temple/generator.rb, line 34 def restore_buffer "ensure; #{buffer} = #{@original_buffer}; end" if options[:save_buffer] end
Source
# File lib/temple/generator.rb, line 30 def save_buffer "begin; #{@original_buffer = unique_name} = #{buffer} if defined?(#{buffer})" if options[:save_buffer] end
Protected Instance Methods
Source
# File lib/temple/generator.rb, line 81 def capture_generator @capture_generator ||= Class === options[:capture_generator] ? options[:capture_generator] : Generators.const_get(options[:capture_generator]) end
Source
# File lib/temple/generator.rb, line 87 def concat(str) "#{buffer} << (#{str})" end