Module: Hypertemplate::Builder

Defined in:
lib/hypertemplate/builder.rb,
lib/hypertemplate/builder/xml.rb,
lib/hypertemplate/builder/base.rb,
lib/hypertemplate/builder/json.rb,
lib/hypertemplate/builder/values.rb

Defined Under Namespace

Classes: Base, Json, Values, Xml

Class Method Summary collapse

Class Method Details

.helper_module_for(const) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/hypertemplate/builder.rb', line 8

def self.helper_module_for(const)
  mod = Module.new
  mod.module_eval <<-EOS
    def collection(obj, *args, &block)
      #{const.name}.build(obj, *args, &block)
    end

    alias_method :member, :collection
    
    def method_missing(sym, *args, &block)
      
      # you thought meta-(meta-programming) was nasty?
      # this is nasty... help me! i am an ActionView
      # so coupled to the entire Rails stack that I need
      # this hack.
      super if @first_invocation
      @first_invocation = true
      
      #{const.name}.build_dsl(self, :root => sym.to_s, &block)
    end
    
  EOS
  mod
end