Class: Flok::UserCompilerAction
- Inherits:
-
Object
- Object
- Flok::UserCompilerAction
- Includes:
- UserCompilerMacro
- Defined in:
- lib/flok/user_compiler.rb
Instance Attribute Summary collapse
-
#controller ⇒ Object
Returns the value of attribute controller.
-
#every_handlers ⇒ Object
Returns the value of attribute every_handlers.
-
#name ⇒ Object
Returns the value of attribute name.
-
#ons ⇒ Object
Returns the value of attribute ons.
Instance Method Summary collapse
- #every(seconds, str) ⇒ Object
-
#initialize(controller, name, ctx, &block) ⇒ UserCompilerAction
constructor
A new instance of UserCompilerAction.
-
#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
- #on_entry_src ⇒ Object
Methods included from UserCompilerMacro
Constructor Details
#initialize(controller, name, ctx, &block) ⇒ UserCompilerAction
Returns a new instance of UserCompilerAction.
500 501 502 503 504 505 506 507 508 509 |
# File 'lib/flok/user_compiler.rb', line 500 def initialize controller, name, ctx, &block @controller = controller @name = name @ctx = ctx @_on_entry_src = "" @ons = [] #Event handlers @every_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
535 536 537 538 539 540 541 542 543 544 |
# File 'lib/flok/user_compiler.rb', line 535 def method_missing method, *args, &block if macro = @controller.macros[method] #Call the macro in our context @current_action = name self.instance_eval(¯o) @current_action = nil else raise "No macro found named: #{method}" end end |
Instance Attribute Details
#controller ⇒ Object
Returns the value of attribute controller.
497 498 499 |
# File 'lib/flok/user_compiler.rb', line 497 def controller @controller end |
#every_handlers ⇒ Object
Returns the value of attribute every_handlers.
497 498 499 |
# File 'lib/flok/user_compiler.rb', line 497 def every_handlers @every_handlers end |
#name ⇒ Object
Returns the value of attribute name.
497 498 499 |
# File 'lib/flok/user_compiler.rb', line 497 def name @name end |
#ons ⇒ Object
Returns the value of attribute ons.
497 498 499 |
# File 'lib/flok/user_compiler.rb', line 497 def ons @ons end |
Instance Method Details
#every(seconds, str) ⇒ Object
524 525 526 527 528 529 530 |
# File 'lib/flok/user_compiler.rb', line 524 def every seconds, str @every_handlers << { :name => "#{seconds}_sec_#{SecureRandom.hex[0..6]}", :ticks => seconds*4, :src => _macro(str) } end |
#on(name, js_src) ⇒ Object
520 521 522 |
# File 'lib/flok/user_compiler.rb', line 520 def on name, js_src @ons << {:name => name, :src => _macro(js_src)} end |
#on_entry(js_src) ⇒ Object
511 512 513 514 |
# File 'lib/flok/user_compiler.rb', line 511 def on_entry js_src #returns a string @_on_entry_src = _macro(js_src) end |
#on_entry_src ⇒ Object
516 517 518 |
# File 'lib/flok/user_compiler.rb', line 516 def on_entry_src return @_on_entry_src end |