"DTD/xhtml1-strict.dtd">
Class Amx::Template
In: lib/amrita/amx.rb
Parent: Amrita::Template
Methods
[]    befor_expand    define_method    expand    get_model    init_amx    new    rexml2amrita    setup_context    setup_template   
Attributes
:doc  [R] 
:root  [R] 
Included modules
ExpandByMember
Public Class methods
[](f)
# 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
new(path, doc)
# File lib/amrita/amx.rb, line 73
    def initialize(path, doc)
      super()
      @template_root = doc
      @path = path
      @xml = @asxml = true
      init_amx
    end
Public Instance methods
init_amx()
# 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
define_method(method_name, code)
# File lib/amrita/amx.rb, line 89
    def define_method(method_name, code)
      instance_eval "        def \#{method_name}\n          \#{code}\n        end\n"
    end
get_model()
# File lib/amrita/amx.rb, line 98
    def get_model
      self
    end
setup_context()
# File lib/amrita/amx.rb, line 102
    def setup_context
      context = AmxContext.new(self)
      context.delete_id = false if keep_id
      context
    end
expand(stream, doc)
# File lib/amrita/amx.rb, line 108
    def expand(stream, doc)
      @doc = doc
      befor_expand
      super(stream, get_model)
      puts ""
    ensure
      @doc = nil
    end
befor_expand()
# File lib/amrita/amx.rb, line 117
    def befor_expand
    end
setup_template()
# File lib/amrita/amx.rb, line 120
    def setup_template
      @template = rexml2amrita(@template_root.elements['amx/template'].elements)
    end
rexml2amrita(xml)
# 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