maccman-bowline 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
data/bowline.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{bowline}
5
- s.version = "0.4.0"
5
+ s.version = "0.4.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Alex MacCaw"]
9
- s.date = %q{2009-07-18}
9
+ s.date = %q{2009-07-21}
10
10
  s.default_executable = %q{bowline-gen}
11
11
  s.description = %q{Ruby/JS GUI framework}
12
12
  s.email = %q{alex@leadthinking.com}
@@ -95,24 +95,16 @@ module Bowline
95
95
  attr_reader :element
96
96
  attr_reader :item
97
97
 
98
- def self.new(element, *args) #:nodoc:
99
- allocate.instance_eval do
100
- # jQuery element
101
- @element = element
102
- # Calling chain.js 'item' function
103
- @item = element.item()
104
- if @item
105
- @item.with_indifferent_access
106
- # If possible, find Ruby object
107
- if @item[:id] && respond_to?(:find)
108
- @item = find(@item[:id])
109
- end
110
- end
111
-
112
- initialize(*args)
113
- self
98
+ def initialize(element, *args) #:nodoc:
99
+ # jQuery element
100
+ @element = element
101
+ # Calling chain.js 'item' function
102
+ @item = element.item()
103
+ if @item
104
+ # If possible, find Ruby object
105
+ @item = self.class.find(@item._id.to_i)
114
106
  end
115
- end
107
+ end
116
108
 
117
109
  # Trigger jQuery events on this element
118
110
  def trigger(event, data = nil)
@@ -1,27 +1,56 @@
1
1
  module Bowline
2
2
  module Binders
3
3
  class Collection < Base
4
+ class ItemsProxy
5
+ def initialize(&block)
6
+ @callback = block
7
+ @items = []
8
+ end
9
+
10
+ def real
11
+ @items
12
+ end
13
+
14
+ def method_missing(*args, &block)
15
+ diff = @items.hash
16
+ res = @items.send(*args, &block)
17
+ if diff != @items.hash
18
+ @callback.call
19
+ end
20
+ res
21
+ end
22
+ end
23
+
4
24
  class << self
5
25
  def items=(args)
6
- @items = args
7
- self.item_sync!
8
- @items
26
+ if args
27
+ items.replace(args)
28
+ else
29
+ items.clear
30
+ end
9
31
  end
10
32
 
11
33
  def items
12
- @items ||= []
34
+ @items ||= ItemsProxy.new {
35
+ self.item_sync!
36
+ }
13
37
  end
14
38
 
15
39
  def item_sync!
16
40
  return unless @items && @elements
17
- @elements.each {|i|
18
- i.updateCollection(@items.to_js)
41
+ value = @items.real.map {|item|
42
+ hash = item.to_js
43
+ hash.merge!({:_id => item.__id__})
44
+ hash.stringify_keys
45
+ }
46
+ @elements.each {|i|
47
+ i.updateCollection(value)
19
48
  }
20
49
  end
21
50
 
22
51
  def find(id)
23
- @items.find {|item|
24
- item.id == id
52
+ @items.real.find {|item|
53
+ item.__id__ == id
25
54
  }
26
55
  end
27
56
  end
@@ -13,9 +13,12 @@ module Bowline
13
13
 
14
14
  def item_sync!
15
15
  return unless @item && @elements
16
+ value = @item.to_js
17
+ value.merge!({:_id => @item.__id__})
18
+ value.stringify_keys!
16
19
  # Call the chain.js function 'item' on elements
17
20
  @elements.each {|i|
18
- i.updateSingleton(@item.to_js)
21
+ i.updateSingleton(value)
19
22
  }
20
23
  end
21
24
 
@@ -1,5 +1,5 @@
1
1
  class Array
2
- def to_js(opts = {})
3
- map {|i| i.to_js(opts) }
2
+ def to_js
3
+ map {|i| i.to_js }
4
4
  end
5
5
  end
@@ -2,7 +2,7 @@ class Object
2
2
  # Aim is to convert the object in:
3
3
  # * A hash or
4
4
  # * An array of hashes
5
- def to_js(opts = {})
5
+ def to_js
6
6
  if respond_to?(:attributes)
7
7
  attributes
8
8
  else
@@ -2,7 +2,7 @@ module Bowline
2
2
  module Version #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 4
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maccman-bowline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex MacCaw
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-18 00:00:00 -07:00
12
+ date: 2009-07-21 00:00:00 -07:00
13
13
  default_executable: bowline-gen
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency