Class: Amrita2::Macro::Base

Inherits:
Object show all
Defined in:
lib/amrita2/template.rb,
lib/amrita2/macro.rb

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



27
28
29
30
31
32
# File 'lib/amrita2/macro.rb', line 27

def initialize
  @mt = Template.new(get_macro_template, :amrita_prefix=>"macro:", :inline_ruby=>true)
  @option = {}
  @option = self.class.const_get(:Option) if self.class.const_defined?(:Option)
  raise "Macro Option is not defined propery in #{self.class} #{@option.inspect}" unless @option.kind_of?(Hash)
end

Instance Method Details

#get_element_nameObject



38
39
40
41
# File 'lib/amrita2/macro.rb', line 38

def get_element_name
  #self.class.const_get(:ElementName)
  @option[:tag] || underscore(self.class.name)
end

#get_macro_templateObject



34
35
36
# File 'lib/amrita2/macro.rb', line 34

def get_macro_template
  self.class.const_get(:TemplateText)
end

#macro_data(element) ⇒ Object



51
52
53
# File 'lib/amrita2/macro.rb', line 51

def macro_data(element)
  element.as_amrita_dictionary(@option)
end

#match_element(element) ⇒ Object



47
48
49
# File 'lib/amrita2/macro.rb', line 47

def match_element(element)
  element.name == get_element_name.to_s
end

#preprocess_element(mt, element) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/amrita2/macro.rb', line 55

def preprocess_element(mt, element)
  if @option[:trace]
    mt.set_trace(@option[:trace])
    @option[:trace] << (macro_data(element)).inspect
  end
  mt.amrita_prefix = "macro:"
  mt.render_with(macro_data(element))
end

#process(de, element) ⇒ Object



43
44
45
# File 'lib/amrita2/macro.rb', line 43

def process(de, element)
  preprocess_element(@mt, element)
end