ruby_motion_query 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,11 @@
1
1
  module RubyMotionQuery
2
2
  class RMQ
3
-
4
3
  class << self
5
4
  # @return [Boolean]
6
5
  def is_class?(o)
7
6
  # This line fails in spec, causes exit without message. It works fine in production
8
7
  #(o.class == Class) && (defined?(o) == 'constant')
9
-
8
+
10
9
  # So I'm doing this instead
11
10
  !!(o.respond_to?(:name) && o.name.to_s[0] =~ /[A-Z]/)
12
11
  end
@@ -24,19 +23,63 @@ module RubyMotionQuery
24
23
  end
25
24
 
26
25
  # @param view
27
- # @return [UIViewController] The controller the view it is sitting in, or nil if it's not sitting anywhere in particular
26
+ # @return [UIViewController] The controller the view it is sitting in, or nil if it's not sitting anywhere in particular
28
27
  def controller_for_view(view)
29
- # Non-recursive for speed
30
- while view
31
- view = view.nextResponder
32
- if view.is_a?(UIViewController)
33
- break
34
- elsif !view.is_a?(UIView)
35
- view = nil
28
+ #debug.assert(view.nil? || view.is_a?(UIView), 'Invalid view in controller for view', {view: view})
29
+
30
+ if view && (vc = view.rmq_data.view_controller)
31
+ vc
32
+ else
33
+ # Non-recursive for speed
34
+ while view
35
+ view = view.nextResponder
36
+ if view.is_a?(UIViewController)
37
+ break
38
+ elsif view.is_a?(UIView)
39
+ if vc = view.rmq_data.view_controller
40
+ view = vc
41
+ break
42
+ end
43
+ else
44
+ view = nil
45
+ end
36
46
  end
47
+
48
+ view
49
+
37
50
  end
51
+ end
52
+
53
+ # @deprecated this has been fixed in 2.17, so this method is no longer needed.
54
+ #
55
+ # Creates a weak reference to an object. Unlike WeakRef.new provided by RubyMotion, this will
56
+ # not wrap a weak ref inside another weak ref (which causes bugs).
57
+ #
58
+ # This is fairly performant. It's about twice as slow as WeakRef.new. However, you can
59
+ # create a million weak refs in about 651 miliseconds, compared to 319 for WeakRef.new
60
+ #
61
+ # Creating a WeakRef with a literal like a string will cause your app to crash
62
+ # instantly, it's fun, try it. Only create weak refs of variables
63
+ #
64
+ # @example
65
+ # foo = RubyMotionQuery::RMQ.weak_ref(bar)
66
+ def weak_ref(o)
67
+ weak = WeakRef.new(weak_ref_to_strong_ref(o))
68
+ end
69
+
70
+ # @deprecated this has been fixed in 2.17, so this method is no longer needed.
71
+ #
72
+ # This gets around a bug in RubyMotion
73
+ # Hopefully I can remove this quickly. Only use this for complex objects that have no comparison
74
+ # other than that they are the exact same object. For example, strings compare their contents.
75
+ def weak_ref_is_same_object?(a, b)
76
+ (a.class == b.class) && (a.object_id == b.object_id)
77
+ end
38
78
 
39
- view
79
+ # Gets a strong reference from a weak reference
80
+ def weak_ref_to_strong_ref(weak_ref)
81
+ # This is a hack but it works, is there a better way?
82
+ weak_ref.tap{}
40
83
  end
41
84
 
42
85
  # Mainly used for console and logging
@@ -1,3 +1,9 @@
1
1
  module RubyMotionQuery
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
+
4
+ class RMQ
5
+ def version
6
+ RubyMotionQuery::VERSION
7
+ end
8
+ end
3
9
  end
@@ -49,7 +49,7 @@ class <%= @name_camel_case %>Controller < UICollectionViewController
49
49
 
50
50
  def collectionView(view, cellForItemAtIndexPath: index_path)
51
51
  view.dequeueReusableCellWithReuseIdentifier(<%= @name.upcase %>_CELL_ID, forIndexPath: index_path).tap do |cell|
52
- cell.setup_with(rmq)
52
+ rmq.build(cell) unless cell.reused
53
53
 
54
54
  # Update cell's data here
55
55
  end
@@ -1,6 +1,6 @@
1
1
  module <%= @name_camel_case %>CellStylesheet
2
2
  def cell_size
3
- [96, 96]
3
+ {w: 96, h: 96}
4
4
  end
5
5
 
6
6
  def <%= @name %>_cell(st)
@@ -14,12 +14,11 @@ class <%= @name_camel_case %>ControllerStylesheet < ApplicationStylesheet
14
14
  st.background_color = color.white
15
15
 
16
16
  st.view.collectionViewLayout.tap do |cl|
17
- cl.itemSize = cell_size
17
+ cl.itemSize = [cell_size[:w], cell_size[:h]]
18
18
  #cl.scrollDirection = UICollectionViewScrollDirectionHorizontal
19
- #cl.headerReferenceSize = cell_size
19
+ #cl.headerReferenceSize = [cell_size[:w], cell_size[:h]]
20
20
  cl.minimumInteritemSpacing = @margin
21
21
  cl.minimumLineSpacing = @margin
22
- #cl.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight,
23
22
  #cl.sectionInsert = [0,0,0,0]
24
23
  end
25
24
  end
@@ -1,17 +1,17 @@
1
1
  class <%= @name_camel_case %>Cell < UICollectionViewCell
2
- def setup_with(controller_rmq)
3
- unless @initialized
4
- @initialized = true
2
+ attr_reader :reused
5
3
 
6
- controller_rmq.wrap(self).tap do |q|
7
- q.apply_style :<%= @name %>_cell
4
+ def rmq_build
5
+ rmq(self).apply_style :<%= @name %>_cell
8
6
 
9
- # Add your subviews, init stuff here
10
- # @foo = q.append(UILabel, :foo).get
11
- end
7
+ rmq(self.contentView).tap do |q|
8
+ # Add your subviews, init stuff here
9
+ # @foo = q.append(UILabel, :foo).get
12
10
  end
13
11
  end
14
12
 
15
13
  def prepareForReuse
14
+ @reused = true
16
15
  end
16
+
17
17
  end
@@ -1,4 +1,6 @@
1
1
  class <%= @name_camel_case %>ControllerStylesheet < ApplicationStylesheet
2
+ # Add your view stylesheets here. You can then override styles if needed, example:
3
+ # include FooStylesheet
2
4
 
3
5
  def setup
4
6
  # Add sytlesheet specific setup stuff here.
@@ -1,13 +1,11 @@
1
1
  class <%= @name_camel_case %> < UIView
2
2
 
3
- def rmq_did_create(self_in_rmq)
3
+ def rmq_build
4
4
 
5
- self_in_rmq.tap do |q|
6
- q.apply_style :<%= @name %>
5
+ rmq.apply_style :<%= @name %>
7
6
 
8
- # Add subviews here, like so:
9
- #q.append(UILabel, :some_label)
10
- end
7
+ # Add subviews here, like so:
8
+ #rmq.append(UILabel, :some_label)
11
9
 
12
10
  end
13
11
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_motion_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Werth
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-23 00:00:00.000000000 Z
12
+ date: 2013-12-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bacon
@@ -57,6 +57,7 @@ files:
57
57
  - motion/ruby_motion_query/base.rb
58
58
  - motion/ruby_motion_query/color.rb
59
59
  - motion/ruby_motion_query/data.rb
60
+ - motion/ruby_motion_query/debug.rb
60
61
  - motion/ruby_motion_query/device.rb
61
62
  - motion/ruby_motion_query/enumerablish.rb
62
63
  - motion/ruby_motion_query/event.rb