Class: Flok::UserCompilerAction

Inherits:
Object
  • Object
show all
Defined in:
lib/flok/user_compiler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, name, ctx, &block) ⇒ UserCompilerAction

Returns a new instance of UserCompilerAction.



66
67
68
69
70
71
72
73
# File 'lib/flok/user_compiler.rb', line 66

def initialize controller, name, ctx, &block
  @controller = controller
  @name = name
  @ctx = ctx
  @ons = [] #Event handlers

  self.instance_eval(&block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

You can def things in controller and use them as macros inside actions But these defs. live in the UserCompilerController instance and we need to delegate these calls to the controller that are not available in the action



387
388
389
390
391
392
393
394
# File 'lib/flok/user_compiler.rb', line 387

def method_missing method, *args, &block
  if macro = @controller.macros[method]
    #Call the macro in our context
    self.instance_eval(&macro)
  else
    raise "No macro found named: #{method}"
  end
end

Instance Attribute Details

#controllerObject

Returns the value of attribute controller.



64
65
66
# File 'lib/flok/user_compiler.rb', line 64

def controller
  @controller
end

#nameObject

Returns the value of attribute name.



64
65
66
# File 'lib/flok/user_compiler.rb', line 64

def name
  @name
end

#on_entry_srcObject

Returns the value of attribute on_entry_src.



64
65
66
# File 'lib/flok/user_compiler.rb', line 64

def on_entry_src
  @on_entry_src
end

#onsObject

Returns the value of attribute ons.



64
65
66
# File 'lib/flok/user_compiler.rb', line 64

def ons
  @ons
end

Instance Method Details

#macro(text) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/flok/user_compiler.rb', line 84

def macro js_src
  lines = js_src.split("\n").map do |line|
    
  end

  return lines.join("\n")
end

#on(name, js_src) ⇒ Object



80
81
82
# File 'lib/flok/user_compiler.rb', line 80

def on name, js_src
  @ons << {:name => name, :src => macro(js_src)}
end

#on_entry(js_src) ⇒ Object



75
76
77
78
# File 'lib/flok/user_compiler.rb', line 75

def on_entry js_src
  #returns a string
  @on_entry_src = macro(js_src)
end