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
call(exp)
click to toggle source
# File lib/temple/generator.rb, line 17 def call(exp) [preamble, compile(exp), postamble].flatten.compact.join('; ') end
create_buffer()
click to toggle source
# File lib/temple/generator.rb, line 37 def create_buffer end
on(*exp)
click to toggle source
# File lib/temple/generator.rb, line 44 def on(*exp) raise InvalidExpression, "Generator supports only core expressions - found #{exp.inspect}" end
on_capture(name, exp)
click to toggle source
# File lib/temple/generator.rb, line 56 def on_capture(name, exp) capture_generator.new(buffer: name).call(exp) end
on_code(code)
click to toggle source
# File lib/temple/generator.rb, line 68 def on_code(code) code end
on_dynamic(code)
click to toggle source
# File lib/temple/generator.rb, line 64 def on_dynamic(code) concat(code) end
on_multi(*exp)
click to toggle source
# File lib/temple/generator.rb, line 48 def on_multi(*exp) exp.map {|e| compile(e) }.join('; '.freeze) end
on_newline()
click to toggle source
# File lib/temple/generator.rb, line 52 def on_newline "\n" end
on_static(text)
click to toggle source
# File lib/temple/generator.rb, line 60 def on_static(text) concat(options[:freeze_static] ? "#{text.inspect}.freeze" : text.inspect) end
postamble()
click to toggle source
# File lib/temple/generator.rb, line 25 def postamble [return_buffer, restore_buffer] end
preamble()
click to toggle source
# File lib/temple/generator.rb, line 21 def preamble [save_buffer, create_buffer] end
restore_buffer()
click to toggle source
# File lib/temple/generator.rb, line 33 def restore_buffer "ensure; #{buffer} = #{@original_buffer}; end" if options[:save_buffer] end
return_buffer()
click to toggle source
# File lib/temple/generator.rb, line 40 def return_buffer 'nil' end
save_buffer()
click to toggle source
# File lib/temple/generator.rb, line 29 def save_buffer "begin; #{@original_buffer = unique_name} = #{buffer} if defined?(#{buffer})" if options[:save_buffer] end
Protected Instance Methods
buffer()
click to toggle source
# File lib/temple/generator.rb, line 74 def buffer options[:buffer] end
capture_generator()
click to toggle source
# File lib/temple/generator.rb, line 78 def capture_generator @capture_generator ||= Class === options[:capture_generator] ? options[:capture_generator] : Generators.const_get(options[:capture_generator]) end
concat(str)
click to toggle source
# File lib/temple/generator.rb, line 84 def concat(str) "#{buffer} << (#{str})" end