ruby_motion_query 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/README.md +28 -23
- data/motion/ruby_motion_query/actions.rb +21 -0
- data/motion/ruby_motion_query/animations.rb +11 -0
- data/motion/ruby_motion_query/app.rb +13 -10
- data/motion/ruby_motion_query/base.rb +118 -34
- data/motion/ruby_motion_query/color.rb +54 -0
- data/motion/ruby_motion_query/data.rb +9 -0
- data/motion/ruby_motion_query/device.rb +7 -0
- data/motion/ruby_motion_query/enumerablish.rb +15 -0
- data/motion/ruby_motion_query/events.rb +2 -0
- data/motion/ruby_motion_query/factory.rb +4 -0
- data/motion/ruby_motion_query/font.rb +33 -14
- data/motion/ruby_motion_query/format.rb +3 -0
- data/motion/ruby_motion_query/image.rb +9 -1
- data/motion/ruby_motion_query/position.rb +2 -6
- data/motion/ruby_motion_query/selectors.rb +9 -0
- data/motion/ruby_motion_query/stylesheet.rb +8 -1
- data/motion/ruby_motion_query/subviews.rb +20 -5
- data/motion/ruby_motion_query/tags.rb +1 -0
- data/motion/ruby_motion_query/traverse.rb +118 -10
- data/motion/ruby_motion_query/utils.rb +7 -3
- metadata +32 -3
@@ -1,15 +1,24 @@
|
|
1
1
|
module RubyMotionQuery
|
2
2
|
class RMQ
|
3
3
|
|
4
|
+
# Do not use
|
4
5
|
def selectors=(value)
|
5
6
|
@selected_dirty = true
|
6
7
|
normalize_selectors(value)
|
7
8
|
@_selectors = value
|
8
9
|
end
|
10
|
+
|
11
|
+
# @return [Array] The selectors, which is what you used for the query
|
12
|
+
# @example
|
13
|
+
# (main)> rmq(UILabel, UIImageView).selectors
|
14
|
+
# => [UILabel, UIImageView]
|
9
15
|
def selectors
|
10
16
|
@_selectors
|
11
17
|
end
|
12
18
|
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
13
22
|
def match_context(new_selectors)
|
14
23
|
match(context_or_context_view, new_selectors)
|
15
24
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module RubyMotionQuery
|
2
2
|
class RMQ
|
3
|
+
|
4
|
+
# @return [RMQ]
|
3
5
|
def stylesheet=(value)
|
4
6
|
controller = view_controller
|
5
7
|
unless value.is_a?(RubyMotionQuery::Stylesheet)
|
@@ -8,12 +10,15 @@ module RubyMotionQuery
|
|
8
10
|
controller.rmq_data.stylesheet = value
|
9
11
|
self
|
10
12
|
end
|
13
|
+
|
14
|
+
# @return [String]
|
11
15
|
def stylesheet
|
12
16
|
@_stylesheet ||= begin
|
13
17
|
self.view_controller.rmq_data.stylesheet if self.view_controller
|
14
18
|
end
|
15
19
|
end
|
16
20
|
|
21
|
+
# @return [RMQ]
|
17
22
|
def apply_style(style_name)
|
18
23
|
selected.each do |selected_view|
|
19
24
|
apply_style_to_view selected_view, style_name
|
@@ -21,6 +26,7 @@ module RubyMotionQuery
|
|
21
26
|
self
|
22
27
|
end
|
23
28
|
|
29
|
+
# @return [RMQ]
|
24
30
|
def style()
|
25
31
|
selected.each do |view|
|
26
32
|
yield(styler_for(view))
|
@@ -28,12 +34,14 @@ module RubyMotionQuery
|
|
28
34
|
self
|
29
35
|
end
|
30
36
|
|
37
|
+
# @return [RMQ]
|
31
38
|
def reapply_styles
|
32
39
|
selected.each do |selected_view|
|
33
40
|
if style_name = selected_view.rmq_data.style_name
|
34
41
|
apply_style_to_view selected_view, style_name
|
35
42
|
end
|
36
43
|
end
|
44
|
+
self
|
37
45
|
end
|
38
46
|
|
39
47
|
def styler_for(view)
|
@@ -41,7 +49,6 @@ module RubyMotionQuery
|
|
41
49
|
# memoize this, however if you do that, make sure the dev doesn't retain them in a var
|
42
50
|
custom_stylers(view) || begin
|
43
51
|
case view
|
44
|
-
# TODO, rename all the stylers to Styler::UILabel, etc
|
45
52
|
when UILabel then Stylers::UILabelStyler.new(view)
|
46
53
|
when UIButton then Stylers::UIButtonStyler.new(view)
|
47
54
|
when UIImageView then Stylers::UIImageViewStyler.new(view)
|
@@ -2,13 +2,16 @@
|
|
2
2
|
module RubyMotionQuery
|
3
3
|
class RMQ
|
4
4
|
|
5
|
+
# @return [RMQ]
|
5
6
|
def remove
|
6
7
|
selected.each { |view| view.removeFromSuperview }
|
7
8
|
self
|
8
9
|
end
|
9
10
|
|
10
|
-
|
11
|
+
# @return [RMQ]
|
12
|
+
def add_subview(view_or_constant, opts={})
|
11
13
|
subviews_added = []
|
14
|
+
style = opts[:style]
|
12
15
|
selected.each do |selected_view|
|
13
16
|
if view_or_constant.is_a?(UIView)
|
14
17
|
new_view = view_or_constant
|
@@ -17,7 +20,13 @@ module RubyMotionQuery
|
|
17
20
|
end
|
18
21
|
|
19
22
|
subviews_added << new_view
|
20
|
-
|
23
|
+
if at_index = opts[:at_index]
|
24
|
+
selected_view.insertSubview(new_view, atIndex: at_index)
|
25
|
+
elsif below_view = opts[:below_view]
|
26
|
+
selected_view.insertSubview(new_view, belowSubview: below_view)
|
27
|
+
else
|
28
|
+
selected_view.addSubview(new_view)
|
29
|
+
end
|
21
30
|
|
22
31
|
if self.stylesheet
|
23
32
|
apply_style_to_view(new_view, style) if style
|
@@ -26,10 +35,16 @@ module RubyMotionQuery
|
|
26
35
|
|
27
36
|
RMQ.create_with_array_and_selectors(subviews_added, selectors, @context)
|
28
37
|
end
|
29
|
-
alias :
|
38
|
+
alias :insert :add_subview
|
39
|
+
|
40
|
+
# @return [RMQ]
|
41
|
+
def append(view_or_constant, style=nil)
|
42
|
+
add_subview(view_or_constant, style: style)
|
43
|
+
end
|
30
44
|
|
31
|
-
|
32
|
-
|
45
|
+
# @return [RMQ]
|
46
|
+
def unshift(view_or_constant, style = nil)
|
47
|
+
add_subview view_or_constant, style: style, at_index: 0
|
33
48
|
end
|
34
49
|
|
35
50
|
protected
|
@@ -1,7 +1,15 @@
|
|
1
1
|
module RubyMotionQuery
|
2
2
|
class RMQ
|
3
3
|
|
4
|
-
# Most
|
4
|
+
# Most everything uses filter to do its work. This is mostly used internally
|
5
|
+
# but you can use it too. Just pass a block that returns views, it will be
|
6
|
+
# called for every view that is *selected*
|
7
|
+
#
|
8
|
+
# @param return_array returns array not rmq: return_array: true
|
9
|
+
# @param uniq removes duplicate views: uniq: true
|
10
|
+
# @param limit limits the number of views *per selected view*: limit: true
|
11
|
+
#
|
12
|
+
# @return [RMQ]
|
5
13
|
def filter(opts = {}, &block)
|
6
14
|
out = []
|
7
15
|
limit = opts[:limit]
|
@@ -25,10 +33,20 @@ module RubyMotionQuery
|
|
25
33
|
end
|
26
34
|
end
|
27
35
|
|
36
|
+
# @return [RMQ] All selected views
|
37
|
+
#
|
38
|
+
# @example
|
39
|
+
# rmq.all.log
|
28
40
|
def all
|
29
41
|
self.view_controller.rmq.find
|
30
42
|
end
|
31
43
|
|
44
|
+
# @return [RMQ] A new rmq instance reducing selected views to those that match selectors provided
|
45
|
+
#
|
46
|
+
# @param selectors your selector
|
47
|
+
#
|
48
|
+
# @example
|
49
|
+
# rmq(UIImage).and(:some_tag).attr(image: nil)
|
32
50
|
def and(*working_selectors)
|
33
51
|
return self unless working_selectors
|
34
52
|
normalize_selectors(working_selectors)
|
@@ -38,6 +56,13 @@ module RubyMotionQuery
|
|
38
56
|
end
|
39
57
|
end
|
40
58
|
|
59
|
+
# @return [RMQ] A new rmq instance removing selected views that match selectors provided
|
60
|
+
#
|
61
|
+
# @param selectors
|
62
|
+
#
|
63
|
+
# @example
|
64
|
+
# # Entire family of labels from siblings on down
|
65
|
+
# rmq(my_label).parent.find(UILabel).not(my_label).move(left: 10)
|
41
66
|
def not(*working_selectors)
|
42
67
|
return self unless working_selectors
|
43
68
|
normalize_selectors(working_selectors)
|
@@ -47,10 +72,10 @@ module RubyMotionQuery
|
|
47
72
|
end
|
48
73
|
end
|
49
74
|
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
|
75
|
+
# @return [RMQ] A new rmq instance adding the context to the selected views
|
76
|
+
#
|
77
|
+
# @example
|
78
|
+
# rmq(my_view).children.and_self
|
54
79
|
def and_self
|
55
80
|
if @parent_rmq
|
56
81
|
out = @parent_rmq.selected.dup
|
@@ -63,15 +88,30 @@ module RubyMotionQuery
|
|
63
88
|
end
|
64
89
|
alias :add_self :and_self
|
65
90
|
|
91
|
+
# @return [RMQ] The parent rmq instance
|
92
|
+
#
|
93
|
+
# @example
|
94
|
+
# rmq(test_view).find(UIImageView).tag(:foo).end.find(UILabel).tag(:bar)
|
66
95
|
def end
|
67
96
|
@parent_rmq || self
|
68
97
|
end
|
69
98
|
|
99
|
+
# @return [RMQ] rmq instance selecting the parent of the selected view(s)
|
100
|
+
#
|
101
|
+
# @example
|
102
|
+
# rmq(my_view).parent.find(:delete_button).toggle_enabled
|
70
103
|
def parent
|
71
104
|
closest(UIView)
|
72
105
|
end
|
73
106
|
alias :superview :parent
|
74
107
|
|
108
|
+
# @return [RMQ] Instance selecting the parents, grandparents, etc, all the way up the tree
|
109
|
+
# of the selected view(s)
|
110
|
+
#
|
111
|
+
# @param selectors
|
112
|
+
#
|
113
|
+
# @example
|
114
|
+
# rmq(my_view).parents.log
|
75
115
|
def parents(*working_selectors)
|
76
116
|
normalize_selectors(working_selectors)
|
77
117
|
|
@@ -90,6 +130,14 @@ module RubyMotionQuery
|
|
90
130
|
end
|
91
131
|
alias :superviews :parents
|
92
132
|
|
133
|
+
# Get the descendants of each view in the current set of selected views, filtered by a selector(s)
|
134
|
+
#
|
135
|
+
# @return [RMQ] Instance selecting the children, grandchildren, etc of the selected view(s)
|
136
|
+
#
|
137
|
+
# @param selectors
|
138
|
+
#
|
139
|
+
# @example
|
140
|
+
# rmq(my_view).find(UIButton).show
|
93
141
|
def find(*working_selectors)
|
94
142
|
normalize_selectors(working_selectors)
|
95
143
|
|
@@ -107,6 +155,12 @@ module RubyMotionQuery
|
|
107
155
|
end
|
108
156
|
end
|
109
157
|
|
158
|
+
# @return [RMQ] Instance selecting the children of the selected view(s)
|
159
|
+
#
|
160
|
+
# @param selectors
|
161
|
+
#
|
162
|
+
# @example
|
163
|
+
# rmq(my_view).children.show
|
110
164
|
def children(*working_selectors)
|
111
165
|
normalize_selectors(working_selectors)
|
112
166
|
|
@@ -125,19 +179,65 @@ module RubyMotionQuery
|
|
125
179
|
end
|
126
180
|
alias :subviews :children
|
127
181
|
|
182
|
+
|
183
|
+
# @return [RMQ] Siblings of the selected view(s)
|
184
|
+
#
|
185
|
+
# @param selectors
|
186
|
+
#
|
187
|
+
# @example
|
188
|
+
# rmq(my_view).siblings.send(:poke)
|
128
189
|
def siblings(*working_selectors)
|
129
190
|
normalize_selectors(working_selectors)
|
130
191
|
|
131
192
|
self.parent.children.not(selected)
|
132
193
|
end
|
133
194
|
|
134
|
-
|
135
|
-
#
|
136
|
-
#end
|
137
|
-
#def prev(*working_selectors)
|
138
|
-
#end
|
195
|
+
|
196
|
+
# @return [RMQ] Sibling above to the selected view(s)
|
139
197
|
#
|
198
|
+
# @param selectors
|
199
|
+
#
|
200
|
+
# @example
|
201
|
+
# rmq(my_view).next(UITextField).focus
|
202
|
+
def next(*working_selectors)
|
203
|
+
normalize_selectors(working_selectors)
|
204
|
+
|
205
|
+
filter do |view|
|
206
|
+
subs = view.superview.subviews
|
207
|
+
location = subs.index(view)
|
208
|
+
if location < subs.length - 1
|
209
|
+
subs[location + 1]
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
# @return [RMQ] Sibling below to the selected view(s)
|
215
|
+
#
|
216
|
+
# @param selectors
|
217
|
+
#
|
218
|
+
# @example
|
219
|
+
# rmq(my_view).prev(UITextField).focus
|
220
|
+
def prev(*working_selectors)
|
221
|
+
normalize_selectors(working_selectors)
|
140
222
|
|
223
|
+
filter do |view|
|
224
|
+
subs = view.superview.subviews
|
225
|
+
location = subs.index(view)
|
226
|
+
if location > 0
|
227
|
+
subs[location - 1]
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
# For each selected view, get the first view that matches the selector(s) by testing the view's parent and
|
233
|
+
# traversing up through its ancestors in the tree
|
234
|
+
#
|
235
|
+
# @return [RMQ] Instance selecting the first parent or grandparent or ancestor up the tree of the selected view(s)
|
236
|
+
#
|
237
|
+
# @param selectors
|
238
|
+
#
|
239
|
+
# @example
|
240
|
+
# rmq.closest(UIScrollView).get.setContentOffset([0,0])
|
141
241
|
def closest(*working_selectors)
|
142
242
|
normalize_selectors(working_selectors)
|
143
243
|
|
@@ -146,6 +246,10 @@ module RubyMotionQuery
|
|
146
246
|
end
|
147
247
|
end
|
148
248
|
|
249
|
+
# @return [UIViewController] Controller of this rmq instance
|
250
|
+
#
|
251
|
+
# @example
|
252
|
+
# rmq.view_controller
|
149
253
|
def view_controller
|
150
254
|
@_view_controller ||= begin
|
151
255
|
if @context.is_a?(UIViewController)
|
@@ -156,6 +260,10 @@ module RubyMotionQuery
|
|
156
260
|
end
|
157
261
|
end
|
158
262
|
|
263
|
+
# @return [UIView] Root view of this rmq instance's controller
|
264
|
+
#
|
265
|
+
# @example
|
266
|
+
# rmq.root_view
|
159
267
|
def root_view
|
160
268
|
vc = self.view_controller
|
161
269
|
if RMQ.is_blank?(vc)
|
@@ -2,6 +2,7 @@ module RubyMotionQuery
|
|
2
2
|
class RMQ
|
3
3
|
|
4
4
|
class << self
|
5
|
+
# @return [Boolean]
|
5
6
|
def is_class?(o)
|
6
7
|
# This line fails in spec, causes exit without message. It works fine in production
|
7
8
|
#(o.class == Class) && (defined?(o) == 'constant')
|
@@ -12,6 +13,8 @@ module RubyMotionQuery
|
|
12
13
|
|
13
14
|
# This is purposely not blank? as to not conflict with many libraries that
|
14
15
|
# add .blank? to Object
|
16
|
+
#
|
17
|
+
# @return [Boolean]
|
15
18
|
def is_blank?(o)
|
16
19
|
if o.is_a?(RubyMotionQuery::RMQ)
|
17
20
|
RubyMotionQuery::RMQ.is_blank?(o.to_a)
|
@@ -20,9 +23,8 @@ module RubyMotionQuery
|
|
20
23
|
end
|
21
24
|
end
|
22
25
|
|
23
|
-
|
24
|
-
#
|
25
|
-
# sitting anywhere in particular
|
26
|
+
# @param view
|
27
|
+
# @return [UIViewController] The controller the view it is sitting in, or nil if it's not sitting anywhere in particular
|
26
28
|
def controller_for_view(view)
|
27
29
|
# Non-recursive for speed
|
28
30
|
while view
|
@@ -38,6 +40,8 @@ module RubyMotionQuery
|
|
38
40
|
end
|
39
41
|
|
40
42
|
# Mainly used for console and logging
|
43
|
+
#
|
44
|
+
# @return [String]
|
41
45
|
def view_to_s(view)
|
42
46
|
out = "\n"
|
43
47
|
out << " VIEW class:o #{view.class.name} object_id: #{view.object_id}\n"
|
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
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Werth
|
@@ -9,8 +9,36 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
-
dependencies:
|
12
|
+
date: 2013-08-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bacon
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ! '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
14
42
|
description: RubyMotionQuery - RMQ - A light, nonpolluting, jQuery-like library for
|
15
43
|
RubyMotion
|
16
44
|
email: todd@infinitered.com
|
@@ -87,3 +115,4 @@ signing_key:
|
|
87
115
|
specification_version: 4
|
88
116
|
summary: RubyMotionQuery - RMQ
|
89
117
|
test_files: []
|
118
|
+
has_rdoc:
|