Class: Temple::Generator

Inherits:
Object
  • Object
show all
Includes:
Mixins::Options
Defined in:
lib/temple/generators.rb

Overview

Abstract generator base class Generators should inherit this class and compile the Core Abstraction to ruby code.

Direct Known Subclasses

Temple::Generators::Array

Instance Attribute Summary

Attributes included from Mixins::Options

#options

Instance Method Summary collapse

Methods included from Mixins::Options

included, #initialize

Instance Method Details

#call(exp) ⇒ Object



18
19
20
# File 'lib/temple/generators.rb', line 18

def call(exp)
  [preamble, compile(exp), postamble].join('; ')
end

#compile(exp) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/temple/generators.rb', line 22

def compile(exp)
  type, *args = exp
  method = "on_#{type}"
  if respond_to?(method)
    send(method, *args)
  else
    raise InvalidExpression, "Generator supports only core expressions - found #{exp.inspect}"
  end
end

#on_capture(name, exp) ⇒ Object



40
41
42
# File 'lib/temple/generators.rb', line 40

def on_capture(name, exp)
  options[:capture_generator].new(:buffer => name).call(exp)
end

#on_code(code) ⇒ Object



52
53
54
# File 'lib/temple/generators.rb', line 52

def on_code(code)
  code
end

#on_dynamic(code) ⇒ Object



48
49
50
# File 'lib/temple/generators.rb', line 48

def on_dynamic(code)
  concat(code)
end

#on_multi(*exp) ⇒ Object



32
33
34
# File 'lib/temple/generators.rb', line 32

def on_multi(*exp)
  exp.map {|e| compile(e) }.join('; ')
end

#on_newlineObject



36
37
38
# File 'lib/temple/generators.rb', line 36

def on_newline
  "\n"
end

#on_static(text) ⇒ Object



44
45
46
# File 'lib/temple/generators.rb', line 44

def on_static(text)
  concat(text.inspect)
end