Class | Amx::Template |
In: |
lib/amrita/amx.rb
|
Parent: | Amrita::Template |
doc | [R] | |
root | [R] |
# File lib/amrita/amx.rb, line 49 def Template::[](f) path = case f when String f when REXML::Document f.template_href else raise "unknown param #{f.type}" end doc = REXML::Document.new(REXML::File.new(path)) root = doc.elements['amx'] req = root.attributes['require'] require(req) if req clsname = root.attributes['class'] cls = if clsname eval clsname else Template end cls.new(path, doc) end
# File lib/amrita/amx.rb, line 73 def initialize(path, doc) super() @template_root = doc @path = path @xml = @asxml = true init_amx end
# File lib/amrita/amx.rb, line 89 def define_method(method_name, code) instance_eval "def \#{method_name}\n\#{code}\nend\n" end
# File lib/amrita/amx.rb, line 108 def expand(stream, doc) @doc = doc befor_expand super(stream, get_model) puts "" ensure @doc = nil end
# File lib/amrita/amx.rb, line 81 def init_amx @template_root.elements.to_a("amx/method").each do |m| method_name = m.attributes['id'].to_s code = m.elements['method_body'].get_text.to_s define_method(method_name, code) end end
# File lib/amrita/amx.rb, line 124 def rexml2amrita(xml) case xml when REXML::Element h = {} xml.attributes.each do |k,v| h[k] = convert(v) end e(xml.name, h) { xml.collect do |x| rexml2amrita(x) end } when REXML::Elements ret = xml.collect do |x| rexml2amrita(x) end Node::to_node(ret) when REXML::Text TextElement.new convert(xml.to_s) when REXML::Instruction "REXML::Instruction here(PENDING)" else raise "can't convert #{xml.type}" end end
# File lib/amrita/amx.rb, line 102 def setup_context context = AmxContext.new(self) context.delete_id = false if keep_id context end