ruby_motion_query 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +15 -0
  2. data/LICENSE +21 -0
  3. data/README.md +964 -0
  4. data/lib/ruby_motion_query.rb +8 -0
  5. data/motion/ext.rb +34 -0
  6. data/motion/ruby_motion_query/actions.rb +44 -0
  7. data/motion/ruby_motion_query/animations.rb +125 -0
  8. data/motion/ruby_motion_query/app.rb +71 -0
  9. data/motion/ruby_motion_query/base.rb +161 -0
  10. data/motion/ruby_motion_query/color.rb +80 -0
  11. data/motion/ruby_motion_query/data.rb +32 -0
  12. data/motion/ruby_motion_query/device.rb +73 -0
  13. data/motion/ruby_motion_query/enumerablish.rb +74 -0
  14. data/motion/ruby_motion_query/event.rb +125 -0
  15. data/motion/ruby_motion_query/events.rb +65 -0
  16. data/motion/ruby_motion_query/factory.rb +32 -0
  17. data/motion/ruby_motion_query/font.rb +66 -0
  18. data/motion/ruby_motion_query/format.rb +54 -0
  19. data/motion/ruby_motion_query/image.rb +79 -0
  20. data/motion/ruby_motion_query/position.rb +45 -0
  21. data/motion/ruby_motion_query/selectors.rb +56 -0
  22. data/motion/ruby_motion_query/stylers/ui_button_styler.rb +32 -0
  23. data/motion/ruby_motion_query/stylers/ui_control_styler.rb +8 -0
  24. data/motion/ruby_motion_query/stylers/ui_date_picker_styler.rb +8 -0
  25. data/motion/ruby_motion_query/stylers/ui_image_view_styler.rb +14 -0
  26. data/motion/ruby_motion_query/stylers/ui_label_styler.rb +36 -0
  27. data/motion/ruby_motion_query/stylers/ui_navigation_bar_styler.rb +8 -0
  28. data/motion/ruby_motion_query/stylers/ui_page_control_styler.rb +8 -0
  29. data/motion/ruby_motion_query/stylers/ui_refresh_control_styler.rb +8 -0
  30. data/motion/ruby_motion_query/stylers/ui_scroll_view_styler.rb +10 -0
  31. data/motion/ruby_motion_query/stylers/ui_segmented_control_styler.rb +8 -0
  32. data/motion/ruby_motion_query/stylers/ui_slider_styler.rb +8 -0
  33. data/motion/ruby_motion_query/stylers/ui_stepper_styler.rb +8 -0
  34. data/motion/ruby_motion_query/stylers/ui_switch_styler.rb +10 -0
  35. data/motion/ruby_motion_query/stylers/ui_tab_bar_styler.rb +8 -0
  36. data/motion/ruby_motion_query/stylers/ui_table_view_cell_styler.rb +8 -0
  37. data/motion/ruby_motion_query/stylers/ui_table_view_styler.rb +8 -0
  38. data/motion/ruby_motion_query/stylers/ui_text_field_styler.rb +8 -0
  39. data/motion/ruby_motion_query/stylers/ui_text_view_styler.rb +8 -0
  40. data/motion/ruby_motion_query/stylers/ui_view_styler.rb +243 -0
  41. data/motion/ruby_motion_query/stylesheet.rb +185 -0
  42. data/motion/ruby_motion_query/subviews.rb +52 -0
  43. data/motion/ruby_motion_query/tags.rb +14 -0
  44. data/motion/ruby_motion_query/traverse.rb +183 -0
  45. data/motion/ruby_motion_query/utils.rb +53 -0
  46. metadata +89 -0
@@ -0,0 +1,183 @@
1
+ module RubyMotionQuery
2
+ class RMQ
3
+
4
+ # Most everthing uses filter to do its work
5
+ def filter(opts = {}, &block)
6
+ out = []
7
+ limit = opts[:limit]
8
+
9
+ selected.each do |view|
10
+ results = yield(view)
11
+ unless RMQ.is_blank?(results)
12
+ out << results
13
+ break if limit && (out.length >= limit)
14
+ end
15
+ end
16
+ out.flatten!
17
+ out.uniq! if opts[:uniq]
18
+
19
+ if opts[:return_array]
20
+ out
21
+ else
22
+ rmq = RMQ.create_with_array_and_selectors(out, selectors, @context)
23
+ rmq.parent_rmq = self
24
+ rmq
25
+ end
26
+ end
27
+
28
+ def all
29
+ self.view_controller.rmq.find
30
+ end
31
+
32
+ def and(*working_selectors)
33
+ return self unless working_selectors
34
+ normalize_selectors(working_selectors)
35
+
36
+ self.select do |view|
37
+ match(view, working_selectors)
38
+ end
39
+ end
40
+
41
+ def not(*working_selectors)
42
+ return self unless working_selectors
43
+ normalize_selectors(working_selectors)
44
+
45
+ self.reject do |view|
46
+ match(view, working_selectors)
47
+ end
48
+ end
49
+
50
+ # Return any selected that has a child that matches the selectors
51
+ #def has
52
+ #end
53
+
54
+ def and_self
55
+ if @parent_rmq
56
+ out = @parent_rmq.selected.dup
57
+ out << selected
58
+ out.flatten!
59
+ RMQ.create_with_array_and_selectors(out, selectors, @context)
60
+ else
61
+ self
62
+ end
63
+ end
64
+ alias :add_self :and_self
65
+
66
+ def end
67
+ @parent_rmq || self
68
+ end
69
+
70
+ def parent
71
+ closest(UIView)
72
+ end
73
+ alias :superview :parent
74
+
75
+ def parents(*working_selectors)
76
+ normalize_selectors(working_selectors)
77
+
78
+ filter(uniq: true) do |view|
79
+ superviews = all_superviews_for(view)
80
+
81
+ if RMQ.is_blank?(working_selectors)
82
+ superviews
83
+ else
84
+ superviews.inject([]) do |subview, out|
85
+ out << subview if match(subview, working_selectors)
86
+ out
87
+ end
88
+ end
89
+ end
90
+ end
91
+ alias :superviews :parents
92
+
93
+ def find(*working_selectors)
94
+ normalize_selectors(working_selectors)
95
+
96
+ filter(uniq: true) do |view|
97
+ subviews = all_subviews_for(view)
98
+
99
+ if RMQ.is_blank?(working_selectors)
100
+ subviews
101
+ else
102
+ subviews.inject([]) do |out, subview|
103
+ out << subview if match(subview, working_selectors)
104
+ out
105
+ end
106
+ end
107
+ end
108
+ end
109
+
110
+ def children(*working_selectors)
111
+ normalize_selectors(working_selectors)
112
+
113
+ filter do |view|
114
+ subviews = view.subviews
115
+
116
+ if RMQ.is_blank?(working_selectors)
117
+ subviews
118
+ else
119
+ subviews.inject([]) do |out, subview|
120
+ out << subview if match(subview, working_selectors)
121
+ out
122
+ end
123
+ end
124
+ end
125
+ end
126
+ alias :subviews :children
127
+
128
+ def siblings(*working_selectors)
129
+ normalize_selectors(working_selectors)
130
+
131
+ self.parent.children.not(selected)
132
+ end
133
+
134
+ # TODO
135
+ #def next(*working_selectors)
136
+ #end
137
+ #def prev(*working_selectors)
138
+ #end
139
+ #
140
+
141
+ def closest(*working_selectors)
142
+ normalize_selectors(working_selectors)
143
+
144
+ filter do |view|
145
+ closest_view(view, working_selectors)
146
+ end
147
+ end
148
+
149
+ def view_controller
150
+ @_view_controller ||= begin
151
+ if @context.is_a?(UIViewController)
152
+ @context
153
+ else
154
+ RMQ.controller_for_view(@context)
155
+ end
156
+ end
157
+ end
158
+
159
+ def root_view
160
+ vc = self.view_controller
161
+ if RMQ.is_blank?(vc)
162
+ self.context_or_context_view
163
+ else
164
+ self.view_controller.view
165
+ end
166
+ end
167
+
168
+ protected
169
+
170
+ def closest_view(view, working_selectors)
171
+ if nr = view.nextResponder
172
+ if match(nr, working_selectors)
173
+ nr
174
+ else
175
+ closest_view(nr,working_selectors)
176
+ end
177
+ else
178
+ nil
179
+ end
180
+ end
181
+
182
+ end
183
+ end
@@ -0,0 +1,53 @@
1
+ module RubyMotionQuery
2
+ class RMQ
3
+
4
+ class << self
5
+ def is_class?(o)
6
+ # This line fails in spec, causes exit without message. It works fine in production
7
+ #(o.class == Class) && (defined?(o) == 'constant')
8
+
9
+ # So I'm doing this instead
10
+ !!(o.respond_to?(:name) && o.name.to_s[0] =~ /[A-Z]/)
11
+ end
12
+
13
+ # This is purposely not blank? as to not conflict with many libraries that
14
+ # add .blank? to Object
15
+ def is_blank?(o)
16
+ if o.is_a?(RubyMotionQuery::RMQ)
17
+ RubyMotionQuery::RMQ.is_blank?(o.to_a)
18
+ else
19
+ o.respond_to?(:empty?) ? o.empty? : !o
20
+ end
21
+ end
22
+
23
+
24
+ # Given a UIView, returns the UIViewController it is sitting in, or nil if it's not
25
+ # sitting anywhere in particular
26
+ def controller_for_view(view)
27
+ # Non-recursive for speed
28
+ while view
29
+ view = view.nextResponder
30
+ if view.is_a?(UIViewController)
31
+ break
32
+ elsif !view.is_a?(UIView)
33
+ view = nil
34
+ end
35
+ end
36
+
37
+ view
38
+ end
39
+
40
+ # Mainly used for console and logging
41
+ def view_to_s(view)
42
+ out = "\n"
43
+ out << " VIEW class:o #{view.class.name} object_id: #{view.object_id}\n"
44
+ out << " RECTANGLE left: #{view.origin.y}, top: #{view.origin.y}, width: #{view.size.width}, height: #{view.size.height}\n"
45
+ out << " SUPERVIEW class: #{view.superview.class.name} object_id: #{view.superview.object_id} \n" if view.superview
46
+ out << " SUBVIEWS count: #{view.subviews.length}\n"
47
+ out
48
+ end
49
+ end
50
+
51
+ end
52
+ end
53
+
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_motion_query
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Todd Werth
8
+ - InfiniteRed
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-30 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: RubyMotionQuery - RMQ - A light, nonpolluting, jQuery-like library for
15
+ RubyMotion
16
+ email: todd@infinitered.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - README.md
22
+ - LICENSE
23
+ - lib/ruby_motion_query.rb
24
+ - motion/ext.rb
25
+ - motion/ruby_motion_query/actions.rb
26
+ - motion/ruby_motion_query/animations.rb
27
+ - motion/ruby_motion_query/app.rb
28
+ - motion/ruby_motion_query/base.rb
29
+ - motion/ruby_motion_query/color.rb
30
+ - motion/ruby_motion_query/data.rb
31
+ - motion/ruby_motion_query/device.rb
32
+ - motion/ruby_motion_query/enumerablish.rb
33
+ - motion/ruby_motion_query/event.rb
34
+ - motion/ruby_motion_query/events.rb
35
+ - motion/ruby_motion_query/factory.rb
36
+ - motion/ruby_motion_query/font.rb
37
+ - motion/ruby_motion_query/format.rb
38
+ - motion/ruby_motion_query/image.rb
39
+ - motion/ruby_motion_query/position.rb
40
+ - motion/ruby_motion_query/selectors.rb
41
+ - motion/ruby_motion_query/stylers/ui_button_styler.rb
42
+ - motion/ruby_motion_query/stylers/ui_control_styler.rb
43
+ - motion/ruby_motion_query/stylers/ui_date_picker_styler.rb
44
+ - motion/ruby_motion_query/stylers/ui_image_view_styler.rb
45
+ - motion/ruby_motion_query/stylers/ui_label_styler.rb
46
+ - motion/ruby_motion_query/stylers/ui_navigation_bar_styler.rb
47
+ - motion/ruby_motion_query/stylers/ui_page_control_styler.rb
48
+ - motion/ruby_motion_query/stylers/ui_refresh_control_styler.rb
49
+ - motion/ruby_motion_query/stylers/ui_scroll_view_styler.rb
50
+ - motion/ruby_motion_query/stylers/ui_segmented_control_styler.rb
51
+ - motion/ruby_motion_query/stylers/ui_slider_styler.rb
52
+ - motion/ruby_motion_query/stylers/ui_stepper_styler.rb
53
+ - motion/ruby_motion_query/stylers/ui_switch_styler.rb
54
+ - motion/ruby_motion_query/stylers/ui_tab_bar_styler.rb
55
+ - motion/ruby_motion_query/stylers/ui_table_view_cell_styler.rb
56
+ - motion/ruby_motion_query/stylers/ui_table_view_styler.rb
57
+ - motion/ruby_motion_query/stylers/ui_text_field_styler.rb
58
+ - motion/ruby_motion_query/stylers/ui_text_view_styler.rb
59
+ - motion/ruby_motion_query/stylers/ui_view_styler.rb
60
+ - motion/ruby_motion_query/stylesheet.rb
61
+ - motion/ruby_motion_query/subviews.rb
62
+ - motion/ruby_motion_query/tags.rb
63
+ - motion/ruby_motion_query/traverse.rb
64
+ - motion/ruby_motion_query/utils.rb
65
+ homepage: http://infinitered.com/rmq
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.0.6
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: RubyMotionQuery - RMQ
89
+ test_files: []