Class: Flok::TransitionCompilerAction

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of TransitionCompilerAction.



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

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 TransitionCompilerController instance and we need to delegate these calls to the controller that are not available in the action



256
257
258
259
260
261
262
263
# File 'lib/flok/transition_compiler.rb', line 256

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.



65
66
67
# File 'lib/flok/transition_compiler.rb', line 65

def controller
  @controller
end

#nameObject

Returns the value of attribute name.



65
66
67
# File 'lib/flok/transition_compiler.rb', line 65

def name
  @name
end

#on_entry_srcObject

Returns the value of attribute on_entry_src.



65
66
67
# File 'lib/flok/transition_compiler.rb', line 65

def on_entry_src
  @on_entry_src
end

#onsObject

Returns the value of attribute ons.



65
66
67
# File 'lib/flok/transition_compiler.rb', line 65

def ons
  @ons
end

Instance Method Details

#macro(text) ⇒ Object



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

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

  return lines.join("\n")
end

#on(name, js_src) ⇒ Object



81
82
83
# File 'lib/flok/transition_compiler.rb', line 81

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

#on_entry(js_src) ⇒ Object



76
77
78
79
# File 'lib/flok/transition_compiler.rb', line 76

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