Class: Bowline::Binders::Base
Direct Known Subclasses
Instance Attribute Summary collapse
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#item ⇒ Object
readonly
Returns the value of attribute item.
Class Method Summary collapse
- .elements ⇒ Object
-
.format_event(name) ⇒ Object
:nodoc:.
-
.inherited(child) ⇒ Object
:nodoc:.
-
.instance(el) ⇒ Object
:nodoc:.
-
.jquery ⇒ Object
Equivalent of the ‘jQuery’ function.
-
.js ⇒ Object
See Bowline::js.
- .loading(&block) ⇒ Object
-
.logger ⇒ Object
See Bowline::logger.
-
.observer ⇒ Object
See the Observer class.
- .params ⇒ Object
-
.params=(p) ⇒ Object
:nodoc:.
-
.setup(d) ⇒ Object
:nodoc:.
-
.show_view(*args) ⇒ Object
See Bowline::show_view.
- .trigger(event, data = nil) ⇒ Object
Instance Method Summary collapse
-
#dom ⇒ Object
Raw DOM element.
-
#initialize(element, *args) ⇒ Base
constructor
:nodoc:.
-
#jquery ⇒ Object
See self.class.jquery.
-
#js ⇒ Object
(also: #page)
See self.class.js.
-
#logger ⇒ Object
See self.class.logger.
-
#observer ⇒ Object
See self.class.observer.
-
#show_view(*args) ⇒ Object
See self.class.show_view.
-
#trigger(event, data = nil) ⇒ Object
Trigger jQuery events on this element.
Constructor Details
#initialize(element, *args) ⇒ Base
:nodoc:
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/bowline/binders.rb', line 98 def initialize(element, *args) #:nodoc: # jQuery element @element = element # Calling chain.js 'item' function @item = element.item() if @item # If possible, find Ruby object @item = self.class.find(@item._id.to_i) end end |
Instance Attribute Details
#element ⇒ Object (readonly)
Returns the value of attribute element.
95 96 97 |
# File 'lib/bowline/binders.rb', line 95 def element @element end |
#item ⇒ Object (readonly)
Returns the value of attribute item.
96 97 98 |
# File 'lib/bowline/binders.rb', line 96 def item @item end |
Class Method Details
.elements ⇒ Object
50 51 52 |
# File 'lib/bowline/binders.rb', line 50 def elements @elements end |
.format_event(name) ⇒ Object
:nodoc:
88 89 90 91 92 |
# File 'lib/bowline/binders.rb', line 88 def format_event(name) #:nodoc: name.is_a?(Array) ? name.join('.') : name.to_s end |
.inherited(child) ⇒ Object
:nodoc:
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/bowline/binders.rb', line 77 def inherited(child) #:nodoc: return if self == Bowline::Binders::Base return if child == Bowline::Binders::Singleton return if child == Bowline::Binders::Collection name = child.name.underscore name = name.split('/').last js.send("bowline_#{name}_setup=", child.method(:setup)) js.send("bowline_#{name}_instance=", child.method(:instance)) js.send("bowline_#{name}=", child.method(:send)) end |
.instance(el) ⇒ Object
:nodoc:
73 74 75 |
# File 'lib/bowline/binders.rb', line 73 def instance(el) #:nodoc: self.new(el).method(:send) end |
.jquery ⇒ Object
Equivalent of the ‘jQuery’ function
11 12 13 |
# File 'lib/bowline/binders.rb', line 11 def jquery @@jquery ||= JQuery.new end |
.loading(&block) ⇒ Object
67 68 69 70 71 |
# File 'lib/bowline/binders.rb', line 67 def loading(&block) trigger(:loading, true) yield trigger(:loading, false) end |
.logger ⇒ Object
See Bowline::logger
21 22 23 |
# File 'lib/bowline/binders.rb', line 21 def logger Bowline::logger end |
.observer ⇒ Object
See the Observer class
16 17 18 |
# File 'lib/bowline/binders.rb', line 16 def observer @observer ||= Observer.new end |
.params ⇒ Object
30 31 32 |
# File 'lib/bowline/binders.rb', line 30 def params @params end |
.params=(p) ⇒ Object
:nodoc:
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bowline/binders.rb', line 34 def params=(p) #:nodoc: case p when String # Params comes in a string (since it's a # serialized form) - we need to make it into # a nestled hash. Stolen from Ramaze m = proc {|_,o,n|o.merge(n,&m)} @params = params.inject({}) do |hash, (key, value)| parts = key.split(/[\]\[]+/) hash.merge(parts.reverse.inject(value) { |x, i| {i => x} }, &m) end else @params = p end end |
.setup(d) ⇒ Object
:nodoc:
54 55 56 57 58 |
# File 'lib/bowline/binders.rb', line 54 def setup(d) #:nodoc: @elements ||= [] @elements << d self.item_sync! end |
.show_view(*args) ⇒ Object
See Bowline::show_view
26 27 28 |
# File 'lib/bowline/binders.rb', line 26 def show_view(*args) Bowline::show_view(*args) end |
.trigger(event, data = nil) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/bowline/binders.rb', line 60 def trigger(event, data = nil) @elements ||= [] @elements.map {|e| e.trigger(format_event(event), data) } end |
Instance Method Details
#dom ⇒ Object
Raw DOM element
118 119 120 |
# File 'lib/bowline/binders.rb', line 118 def dom self.element[0] end |
#jquery ⇒ Object
See self.class.jquery
136 137 138 |
# File 'lib/bowline/binders.rb', line 136 def jquery self.class.jquery end |
#js ⇒ Object Also known as: page
See self.class.js
130 131 132 |
# File 'lib/bowline/binders.rb', line 130 def js self.class.js end |
#logger ⇒ Object
See self.class.logger
146 147 148 |
# File 'lib/bowline/binders.rb', line 146 def logger self.class.logger end |
#observer ⇒ Object
See self.class.observer
141 142 143 |
# File 'lib/bowline/binders.rb', line 141 def observer self.class.observer end |
#show_view(*args) ⇒ Object
See self.class.show_view
125 126 127 |
# File 'lib/bowline/binders.rb', line 125 def show_view(*args) self.class.show_view(*args) end |
#trigger(event, data = nil) ⇒ Object
Trigger jQuery events on this element
110 111 112 113 114 115 |
# File 'lib/bowline/binders.rb', line 110 def trigger(event, data = nil) self.element.trigger( self.class.format_event(event), data ) end |