Class: Flok::UserCompilerAction
- Inherits:
-
Object
- Object
- Flok::UserCompilerAction
- Defined in:
- lib/flok/user_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) ⇒ UserCompilerAction
constructor
A new instance of UserCompilerAction.
- #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) ⇒ 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(¯o) else raise "No macro found named: #{method}" end end |
Instance Attribute Details
#controller ⇒ Object
Returns the value of attribute controller.
64 65 66 |
# File 'lib/flok/user_compiler.rb', line 64 def controller @controller end |
#name ⇒ Object
Returns the value of attribute name.
64 65 66 |
# File 'lib/flok/user_compiler.rb', line 64 def name @name end |
#on_entry_src ⇒ Object
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 |
#ons ⇒ Object
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 |