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

- (Object) call(exp)



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

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

- (Object) compile(exp)



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

- (Object) on_capture(name, exp)



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

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

- (Object) on_code(code)



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

def on_code(code)
  code
end

- (Object) on_dynamic(code)



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

def on_dynamic(code)
  concat(code)
end

- (Object) on_multi(*exp)



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

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

- (Object) on_newline



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

def on_newline
  "\n"
end

- (Object) on_static(text)



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

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