Class: Flok::TransitionCompilerAction
- Inherits:
-
Object
- Object
- Flok::TransitionCompilerAction
- Defined in:
- lib/flok/transition_compiler.rb
Instance Attribute Summary collapse
-
#controller ⇒ Object
Returns the value of attribute controller.
-
#name ⇒ Object
Returns the value of attribute name.
-
#on_entry_src ⇒ Object
Returns the value of attribute on_entry_src.
-
#ons ⇒ Object
Returns the value of attribute ons.
Instance Method Summary collapse
-
#initialize(controller, name, ctx, &block) ⇒ TransitionCompilerAction
constructor
A new instance of TransitionCompilerAction.
- #macro(text) ⇒ Object
-
#method_missing(method, *args, &block) ⇒ Object
You can def things in controller and use them as macros inside actions But these defs.
- #on(name, js_src) ⇒ Object
- #on_entry(js_src) ⇒ Object
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(¯o) else raise "No macro found named: #{method}" end end |
Instance Attribute Details
#controller ⇒ Object
Returns the value of attribute controller.
65 66 67 |
# File 'lib/flok/transition_compiler.rb', line 65 def controller @controller end |
#name ⇒ Object
Returns the value of attribute name.
65 66 67 |
# File 'lib/flok/transition_compiler.rb', line 65 def name @name end |
#on_entry_src ⇒ Object
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 |
#ons ⇒ Object
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 |