ruby_motion_query 0.3.0 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZWQyYzBmYzcxMmJhZDQwMGYzZDU1ZWFiYWRjNDBlMmM1YTU4YjY5Ng==
4
+ YWNlNGE2M2YwYzFkYTMyZTFmZDNkN2MwMGQ3NjM3YWFlNzc1M2VlMQ==
5
5
  data.tar.gz: !binary |-
6
- YjA0YzdiMDkwN2YzOWY1NDAwMDNlNzIwMzQxYTA1Njc3ZmY1NTBiZA==
6
+ YmUwYjFlZGU4ODlkMDIzMzUwOTc0ZTYyMjg0ODQxNmYwOTg4ZjMzMA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZThjYTAzM2U3ZGExYzBkY2I2NmZmY2NiZDRjYjc5MjZmNzVhY2Y1Mzg5MGQ1
10
- ZTU3MmY5OTkzMTQ5YjQzYmRmNzQ0MzI2MTQxZWRlYmYyNzljNzViN2Q3YWE3
11
- MjIyODE5YTg3NTllMTYzN2E5ZjA4ZTNlYjVjZmUwZjgwNzE2MGE=
9
+ NjBhZGY2ZjMwZTI5M2M5MWI5NDc3NWY0YjdjOTkzN2Y0YmY0N2JiN2M3ZGI0
10
+ NGFiNzNjZTQ0OGEzZDQ4OWQ3ZTQ5MzNmMTIxYzE0ODhjMzdkYjVmMzAyMzIx
11
+ MTQ5NjAwZjI3ODZhY2NjNmUxYTcxODdkZGQwOGUxMWY1MWE4MDA=
12
12
  data.tar.gz: !binary |-
13
- ZjU3MWUzYzFiZDFmYzkzYTA2ZjViYTQ2OTVkZTdjNDQ5NWY2NTBhNTcyODAy
14
- MGM0MzE4ODI5ZjkxNDcyNzdiYzJiZDZiZDRmZjIyMzY1ZWVkMzAwMjdjYmMz
15
- ZWYxZTM4M2VkODA2Mzk4OWQyNTY4NTA4ZjdmODNkZmI3NTA1ZGI=
13
+ MjQxYjUwNDFlYzJiNWJkNDE5OGYyZDE2ZTdiMmViYjkyN2NkZmRlOTQ3Mzcz
14
+ ZGM1N2VkNDc5MTJhYzAyYjM2NjAyYTZiZDE5ZjUzODRlMTNiM2Y5NWEyOTY3
15
+ YTc2MDIzODE0MGEyZGM2ZDNmMDZjYWI5N2FlMTk2YTQ5ZjI3MmU=
data/README.md CHANGED
@@ -39,6 +39,12 @@ RMQ **doesn't require any** other wrapper or gem.
39
39
 
40
40
  Some of the code in RMQ came from BubbleWrap and Sugarcube. Not too much but some did. I thank you BubbleWrap and Sugarcube teams for your work.
41
41
 
42
+ ## Quick Start
43
+ - `gem install ruby_motion_query`
44
+ - `rmq create my_app`
45
+ - `cd my_app`
46
+ - `bundle`
47
+ - `rake retina=4`
42
48
 
43
49
  ## Installation
44
50
 
@@ -287,9 +293,15 @@ The internal store of events in a UIView. It's rmq.events, you won't use it too
287
293
  ```ruby
288
294
  # Add tags
289
295
  rmq(my_view).tag(:your_tag)
296
+ rmq(my_view).clear_tags.tag(:your_new_tag)
290
297
 
291
298
  rmq(my_view).find(UILabel).tag(:selected, :customer)
292
299
 
300
+ # You can optionally store a value in the tag, which can be super useful in some rare situations
301
+ rmq(my_view).tag(your_tag: 22)
302
+ rmq(my_view).tag(your_tag: 22, your_other_tag: 'Hello world')
303
+
304
+
293
305
  # You can use a tag or tags as selecors
294
306
  rmq(:selected).hide
295
307
  rmq(:your_tag).and(:selected).hide
@@ -306,7 +318,7 @@ rmq(my_view).toggle_enabled
306
318
  rmq(my_text_field).focus # or .become_first_responder
307
319
  ```
308
320
 
309
- ### Subviews
321
+ ### Subviews - appending, creating, etc
310
322
 
311
323
  ```ruby
312
324
  rmq.append(UILabel) # Creates a UILabel in the current controller
@@ -334,6 +346,27 @@ rmq.root_view
334
346
  rmq.view_controller
335
347
  ```
336
348
 
349
+ #### Create a view
350
+ If you want to create a view but not add it to the subviews of any other view, you can
351
+ use #create. It's basically #append without the actual appending.
352
+ This is very handy for stuff like table cells:
353
+
354
+ ```ruby
355
+ # In your controller that is a delegate for a UITableView
356
+ def tableView(table_view, cellForRowAtIndexPath: index_path)
357
+ cell = tableView.dequeueReusableCellWithIdentifier(CELL_IDENTIFIER) || begin
358
+ rmq.create(StoreCell, :store_cell)
359
+ end
360
+ end
361
+
362
+ # Your cell
363
+ class StoreCell < UITableViewCell
364
+ def rmq_did_create(self_in_rmq)
365
+ self_in_rmq.append(UILabel, :title_label) # <- this works even though this object isn't in a controller
366
+ end
367
+ end
368
+ ```
369
+
337
370
  ### Animate
338
371
 
339
372
  ```ruby
data/bin/rmq ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ unless ARGV.length > 0
4
+ puts 'RMQ - Invalid command, do something like this: rmq create my_new_app'
5
+ exit
6
+ end
7
+
8
+
9
+ action = ARGV[0]
10
+ value = ARGV[1]
11
+
12
+ case action
13
+ when 'create'
14
+ `motion create --template=git@github.com:infinitered/rmq-template.git #{value}`
15
+
16
+ puts %{
17
+ Complete. Things you should do:
18
+ > cd #{value}
19
+ > bundle
20
+ > rake spec
21
+ > rake
22
+ (main)> exit
23
+
24
+ Then try these:
25
+ > rake retina=3.5
26
+ > rake retina=4
27
+ > rake device_family=ipad
28
+ > rake device }
29
+
30
+ when 'api'
31
+ `open http://rdoc.info/github/infinitered/rmq`
32
+ when 'docs'
33
+ `open http://infinitered.com/rmq`
34
+ else
35
+ puts 'RMQ - Invalid action'
36
+
37
+ end
data/motion/ext.rb CHANGED
@@ -4,12 +4,14 @@ class UIView
4
4
  end
5
5
 
6
6
  # Override in your view if you want to setup subviews after your view has
7
- # been created by rmq, usually through an #append
7
+ # been created by rmq, usually through an #append or #create
8
+ #
9
+ # @param [RMQ] rmq that created your view
8
10
  #
9
11
  # In your view
10
12
  # @example
11
- # def rmq_did_create
12
- # rmq(self).tap do |q|
13
+ # def rmq_did_create(self_in_rmq)
14
+ # self_in_rmq.tap do |q|
13
15
  # q.append(UILabel, :section_title)
14
16
  # q.append(UIButton, :buy_button).on(:tap) do |sender|
15
17
  # # do something
@@ -24,11 +26,16 @@ class UIView
24
26
  # In this example an instance of YourView is created, :your_style is applied
25
27
  # then rmq_did_create is called on the instance that was just created. In that
26
28
  # order.
27
- def rmq_did_create
29
+ def rmq_did_create(self_in_rmq)
28
30
  end
29
31
 
30
- protected
31
-
32
+ # I intend for this to be protected
33
+ # Do not call rmq from outside a view. Because of some weirdness with table cells
34
+ # and event blocks this has to be public (later I want to figure out why exactly).
35
+ #
36
+ # Technically my_view.rmq is the same as rmq(my_view), so it may seem enticing to use
37
+ # but the really nice thing about rmq is its consistent API, and doing this
38
+ # for one view: my_view.rmq and this for two views: rmq(my_view, my_other_view) sucks
32
39
  def rmq(*selectors)
33
40
  RubyMotionQuery::RMQ.create_with_selectors(selectors, self)
34
41
  end
@@ -39,7 +46,7 @@ class UIViewController
39
46
  if RubyMotionQuery::RMQ.cache_controller_rmqs && selectors.length == 0
40
47
  rmq_data.rmq ||= RubyMotionQuery::RMQ.create_with_selectors(selectors, self)
41
48
  else
42
- RubyMotionQuery::RMQ.create_with_selectors(selectors, self)
49
+ RubyMotionQuery::RMQ.create_with_selectors(selectors, self, rmq_data.rmq)
43
50
  end
44
51
  end
45
52
 
@@ -16,7 +16,7 @@ module RubyMotionQuery
16
16
  # controller that the view is currently in or to the current screen's
17
17
  # controller
18
18
  class RMQ
19
- attr_accessor :context, :parent_rmq
19
+ attr_accessor :context
20
20
 
21
21
  def initialize
22
22
  @selected_dirty = true
@@ -61,12 +61,44 @@ module RubyMotionQuery
61
61
  @_selected
62
62
  end
63
63
 
64
+ # Wraps 1 or more views in an rmq instance.
65
+ #
66
+ # Normally you select a view or views using rmq(my_view). Which doesn't
67
+ # work if you have an instance of a RMQ, in which case it isn't a method.
68
+ # In some cases you want to save an instance of rmq and use it like the rmq
69
+ # method, for this you'd use #wrap
70
+ #
71
+ # @example
72
+ # q = RubyMotionQuery::RMQ.new
73
+ #
74
+ # # Bad
75
+ # q(my_view).view_controller
76
+ #
77
+ # # Good
78
+ # q.wrap(my_view).view_controller
79
+ def wrap(*views)
80
+ views.flatten!
81
+ views.select!{ |v| v.is_a?(UIView) }
82
+ RMQ.create_with_array_and_selectors(views, views, views.first, self)
83
+ end
84
+
85
+
86
+ # Untested and I don' think it's getting set right in some situations
87
+ #
88
+ # @return [RMQ] rmq that created this rmq, if any
89
+ def parent_rmq
90
+ @_parent_rmq
91
+ end
92
+ def parent_rmq=(value)
93
+ @_parent_rmq = value
94
+ end
95
+
64
96
  # The view(s) this rmq was derived from
65
97
  #
66
98
  # @return [Array]
67
99
  def origin_views
68
- if @parent_rmq
69
- @parent_rmq.selected
100
+ if pq = self.parent_rmq
101
+ pq.selected
70
102
  else
71
103
  [self.view_controller.view]
72
104
  end
@@ -96,7 +96,7 @@ module RubyMotionQuery
96
96
  # color.from_hex('#ffffff')
97
97
  # color.from_hex('ffffff')
98
98
  def from_hex(hex_color)
99
- hex_color.gsub!("#", "")
99
+ hex_color = hex_color.gsub("#", "")
100
100
  case hex_color.size
101
101
  when 3
102
102
  colors = hex_color.scan(%r{[0-9A-Fa-f]}).map{ |el| (el * 2).to_i(16) }
@@ -17,8 +17,18 @@ module RubyMotionQuery
17
17
  # rmq(my_view).tag(:foo)
18
18
  def tag(*tag_or_tags)
19
19
  tag_or_tags.flatten!
20
- tag_or_tags.each do |tag_name|
21
- tags[tag_name] = 1
20
+ tag_or_tags = tag_or_tags.first if tag_or_tags.length == 1
21
+
22
+ if tag_or_tags.is_a?(Array)
23
+ tag_or_tags.each do |tag_name|
24
+ tags[tag_name] = 1
25
+ end
26
+ elsif tag_or_tags.is_a?(Hash)
27
+ tag_or_tags.each do |tag_name, tag_value|
28
+ tags[tag_name] = tag_value
29
+ end
30
+ elsif tag_or_tags.is_a?(Symbol)
31
+ tags[tag_or_tags] = 1
22
32
  end
23
33
  end
24
34
 
@@ -15,18 +15,20 @@ module RubyMotionQuery
15
15
  class << self
16
16
 
17
17
  # @return [RMQ]
18
- def create_with_selectors(selectors, context)
18
+ def create_with_selectors(selectors, context, parent_rmq = nil)
19
19
  RMQ.new.tap do |o|
20
20
  o.context = context
21
+ o.parent_rmq = parent_rmq
21
22
  o.selectors = selectors
22
23
  end
23
24
  end
24
25
 
25
26
  # @return [RMQ]
26
- def create_with_array_and_selectors(array, selectors, context)
27
+ def create_with_array_and_selectors(array, selectors, context, parent_rmq = nil) # TODO, convert to opts
27
28
  RMQ.new.tap do |o|
28
29
  o.context = context
29
30
  o.selectors = selectors
31
+ o.parent_rmq = parent_rmq
30
32
  o.selected = array # Must be last
31
33
  end
32
34
  end
@@ -19,6 +19,13 @@ module RubyMotionQuery
19
19
  @view.titleColor
20
20
  end
21
21
 
22
+ def tint_color=(value)
23
+ @view.tintColor = value
24
+ end
25
+ def tint_color
26
+ @view.tintColor
27
+ end
28
+
22
29
  def image_normal=(value)
23
30
  @view.setImage value, forState: UIControlStateNormal
24
31
  end
@@ -27,6 +34,14 @@ module RubyMotionQuery
27
34
  @view.setImage value, forState: UIControlStateHighlighted
28
35
  end
29
36
 
37
+ def background_image_normal=(value)
38
+ @view.setBackgroundImage value, forState: UIControlStateNormal
39
+ end
40
+
41
+ def background_image_highlighted=(value)
42
+ @view.setBackgroundImage value, forState: UIControlStateHighlighted
43
+ end
44
+
30
45
  end
31
46
  end
32
47
  end
@@ -30,26 +30,24 @@ module RubyMotionQuery
30
30
 
31
31
  def frame=(value)
32
32
  if value == :full # Thanks teacup for the name
33
- value = self.superview.bounds
33
+ @view.frame = self.superview.bounds
34
34
  elsif value.is_a?(Hash)
35
+ f = @view.frame
35
36
  h = value
36
- h[:l] ||= (h[:left] || 0)
37
- h[:t] ||= (h[:top] || 0)
38
- h[:w] ||= (h[:width] || 0)
39
- h[:h] ||= (h[:height] || 0)
40
37
 
41
- value = [[h[:l], h[:t]], [h[:w], h[:h]]]
42
- end
38
+ f.origin.x = h[:l] || h[:left] || f.origin.x
39
+ f.origin.y = h[:t] || h[:top] || f.origin.y
40
+ f.size.width = h[:w] || h[:width] || f.size.width
41
+ f.size.height =h[:h] || h[:height] || f.size.height
43
42
 
44
- @view.frame = value
43
+ @view.frame = f
44
+ end
45
45
  end
46
46
  def frame
47
47
  @view.frame
48
48
  end
49
49
 
50
50
  def padded=(value)
51
- #st.padded = {l: 10, t: 10, b:10, r: 10}
52
-
53
51
  if value.is_a?(Hash)
54
52
  h = value
55
53
  h[:l] ||= (h[:left] || 0)
@@ -68,7 +66,6 @@ module RubyMotionQuery
68
66
 
69
67
  @view.frame = value
70
68
  end
71
-
72
69
  end
73
70
 
74
71
  def left=(value)
@@ -7,14 +7,20 @@ module RubyMotionQuery
7
7
  unless value.is_a?(RubyMotionQuery::Stylesheet)
8
8
  value = value.new(controller)
9
9
  end
10
+ @_stylesheet = value
10
11
  controller.rmq_data.stylesheet = value
11
12
  self
12
13
  end
13
14
 
14
- # @return [String]
15
+ # @return [RubyMotionQuery::Stylesheet]
15
16
  def stylesheet
16
17
  @_stylesheet ||= begin
17
- self.view_controller.rmq_data.stylesheet if self.view_controller
18
+
19
+ if self.view_controller && (ss = self.view_controller.rmq_data.stylesheet)
20
+ ss
21
+ elsif (prmq = self.parent_rmq) && prmq.stylesheet
22
+ prmq.stylesheet
23
+ end
18
24
  end
19
25
  end
20
26
 
@@ -24,22 +24,25 @@ module RubyMotionQuery
24
24
  end
25
25
 
26
26
  subviews_added << new_view
27
- if at_index = opts[:at_index]
28
- selected_view.insertSubview(new_view, atIndex: at_index)
29
- elsif below_view = opts[:below_view]
30
- selected_view.insertSubview(new_view, belowSubview: below_view)
31
- else
32
- selected_view.addSubview(new_view)
27
+
28
+ unless opts[:do_not_add]
29
+ if at_index = opts[:at_index]
30
+ selected_view.insertSubview(new_view, atIndex: at_index)
31
+ elsif below_view = opts[:below_view]
32
+ selected_view.insertSubview(new_view, belowSubview: below_view)
33
+ else
34
+ selected_view.addSubview(new_view)
35
+ end
33
36
  end
34
37
 
35
38
  if self.stylesheet
36
39
  apply_style_to_view(new_view, style) if style
37
40
  end
38
41
 
39
- new_view.rmq_did_create if created
42
+ new_view.rmq_did_create(self.wrap(new_view)) if created
40
43
  end
41
44
 
42
- RMQ.create_with_array_and_selectors(subviews_added, selectors, @context)
45
+ RMQ.create_with_array_and_selectors(subviews_added, selectors, @context, self)
43
46
  end
44
47
  alias :insert :add_subview
45
48
 
@@ -54,6 +57,30 @@ module RubyMotionQuery
54
57
  end
55
58
  alias :prepend :unshift
56
59
 
60
+ # Creates a view then returns an rmq with that view in it. It does not add that
61
+ # view to the view tree. This is useful for stuff like creating table cells. You
62
+ # can use the rmq_did_create method, just like you do when you append a subview
63
+ #
64
+ # @return [RMQ] wrapping the view that was just create
65
+ #
66
+ # @example
67
+ # def tableView(table_view, cellForRowAtIndexPath: index_path)
68
+ # cell = tableView.dequeueReusableCellWithIdentifier(CELL_IDENTIFIER) || begin
69
+ # rmq.create(StoreCell, :store_cell)
70
+ # end
71
+ # end
72
+ #
73
+ # class StoreCell < UITableViewCell
74
+ # def rmq_did_create(self_in_rmq)
75
+ # self_in_rmq.append(UILabel, :title_label)
76
+ # end
77
+ # end
78
+ #
79
+ def create(view_or_constant, style = nil)
80
+ # TODO, refactor so that add_subview uses create, not backwards like it is now
81
+ add_subview view_or_constant, style: style, do_not_add: true
82
+ end
83
+
57
84
  protected
58
85
 
59
86
  def create_view(klass)
@@ -1,6 +1,17 @@
1
1
  module RubyMotionQuery
2
2
  class RMQ
3
3
 
4
+ # Add tags
5
+ # @example
6
+ # rmq(my_view).tag(:your_tag)
7
+ # rmq(my_view).clear_tags.tag(:your_new_tag)
8
+ # rmq(my_view).find(UILabel).tag(:selected, :customer)
9
+ #
10
+ # You can optionally store a value in the tag, which can be super useful in some rare situations
11
+ # @example
12
+ # rmq(my_view).tag(your_tag: 22)
13
+ # rmq(my_view).tag(your_tag: 22, your_other_tag: 'Hello world')
14
+ #
4
15
  # @return [RMQ]
5
16
  def tag(*tag_or_tags)
6
17
  selected.each do |view|
@@ -9,7 +20,15 @@ module RubyMotionQuery
9
20
  self
10
21
  end
11
22
 
12
- # See /lib/data.rb for the rest of the tag stuff
23
+ # @return [RMQ]
24
+ def clear_tags
25
+ selected.each do |view|
26
+ view.rmq_data.tags.clear
27
+ end
28
+ self
29
+ end
30
+
31
+ # See /motion/data.rb for the rest of the tag stuff
13
32
 
14
33
  end
15
34
  end
@@ -27,9 +27,7 @@ module RubyMotionQuery
27
27
  if opts[:return_array]
28
28
  out
29
29
  else
30
- rmq = RMQ.create_with_array_and_selectors(out, selectors, @context)
31
- rmq.parent_rmq = self
32
- rmq
30
+ RMQ.create_with_array_and_selectors(out, selectors, @context, self)
33
31
  end
34
32
  end
35
33
 
@@ -77,11 +75,11 @@ module RubyMotionQuery
77
75
  # @example
78
76
  # rmq(my_view).children.and_self
79
77
  def and_self
80
- if @parent_rmq
81
- out = @parent_rmq.selected.dup
78
+ if self.parent_rmq
79
+ out = self.parent_rmq.selected.dup
82
80
  out << selected
83
81
  out.flatten!
84
- RMQ.create_with_array_and_selectors(out, selectors, @context)
82
+ RMQ.create_with_array_and_selectors(out, selectors, @context, self)
85
83
  else
86
84
  self
87
85
  end
@@ -93,7 +91,7 @@ module RubyMotionQuery
93
91
  # @example
94
92
  # rmq(test_view).find(UIImageView).tag(:foo).end.find(UILabel).tag(:bar)
95
93
  def end
96
- @parent_rmq || self
94
+ self.parent_rmq || self
97
95
  end
98
96
 
99
97
  # @return [RMQ] rmq instance selecting the parent of the selected view(s)
@@ -253,9 +251,11 @@ module RubyMotionQuery
253
251
  def view_controller
254
252
  @_view_controller ||= begin
255
253
  if @context.is_a?(UIViewController)
256
- @context
254
+ WeakRef.new(@context)
257
255
  else
258
- RMQ.controller_for_view(@context)
256
+ if vc = RMQ.controller_for_view(@context)
257
+ WeakRef.new(vc)
258
+ end
259
259
  end
260
260
  end
261
261
  end
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.3.0
4
+ version: 0.3.5
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-08-20 00:00:00.000000000 Z
12
+ date: 2013-09-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bacon
@@ -39,10 +39,11 @@ dependencies:
39
39
  - - ! '>='
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
- description: RubyMotionQuery - RMQ - A light, nonpolluting, jQuery-like library for
43
- RubyMotion
42
+ description: RubyMotionQuery - RMQ - A fast, non-magical, non-polluting, jQuery-like
43
+ library for RubyMotion
44
44
  email: todd@infinitered.com
45
- executables: []
45
+ executables:
46
+ - rmq
46
47
  extensions: []
47
48
  extra_rdoc_files: []
48
49
  files:
@@ -90,6 +91,7 @@ files:
90
91
  - motion/ruby_motion_query/tags.rb
91
92
  - motion/ruby_motion_query/traverse.rb
92
93
  - motion/ruby_motion_query/utils.rb
94
+ - bin/rmq
93
95
  homepage: http://infinitered.com/rmq
94
96
  licenses:
95
97
  - MIT