ruby_motion_query 0.2.0 → 0.3.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
- ZjFmZTc0N2Y5NDViYjkyNGI3MjQ0MmFhZmQxNmQ3NzRiMzY3YzRkNQ==
4
+ ZWQyYzBmYzcxMmJhZDQwMGYzZDU1ZWFiYWRjNDBlMmM1YTU4YjY5Ng==
5
5
  data.tar.gz: !binary |-
6
- ZjU1NWJhMmE3MmZkNGRjNDIyYzJjNjE0YTdmOGNlYzcxNDE3MTMzMQ==
6
+ YjA0YzdiMDkwN2YzOWY1NDAwMDNlNzIwMzQxYTA1Njc3ZmY1NTBiZA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZDA4NThmZjhhYjhlM2ViZjBiYzI4NzFlYjg0NzdlYTllMGQyNzE3Y2ZiZGQ1
10
- YjE3M2JmNzc0ZmRhMzVhYWIxYzg5ZjdhMGEyYzFiYTg2ZmQyM2E5YzlhNDNl
11
- MGYxNDUyOTE5NDJkODljYjc3MmMwYTI1ZDZjNzgwNGI2NDhiMmI=
9
+ ZThjYTAzM2U3ZGExYzBkY2I2NmZmY2NiZDRjYjc5MjZmNzVhY2Y1Mzg5MGQ1
10
+ ZTU3MmY5OTkzMTQ5YjQzYmRmNzQ0MzI2MTQxZWRlYmYyNzljNzViN2Q3YWE3
11
+ MjIyODE5YTg3NTllMTYzN2E5ZjA4ZTNlYjVjZmUwZjgwNzE2MGE=
12
12
  data.tar.gz: !binary |-
13
- YWNkY2Q3YjgyYTJhM2EzZmYxNTcyMzI5MTM2NzU5OGFjNGVlY2U5NDg1YzM2
14
- MmI5ZDc4Y2ZkNGE1YTUwNDA1MzA5OTdkODFhZjVkZGNlZmYzZWM2ZjU1OGQ1
15
- NmJmZWQ2OTFiZjllMDA4YjA0YmQ4ZTUzNDI0NGE0ODU3ZjU3MWY=
13
+ ZjU3MWUzYzFiZDFmYzkzYTA2ZjViYTQ2OTVkZTdjNDQ5NWY2NTBhNTcyODAy
14
+ MGM0MzE4ODI5ZjkxNDcyNzdiYzJiZDZiZDRmZjIyMzY1ZWVkMzAwMjdjYmMz
15
+ ZWYxZTM4M2VkODA2Mzk4OWQyNTY4NTA4ZjdmODNkZmI3NTA1ZGI=
data/README.md CHANGED
@@ -51,6 +51,9 @@ or add it to your `Gemfile`:
51
51
 
52
52
  - `gem 'ruby_motion_query'`
53
53
 
54
+ for **bleeding edge**, add this to your `Gemfile`:
55
+
56
+ - `gem 'ruby_motion_query', :git => 'git@github.com:infinitered/rmq.git'`
54
57
 
55
58
  ## Usage
56
59
 
@@ -159,7 +162,9 @@ rmq(UILabel).get
159
162
  - parents
160
163
  - filter
161
164
  - view_controller
162
- - root_view
165
+ - root_view # View of the view_controller
166
+ - window # Window of the root_view
167
+
163
168
 
164
169
  ### Enumerablish
165
170
  A rmq object is like an enumerable, but each method returns a rmq object instead of a enumerable. For example, these methods:
@@ -567,7 +572,10 @@ class MainController < UIViewController
567
572
  view.rmq.apply_style :root_view
568
573
 
569
574
  @title_label = rmq.append(UILabel, :title_label).get
570
- rmq.append UIImageView, :logo
575
+
576
+ image_view = rmq.append(UIImageView).get
577
+ # Apply style anywhere
578
+ image_view.apply_style(:logo)
571
579
 
572
580
  rmq.append(UIButton, :make_labels_blink).on(:tap) do |sender|
573
581
  rmq(UILabel).animations.blink
@@ -940,6 +948,36 @@ end
940
948
  You can also include all of your custom stylers in one file, which works well if you don't have a lot.
941
949
 
942
950
 
951
+ ### Creating your own views
952
+
953
+ If you use RMQ's stylesheets and you create your own views, you should add your subviews and such in this method:
954
+ ```ruby
955
+ def rmq_did_create
956
+ end
957
+ ```
958
+
959
+ In the following example an instance of YourView is created, :your_style is applied
960
+ then rmq_did_create is called on the instance that was just created. In that
961
+ order.
962
+
963
+ ```ruby
964
+ # Your view
965
+ class YourView < UIView
966
+ def rmq_did_create
967
+ rmq(self).tap do |q|
968
+ q.append(UILabel, :section_title)
969
+ q.append(UIButton, :buy_button).on(:tap) do |sender|
970
+ # do something
971
+ end
972
+ end
973
+ end
974
+ end
975
+
976
+ # In your controller
977
+ rmq.append(YourView, :your_style)
978
+ ```
979
+
980
+
943
981
  ## Contact
944
982
 
945
983
  created by **Todd Werth** ([http://toddwerth.com](http://toddwerth.com))
@@ -4,5 +4,9 @@ end
4
4
 
5
5
  Motion::Project::App.setup do |app|
6
6
  parent = File.join(File.dirname(__FILE__), '..')
7
- app.files.unshift(Dir.glob(File.join(parent, "motion/**/*.rb")))
7
+ files = [File.join(parent, 'motion/ruby_motion_query/stylers/ui_view_styler.rb')]
8
+ files << File.join(parent, 'motion/ruby_motion_query/stylers/ui_control_styler.rb')
9
+ files << Dir.glob(File.join(parent, "motion/**/*.rb"))
10
+ files.flatten!.uniq!
11
+ app.files.unshift files
8
12
  end
data/motion/ext.rb CHANGED
@@ -3,10 +3,34 @@ class UIView
3
3
  @_rmq_data ||= RubyMotionQuery::ViewData.new
4
4
  end
5
5
 
6
+ # Override in your view if you want to setup subviews after your view has
7
+ # been created by rmq, usually through an #append
8
+ #
9
+ # In your view
10
+ # @example
11
+ # def rmq_did_create
12
+ # rmq(self).tap do |q|
13
+ # q.append(UILabel, :section_title)
14
+ # q.append(UIButton, :buy_button).on(:tap) do |sender|
15
+ # # do something
16
+ # end
17
+ # end
18
+ # end
19
+ #
20
+ # In your controller
21
+ # @example
22
+ # rmq.append(YourView, :your_style)
23
+ #
24
+ # In this example an instance of YourView is created, :your_style is applied
25
+ # then rmq_did_create is called on the instance that was just created. In that
26
+ # order.
27
+ def rmq_did_create
28
+ end
29
+
6
30
  protected
7
31
 
8
32
  def rmq(*selectors)
9
- RubyMotionQuery::RMQ.create_with_selectors(selectors, RubyMotionQuery::RMQ.controller_for_view(self))
33
+ RubyMotionQuery::RMQ.create_with_selectors(selectors, self)
10
34
  end
11
35
  end
12
36
 
@@ -12,10 +12,14 @@ module RubyMotionQuery
12
12
  def add_subview(view_or_constant, opts={})
13
13
  subviews_added = []
14
14
  style = opts[:style]
15
+
15
16
  selected.each do |selected_view|
17
+ created = false
18
+
16
19
  if view_or_constant.is_a?(UIView)
17
20
  new_view = view_or_constant
18
21
  else
22
+ created = true
19
23
  new_view = create_view(view_or_constant)
20
24
  end
21
25
 
@@ -31,6 +35,8 @@ module RubyMotionQuery
31
35
  if self.stylesheet
32
36
  apply_style_to_view(new_view, style) if style
33
37
  end
38
+
39
+ new_view.rmq_did_create if created
34
40
  end
35
41
 
36
42
  RMQ.create_with_array_and_selectors(subviews_added, selectors, @context)
@@ -46,6 +52,7 @@ module RubyMotionQuery
46
52
  def unshift(view_or_constant, style = nil)
47
53
  add_subview view_or_constant, style: style, at_index: 0
48
54
  end
55
+ alias :prepend :unshift
49
56
 
50
57
  protected
51
58
 
@@ -273,6 +273,14 @@ module RubyMotionQuery
273
273
  end
274
274
  end
275
275
 
276
+ # @return [UIWindow] Window of the root_view
277
+ #
278
+ # @example
279
+ # rmq.window
280
+ def window
281
+ self.root_view.window
282
+ end
283
+
276
284
  protected
277
285
 
278
286
  def closest_view(view, working_selectors)
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.2.0
4
+ version: 0.3.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-08-06 00:00:00.000000000 Z
12
+ date: 2013-08-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bacon