Class: Roda::Component::Events
- Inherits:
-
Struct
- Object
- Struct
- Roda::Component::Events
- Defined in:
- lib/roda/component/events.rb
Instance Attribute Summary collapse
-
#component_opts ⇒ Object
Returns the value of attribute component_opts.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#request ⇒ Object
Returns the value of attribute request.
-
#scope ⇒ Object
Returns the value of attribute scope.
Instance Method Summary collapse
- #on(name, options = {}, &block) ⇒ Object
- #trigger(name, options = {}) ⇒ Object
- #trigger_jquery_events ⇒ Object
Instance Attribute Details
#component_opts ⇒ Object
Returns the value of attribute component_opts
3 4 5 |
# File 'lib/roda/component/events.rb', line 3 def component_opts @component_opts end |
#klass ⇒ Object
Returns the value of attribute klass
3 4 5 |
# File 'lib/roda/component/events.rb', line 3 def klass @klass end |
#request ⇒ Object
Returns the value of attribute request
3 4 5 |
# File 'lib/roda/component/events.rb', line 3 def request @request end |
#scope ⇒ Object
Returns the value of attribute scope
3 4 5 |
# File 'lib/roda/component/events.rb', line 3 def scope @scope end |
Instance Method Details
#on(name, options = {}, &block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/roda/component/events.rb', line 4 def on name, = {}, &block if client? && .is_a?(String) class_name = klass._name class_events = (events[class_name] ||= {}) event = (class_events[:_jquery_events] ||= []) event << [block, class_name, , name] elsif .is_a?(Hash) limit_if = .delete(:if) || [] limit_if = [limit_if] unless limit_if.is_a? Array class_name = .delete(:for) || klass._name class_events = (events[class_name] ||= {}) event = (class_events[name.to_s] ||= []) # remove the type, if we have an on if and it isn't in the engine_type if limit_if.any? && !limit_if.include?(engine_type.to_sym) block = Proc.new {} end event << [block, klass._name, ] end end |
#trigger(name, options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/roda/component/events.rb', line 45 def trigger name, = {} content = '' e = events[klass._name] return unless e (e[name.to_s] || []).each do |event| block, comp, opts = event if !opts[:socket] response = Component::Instance.new(component(comp), scope).instance_exec , &block if response.is_a? Roda::Component::DOM content = response.to_xml else content = response end else $faye.publish("/components/#{klass._name}", { name: klass._name, type: 'event', event_type: 'call', event_method: name.to_s, data: }) end end content end |
#trigger_jquery_events ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/roda/component/events.rb', line 27 def trigger_jquery_events return unless e = events[klass._name] (e[:_jquery_events] || []).each do |event| block, comp, selector, name = event name = name.to_s if name != 'ready' Document.on name, selector do |evt| Component::Instance.new(component(comp), scope).instance_exec evt.current_target, evt, &block end else Component::Instance.new(component(comp), scope).instance_exec Document.find(selector), nil, &block end end end |