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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YWFmNzE0NjljMGNjYTRhYmYxYTIxMWQ3MGE1YTY1ODI0Y2E0M2EyNw==
4
+ MzUyNDAwZmQ1YTRmMzBiODg3YTMzY2VlMzNiYTA1ZTFjOWY2OGU3Yg==
5
5
  data.tar.gz: !binary |-
6
- M2RjODk1NDgyMmQ2ODc1MDFlZjc2ODg3YWVkMzMwZTk5YWNiMTMxZA==
6
+ ZTljMmU0NDcyZDFjNWEyZjEzZGYzZWQ0YjY1YmEzZjUyOWJkZDY1YQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- Y2MxY2YyZGU0ZDdiZmQxNzAwNTk3NWFlNjA2NGUzNmJhMzVkYTMzMWUxN2Ri
10
- NjBlNmZiYjEzNWY2Nzc2ZDcyZTlmNmU4NDZlOTk3MDM3ZmQ2MWExYjY3YjI2
11
- ODkzZWFlNmI4ZThlODAzMTczYjU4MTAzOWI5YWI3Yjk3MzgzNTQ=
9
+ NDU2MGU1YmJiNmQzZGFhMjExZWVlYTVmN2IwMzkyN2E0NTBiODQwMjU1NzRh
10
+ ZmQ1M2JhZDExMmE4N2FkMjY5NDNmNzdiOTE5OWVkNjk0ODM0MWFhY2FhMTJj
11
+ MTEwNzAwOWM0MzY0ZGI0M2NhM2QxNmYxMmEyOWY2YzE0YTNlNzQ=
12
12
  data.tar.gz: !binary |-
13
- YjRlNjg1YjRkNzk5MmYwYzZiZWY2MjJmYTc5ZWRjZWRhZmZlMTVjZWZlNTVm
14
- ZTQ3Yjg5M2I4YWJjZDM0MDk4ODBiMzJhYzUxOGRlOTI3NGIwYzZlOWJlOGE1
15
- YzljNTlhMTkzMDZlNGVkMzE3MjhjZWEzM2U5M2RhMDY1NDQ5YTc=
13
+ NTY2NTJmNzhmZTE5YjcyZTcxYTc5ZjcxZDk2ZjBjYjAxYTU5MDc1OTE2NGRi
14
+ YjkyMzNkNGYzMmU3NGQwNTcxYjMwODA4Mjg3MTk4M2IzNGRlNWQwMjBlYWRl
15
+ NGVlMDdkN2FjNjE0YzRiZDJjNjdkNzkyMjhjYjIxMDlmNWNjYjY=
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  ![RQM logo](http://ir_wp.s3.amazonaws.com/wp-content/uploads/sites/9/2013/07/rmq_logo.png)
2
2
 
3
3
  # RubyMotionQuery - RMQ
4
- A fast, muggle, nonpolluting, jQuery-like library for [RubyMotion](http://rubymotion.com).
4
+ A fast, muggle, nonpolluting, zero-dependency, jQuery-like library for [RubyMotion](http://rubymotion.com).
5
5
 
6
6
  **The [RMQ Introductory Guide and other info][1] is a great place to start.**
7
7
 
8
8
  [![Dependency Status](https://gemnasium.com/infinitered/rmq.png)](https://gemnasium.com/infinitered/rmq)
9
9
  [![Build Status](https://travis-ci.org/infinitered/rmq.png?branch=master)](https://travis-ci.org/infinitered/rmq)
10
-
10
+ [![Gem Version](https://badge.fury.io/rb/ruby_motion_query.png)](http://badge.fury.io/rb/ruby_motion_query)
11
11
 
12
12
  ## General
13
13
 
@@ -33,7 +33,7 @@ A fast, muggle, nonpolluting, jQuery-like library for [RubyMotion](http://rubymo
33
33
  ### Other wrapper libraries
34
34
  There are a lot of great wrappers out there such as Teacup and Sugarcube. I've used these and I enjoy them. However, many of the wrappers heavily pollute the standard classes, which is great if you like that sort of thing. RMQ is designed to have minimal pollution, to be very simple and high performance (it will be when it's done). RMQ shouldn't conflict with anything.
35
35
 
36
- RMQ **doesn't require any** other wrapper or gem.
36
+ RMQ **doesn't require any** other wrapper or gem.
37
37
 
38
38
  > If you preferred jQuery over Prototype, you'll love RMQ.
39
39
 
@@ -83,6 +83,12 @@ for **bleeding edge**, add this to your `Gemfile`:
83
83
 
84
84
  - `gem 'ruby_motion_query', :git => 'git@github.com:infinitered/rmq.git'`
85
85
 
86
+
87
+ ## Deprecation
88
+
89
+ - **UIView#rmq_did_create(self_in_rmq)** - *Use rmq_build instead*
90
+
91
+
86
92
  ## Usage
87
93
 
88
94
  ### Example App
@@ -98,7 +104,7 @@ The example app works in any orientation, on both iPhone and iPad. Notice how th
98
104
 
99
105
  - an rmq instance is an array-like object containing UIViews
100
106
  - rmq() never returns nil. If nothing is selected, it's an empty [ ] array-like
101
- object
107
+ object
102
108
  - an rmq object always (almost always) returns either itself or a new
103
109
  rmq object. This is how chaining works. You do not need to worry if
104
110
  an rmq is blank or not, everything always works without throwing a
@@ -183,7 +189,7 @@ Here are the commands available to you:
183
189
  > rmq create shared some_class_used_app_wide
184
190
  > rmq create lib some_class_used_by_multiple_apps
185
191
 
186
- > rmq create collection_view_controller foos
192
+ > rmq create collection_view_controller foos
187
193
 
188
194
  # To test the create command without actually creating any files, do:
189
195
  > rmq create view my_view dry_run
@@ -208,7 +214,7 @@ Here are the commands available to you:
208
214
  - and
209
215
  - not
210
216
  - and_self
211
- - end
217
+ - back - rmq(test_view).find(UIImageView).tag(:foo).back.find(UILabel).tag(:bar)
212
218
  - find
213
219
  - children
214
220
  - siblings
@@ -242,7 +248,7 @@ all return another rmq instance, so you can chain.
242
248
 
243
249
  You can also do **rmq.length** and **rmq[0]** like an array
244
250
 
245
- **.to_a** gives you an actual array, so will **.get** (this is preferred)
251
+ **.to_a** gives you an actual array, so will **.get** (this is preferred)
246
252
 
247
253
  ### Events and Gestures
248
254
 
@@ -309,7 +315,7 @@ If you see Event, just remember that's either an event or gesture. I decided to
309
315
  :system
310
316
  :all
311
317
 
312
- # Gestures
318
+ # Gestures
313
319
  :tap
314
320
  :pinch
315
321
  :rotate
@@ -405,21 +411,21 @@ rmq.view_controller
405
411
 
406
412
  #### Create a view
407
413
  If you want to create a view but not add it to the subviews of any other view, you can
408
- use #create. It's basically #append without the actual appending.
414
+ use #create. It's basically #append without the actual appending.
409
415
  This is very handy for stuff like table cells:
410
416
 
411
417
  ```ruby
412
418
  # In your controller that is a delegate for a UITableView
413
419
  def tableView(table_view, cellForRowAtIndexPath: index_path)
414
- cell = tableView.dequeueReusableCellWithIdentifier(CELL_IDENTIFIER) || begin
415
- rmq.create(StoreCell, :store_cell)
420
+ cell = table_view.dequeueReusableCellWithIdentifier(CELL_IDENTIFIER) || begin
421
+ rmq.create(StoreCell, :store_cell, cell_identifier: CELL_IDENTIFIER).get
416
422
  end
417
423
  end
418
424
 
419
425
  # Your cell
420
- class StoreCell < UITableViewCell
421
- def rmq_did_create(self_in_rmq)
422
- self_in_rmq.append(UILabel, :title_label) # <- this works even though this object isn't in a controller
426
+ class StoreCell < UITableViewCell
427
+ def rmq_build
428
+ rmq(self).append(UILabel, :title_label) # <- this works even though this object isn't in a controller
423
429
  end
424
430
  end
425
431
  ```
@@ -436,14 +442,14 @@ rmq(my_view).animate(
436
442
  ```
437
443
 
438
444
  ```ruby
439
- # As an example, this is the implementation of .animations.throb
445
+ # As an example, this is the implementation of .animations.throb
440
446
  rmq(selectors).animate(
441
447
  duration: 0.1,
442
448
  animations: -> (q) {
443
449
  q.style {|st| st.scale = 1.1}
444
450
  },
445
451
  completion: -> (did_finish, q) {
446
- q.animate(
452
+ q.animate(
447
453
  duration: 0.4,
448
454
  animations: -> (cq) {
449
455
  cq.style {|st| st.scale = 1.0}
@@ -457,7 +463,7 @@ rmq(selectors).animate(
457
463
 
458
464
  ### Animations
459
465
 
460
- #### Current animations included:
466
+ #### Current animations included:
461
467
 
462
468
  ```ruby
463
469
  rmq(my_view).animations.fade_in
@@ -483,7 +489,7 @@ rmq.color.from_rgba(128, 128, 128, 0.5)
483
489
 
484
490
  # Add a new standard color
485
491
  rmq.color.add_named :pitch_black, '#000000'
486
- # Or
492
+ # Or
487
493
  rmq.color.add_named :pitch_black, rmq.color.black
488
494
 
489
495
  # In a stylesheet you don't need the rmq
@@ -503,7 +509,7 @@ rmq.font.for_family('Helvetica') # useful in console
503
509
  font_family = 'Helvetica Neue'
504
510
  font.add_named :large, font_family, 36
505
511
  font.add_named :medium, font_family, 24
506
- font.add_named :small, font_family, 18
512
+ font.add_named :small, font_family, 18
507
513
 
508
514
  # then use them like so
509
515
  rmq.font.large
@@ -576,7 +582,7 @@ rmq.device.iphone?
576
582
  rmq.device.four_inch?
577
583
  rmq.device.retina?
578
584
 
579
- # return values are :unkown, :portrait, :portrait_upside_down, :landscape_Left,
585
+ # return values are :unkown, :portrait, :portrait_upside_down, :landscape_Left,
580
586
  # :landscape_right, :face_up, :face_down
581
587
  rmq.device.orientation
582
588
  rmq.device.landscape?
@@ -603,23 +609,25 @@ RubyMotionQuery::RMQ.is_class?(foo)
603
609
  RubyMotionQuery::RMQ.is_blank?(foo)
604
610
  RubyMotionQuery::RMQ.controller_for_view(view)
605
611
  RubyMotionQuery::RMQ.view_to_s(view)
612
+ RubyMotionQuery::RMQ.weak_ref(foo)
606
613
  ```
607
614
 
608
- ### Pollution
615
+ ### Pollution
609
616
 
610
617
  The following are the only pollution in RMQ
611
618
 
612
619
  - UIView
613
- - rmq
614
- - rmq_data
620
+ - rmq
621
+ - rmq_data
615
622
  - UIViewController
616
- - rmq
617
- - rmq_data
618
- - TopLevel *(Only in development, used for console)*
619
- - rmq
623
+ - rmq
624
+ - rmq_data
625
+ - Object
626
+ - rmq
620
627
 
621
628
  ### Console Fun
622
629
 
630
+ rmq.log :tree
623
631
  rmq.all.log
624
632
  rmq.all.log :wide
625
633
  rmq(UIView).show
@@ -635,7 +643,7 @@ The following are the only pollution in RMQ
635
643
  - models
636
644
  - shared
637
645
  - stylers
638
- - ui_view_styler.rb
646
+ - ui_view_styler.rb
639
647
  - ui_button_styler.rb
640
648
  - etc
641
649
  - stylesheets
@@ -654,7 +662,7 @@ The following are the only pollution in RMQ
654
662
  - stylers
655
663
  - views
656
664
 
657
- ### Debugging
665
+ ### Debugging
658
666
 
659
667
  Adding rmq_debug=true to rake turns on some debugging features that are too slow or verbose to include in a normal build. It's great for normal use in the simulator, but you'll want to leave it off if you're measuring performance.
660
668
  ```
@@ -750,10 +758,10 @@ class ApplicationStylesheet < RubyMotionQuery::Stylesheet
750
758
  font_family = 'Helvetica Neue'
751
759
  font.add_named :large, font_family, 36
752
760
  font.add_named :medium, font_family, 24
753
- font.add_named :small, font_family, 18
761
+ font.add_named :small, font_family, 18
754
762
 
755
- color.add_named :translucent_black, color.from_rgba(0, 0, 0, 0.4)
756
- color.add_named :battleship_gray, '#7F7F7F'
763
+ color.add_named :translucent_black, color.from_rgba(0, 0, 0, 0.4)
764
+ color.add_named :battleship_gray, '#7F7F7F'
757
765
  end
758
766
 
759
767
  def label(st)
@@ -905,7 +913,7 @@ class MainStylesheet < ApplicationStylesheet
905
913
  end
906
914
 
907
915
  def overlay(st)
908
- st.frame = :full
916
+ st.frame = :full
909
917
  st.background_color = color.translucent_black
910
918
  st.hidden = true
911
919
  st.z_position = 99
@@ -1058,13 +1066,13 @@ end
1058
1066
 
1059
1067
  #### Add your own stylers
1060
1068
 
1061
- In the example app, look in **/app/stylers**, you can just copy that whole folder to start. Then add methods to the appropriate class.
1069
+ In the example app, look in **/app/stylers**, you can just copy that whole folder to start. Then add methods to the appropriate class.
1062
1070
 
1063
1071
  Here is an example of adding a method to all stylers:
1064
1072
  ```ruby
1065
1073
  module RubyMotionQuery
1066
1074
  module Stylers
1067
- class UIViewStyler
1075
+ class UIViewStyler
1068
1076
 
1069
1077
  def border_width=(value)
1070
1078
  @view.layer.borderWidth = value
@@ -1072,7 +1080,7 @@ module RubyMotionQuery
1072
1080
  def border_width
1073
1081
  @view.layer.borderWidth
1074
1082
  end
1075
-
1083
+
1076
1084
  end
1077
1085
  end
1078
1086
  end
@@ -1083,20 +1091,34 @@ You can also include all of your custom stylers in one file, which works well if
1083
1091
 
1084
1092
  ### Creating your own views
1085
1093
 
1086
- If you use RMQ's stylesheets and you create your own views, you should add your subviews and such in this method:
1094
+ RMQ calls 3 methods when you create, append, or build a view using rmq. rmq_build is the one you most want to use
1087
1095
  ```ruby
1088
- def rmq_did_create
1096
+ def rmq_build
1097
+ end
1098
+
1099
+ def rmq_created
1089
1100
  end
1101
+
1102
+ def rmq_appended
1103
+ end
1104
+ ```
1105
+ If you append a view like so:
1106
+ ```ruby
1107
+ rmq.append(UILabel)
1090
1108
  ```
1109
+ The 3 methods will be called in this order:
1110
+ - rmq_created
1111
+ - rmq_appended
1112
+ - rmq_build
1091
1113
 
1092
1114
  In the following example an instance of YourView is created, :your_style is applied
1093
- then rmq_did_create is called on the instance that was just created. In that
1115
+ then rmq_build is called on the instance that was just created. In that
1094
1116
  order.
1095
1117
 
1096
1118
  ```ruby
1097
1119
  # Your view
1098
1120
  class YourView < UIView
1099
- def rmq_did_create
1121
+ def rmq_build
1100
1122
  rmq(self).tap do |q|
1101
1123
  q.append(UILabel, :section_title)
1102
1124
  q.append(UIButton, :buy_button).on(:tap) do |sender|
@@ -1105,20 +1127,37 @@ class YourView < UIView
1105
1127
  end
1106
1128
  end
1107
1129
  end
1108
-
1130
+
1109
1131
  # In your controller
1110
1132
  rmq.append(YourView, :your_style)
1111
1133
  ```
1112
1134
 
1113
1135
  ### Future features
1114
1136
 
1115
- Future features that I plan on adding
1137
+ Current roadmap:
1138
+
1139
+ - v0.5 new view_controller system: which solves the #1 problem in rmq: having to pass rmq around in things like cells. rmq command will work everywhere
1140
+ - v0.6 new frame system: I’ve already designed this, I just have to implement it and use it in the real world and tweak. This is going to be very cool. It adds to the existing frame system. It doesn’t replace constraints, but rather gives you almost all the features you need without the complexity of constraints.
1141
+ - v0.6.5 templates and stylers all finished
1142
+ - v0.6.7 performance improvements
1143
+ - v0.7 first rmq plugin and any base features needed to support plugins (I don’t think there will be any base features needed)
1144
+ - v0.8 binding system
1145
+ - ?
1146
+ - ?
1147
+ - v1.0
1148
+
1149
+ Random future features that I plan on adding
1116
1150
 
1117
1151
  - rmq.push_sub_controller(my_controller) and rmq.pop_sub_controller and rmq.pop_this_controller
1118
1152
  - add borders to UIView styler: st.borders = {l: {w: 2, color: color.black}, r: {w: 2, color: color.black}}
1119
1153
  - add templates for: nav controller, tab controller, table controller, collection controller
1120
1154
  - add from_right, from_bottom, and centered to both st.frame and to move
1121
1155
  - add binding that combines KVO and events to bind an attribute of one object to the attribute of selected view(s), keeping both in sync, like so: rmq.append(UITextField).bind(@person, attr: :name, to: :text)
1156
+ - rmq.log to wrap nslog to allow you to turn off logging (or does NSLog already have this feature?)
1157
+ - add selectors for UITextField
1158
+ - add string to height utility, given the font and the width
1159
+ - add block to wrap useful for a variety of things, but here is solid example: rmq.append(UIButton).tag(:foo).wrap{|view| view.titleLabel}.tag(:foo_title)
1160
+ - add def rmq_build_with_properties(props = {}). Perhaps remove rmq_created and rmq_appended, not sure if those are usefull or not
1122
1161
 
1123
1162
 
1124
1163
  ## Contact
@@ -1145,6 +1184,6 @@ RMQ is available under the MIT license. See the LICENSE file for more info.
1145
1184
  2. Create your feature branch (`git checkout -b my-new-feature`)
1146
1185
  3. Commit your changes (`git commit -am 'Add some feature'`)
1147
1186
  4. Push to the branch (`git push origin my-new-feature`)
1148
- 5. Create new Pull Request
1187
+ 5. Create new Pull Request
1149
1188
 
1150
1189
  [1]: http://infinitered.com/rmq
data/motion/ext.rb CHANGED
@@ -1,33 +1,28 @@
1
+ class Object
2
+ def rmq(*working_selectors)
3
+ if window = RubyMotionQuery::RMQ.app.window
4
+ RubyMotionQuery::RMQ.app.current_view_controller.rmq(working_selectors)
5
+ end
6
+ end
7
+ end
8
+
1
9
  class UIView
2
10
  def rmq_data
3
11
  @_rmq_data ||= RubyMotionQuery::ViewData.new
4
12
  end
5
13
 
6
- # Override in your view if you want to setup subviews after your view has
7
- # been created by rmq, usually through an #append or #create
8
- #
9
- # @param [RMQ] rmq that created your view
10
- #
11
- # In your view
12
- # @example
13
- # def rmq_did_create(self_in_rmq)
14
- # self_in_rmq.tap do |q|
15
- # q.append(UILabel, :section_title)
16
- # q.append(UIButton, :buy_button).on(:tap) do |sender|
17
- # # do something
18
- # end
19
- # end
20
- # end
21
- #
22
- # In your controller
23
- # @example
24
- # rmq.append(YourView, :your_style)
25
- #
26
- # In this example an instance of YourView is created, :your_style is applied
27
- # then rmq_did_create is called on the instance that was just created. In that
28
- # order.
14
+ # @deprecated No longer needed, use rmq_build
29
15
  def rmq_did_create(self_in_rmq)
30
16
  end
17
+ def rmq_created
18
+ end
19
+
20
+ # Override this to build your view and view's subviews
21
+ def rmq_build
22
+ end
23
+
24
+ def rmq_appended
25
+ end
31
26
 
32
27
  # I intend for this to be protected
33
28
  # Do not call rmq from outside a view. Because of some weirdness with table cells
@@ -36,17 +31,23 @@ class UIView
36
31
  # Technically my_view.rmq is the same as rmq(my_view), so it may seem enticing to use
37
32
  # but the really nice thing about rmq is its consistent API, and doing this
38
33
  # for one view: my_view.rmq and this for two views: rmq(my_view, my_other_view) sucks
39
- def rmq(*selectors)
40
- RubyMotionQuery::RMQ.create_with_selectors(selectors, self)
34
+ def rmq(*working_selectors)
35
+ RubyMotionQuery::RMQ.create_with_selectors(working_selectors, self).tap do |o|
36
+ if vc = self.rmq_data.view_controller
37
+ o.weak_view_controller = vc
38
+ end
39
+ end
41
40
  end
42
41
  end
43
42
 
44
43
  class UIViewController
45
- def rmq(*selectors)
46
- if RubyMotionQuery::RMQ.cache_controller_rmqs && selectors.length == 0
47
- rmq_data.rmq ||= RubyMotionQuery::RMQ.create_with_selectors(selectors, self)
44
+ def rmq(*working_selectors)
45
+ crmq = (rmq_data.cached_rmq ||= RubyMotionQuery::RMQ.create_with_selectors([], self))
46
+
47
+ if working_selectors.length == 0
48
+ crmq
48
49
  else
49
- RubyMotionQuery::RMQ.create_with_selectors(selectors, self, rmq_data.rmq)
50
+ RubyMotionQuery::RMQ.create_with_selectors(working_selectors, self, crmq)
50
51
  end
51
52
  end
52
53
 
@@ -54,12 +55,3 @@ class UIViewController
54
55
  @_rmq_data ||= RubyMotionQuery::ControllerData.new
55
56
  end
56
57
  end
57
-
58
- # Used in console, so that you can just call rmq with an view or controller as self
59
- class TopLevel
60
- def rmq(*selectors)
61
- if window = RubyMotionQuery::RMQ.app.window
62
- RubyMotionQuery::RMQ.create_with_selectors(selectors, window.subviews.first)
63
- end
64
- end
65
- end