Class: Scarpe::Webview::Slot
- Inherits:
-
Drawable
- Object
- Shoes::Linkable
- Drawable
- Scarpe::Webview::Slot
- Defined in:
- lib/scarpe/wv/slot.rb
Constant Summary
Constants included from Shoes::Log
Shoes::Log::DEFAULT_COMPONENT, Shoes::Log::DEFAULT_DEBUG_LOG_CONFIG, Shoes::Log::DEFAULT_LOG_CONFIG
Instance Attribute Summary
Attributes inherited from Drawable
#children, #parent, #shoes_linkable_id
Attributes inherited from Shoes::Linkable
Instance Method Summary collapse
- #element(&block) ⇒ Object
-
#html_attributes ⇒ Object
protected
These get added for event handlers and passed to Calzini.
-
#initialize(properties) ⇒ Slot
constructor
A new instance of Slot.
- #remove_event_callback(obj, event_name) ⇒ Object
- #remove_event_callbacks(obj) ⇒ Object
- #set_event_callback(obj, event_name, js_code) ⇒ Object
- #update_dom_event(event_name) ⇒ Object protected
Methods inherited from Drawable
#add_child, #bind, #destroy_self, display_class_for, #full_window_redraw!, #handler_js_code, #html_element, #html_id, #inspect, #needs_update!, #promise_update, #properties_changed, #remove_child, #set_parent, #shoes_styles, #to_html
Methods included from Shoes::Log
configure_logger, #log_init, logger
Methods inherited from Shoes::Linkable
#bind_shoes_event, #send_self_event, #send_shoes_event, #unsub_all_shoes_events, #unsub_shoes_event
Constructor Details
#initialize(properties) ⇒ Slot
Returns a new instance of Slot.
5 6 7 8 9 |
# File 'lib/scarpe/wv/slot.rb', line 5 def initialize(properties) @event_callbacks = {} super end |
Instance Method Details
#element(&block) ⇒ Object
11 12 13 14 15 |
# File 'lib/scarpe/wv/slot.rb', line 11 def element(&block) props = shoes_styles.merge("html_attributes" => html_attributes) render_name = self.class.name.split("::")[-1].downcase # usually "stack" or "flow" or "documentroot" render(render_name, props, &block) end |
#html_attributes ⇒ Object (protected)
These get added for event handlers and passed to Calzini
54 55 56 57 58 59 60 61 62 |
# File 'lib/scarpe/wv/slot.rb', line 54 def html_attributes attr = {} @event_callbacks.each do |event_name, handlers| attr[event_name] = handlers.values.join(";") end attr end |
#remove_event_callback(obj, event_name) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/scarpe/wv/slot.rb', line 29 def remove_event_callback(obj, event_name) event_name = event_name.to_s @event_callbacks[event_name] ||= {} @event_callbacks[event_name].delete(obj) update_dom_event(event_name) end |
#remove_event_callbacks(obj) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/scarpe/wv/slot.rb', line 37 def remove_event_callbacks(obj) changed = [] @event_callbacks.each do |event_name, items| changed << event_name if items.delete(obj) end changed.each { |event_name| update_dom_event(event_name) } end |
#set_event_callback(obj, event_name, js_code) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/scarpe/wv/slot.rb', line 17 def set_event_callback(obj, event_name, js_code) event_name = event_name.to_s @event_callbacks[event_name] ||= {} if @event_callbacks[event_name][obj] raise Scarpe::DuplicateCallbackError, "Can't have two callbacks on the same event, from the same object, on the same parent!" end @event_callbacks[event_name][obj] = js_code update_dom_event(event_name) end |
#update_dom_event(event_name) ⇒ Object (protected)
49 50 51 |
# File 'lib/scarpe/wv/slot.rb', line 49 def update_dom_event(event_name) html_element.set_attribute(event_name, @event_callbacks[event_name].values.join(";")) end |