Class: RGen::TemplateLanguage::TemplateContainer

Inherits:
Object
  • Object
show all
Includes:
TemplateHelper
Defined in:
lib/rgen/template_language/template_container.rb

Defined Under Namespace

Classes: TemplateDesc

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metamodels, output_path, parent, filename) ⇒ TemplateContainer

Returns a new instance of TemplateContainer.



16
17
18
19
20
21
22
23
24
# File 'lib/rgen/template_language/template_container.rb', line 16

def initialize(metamodels, output_path, parent, filename)
  @templates = {}
  @parent = parent
  @filename = filename
  @indent = 0
  @output_path = output_path
@metamodels = metamodels
@metamodels = [ @metamodels ] unless @metamodels.is_a?(Array)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



60
61
62
# File 'lib/rgen/template_language/template_container.rb', line 60

def method_missing(name, *args)
  @context.send(name, *args)
end

Class Method Details

.const_missing(name) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/rgen/template_language/template_container.rb', line 64

def self.const_missing(name)
  super unless @@metamodels
  @@metamodels.each do |mm|
    return mm.const_get(name) rescue NameError
  end
  super
end

Instance Method Details

#evaluate(template, *all_args) ⇒ Object

Raises:

  • (StandardError)


50
51
52
53
54
# File 'lib/rgen/template_language/template_container.rb', line 50

def evaluate(template, *all_args)
  args, params = _splitArgsAndOptions(all_args)
  raise StandardError.new(":foreach can not be used with evaluate") if params[:foreach]
  _expand(template, args, params.merge({:_evalOnly => true}))
end

#expand(template, *all_args) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/rgen/template_language/template_container.rb', line 39

def expand(template, *all_args)
  args, params = _splitArgsAndOptions(all_args)
if params.has_key?(:foreach)
		raise StandardError.new("expand :foreach argument is not enumerable") \
  		unless params[:foreach].is_a?(Enumerable)
    _expand_foreach(template, args, params)
  else
    _expand(template, args, params)
  end
end

#loadObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rgen/template_language/template_container.rb', line 26

def load
File.open(@filename,"rb") do |f|
    begin
   	@@metamodels = @metamodels
   	fileContent = f.read
	  	_detectNewLinePattern(fileContent)
  		ERB.new(fileContent,nil,nil,'@output').result(binding)
    rescue Exception => e
      processAndRaise(e)
    end
end
end

#thisObject



56
57
58
# File 'lib/rgen/template_language/template_container.rb', line 56

def this
  @context
end