sugarcube 1.0.3 → 1.0.4
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.
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/sugarcube/version.rb +1 -1
- data/lib/sugarcube-classic.rb +1 -0
- data/lib/sugarcube-color/uicolor.rb +2 -1
- data/lib/sugarcube-common.rb +1 -0
- data/lib/sugarcube-factories/uiactionsheet.rb +4 -1
- data/lib/sugarcube-factories/uialertview.rb +19 -12
- data/lib/sugarcube-gestures/gestures.rb +3 -0
- data/lib/sugarcube-nsdate/nsdate.rb +2 -2
- data/lib/sugarcube-uikit/uiview.rb +30 -20
- data/spec/uiactionsheet_spec.rb +19 -9
- data/spec/uialertview_spec.rb +32 -0
- data/spec/uiview_spec.rb +24 -0
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -157,7 +157,7 @@ quick overview:
|
|
157
157
|
> w 15
|
158
158
|
```
|
159
159
|
|
160
|
-
Be sure to read more in the [REPL
|
160
|
+
Be sure to read more in the [REPL Additions][REPL Wiki] Wiki page.
|
161
161
|
|
162
162
|
[REPL Wiki]: https://github.com/rubymotion/sugarcube/wiki/REPL-Additions
|
163
163
|
|
data/lib/sugarcube/version.rb
CHANGED
data/lib/sugarcube-classic.rb
CHANGED
@@ -41,7 +41,8 @@ class UIColor
|
|
41
41
|
color = color.uicolor
|
42
42
|
|
43
43
|
# make amount between 0 and 1
|
44
|
-
amount =
|
44
|
+
amount = amount > 0 ? amount : 0
|
45
|
+
amount = amount < 1 ? amount : 1
|
45
46
|
# start with precise amounts: 0, 0.5, and 1.
|
46
47
|
if amount == 0 && self.alpha == color.alpha
|
47
48
|
self
|
data/lib/sugarcube-common.rb
CHANGED
@@ -144,9 +144,12 @@ module SugarCube
|
|
144
144
|
if handler
|
145
145
|
if handler.arity == 0
|
146
146
|
handler.call
|
147
|
-
|
147
|
+
elsif handler.arity == 1
|
148
148
|
button = buttons[index]
|
149
149
|
handler.call(button)
|
150
|
+
else
|
151
|
+
button = buttons[index]
|
152
|
+
handler.call(button, index)
|
150
153
|
end
|
151
154
|
end
|
152
155
|
|
@@ -96,19 +96,26 @@ module SugarCube
|
|
96
96
|
end
|
97
97
|
|
98
98
|
if handler
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
args
|
99
|
+
if handler.arity == 0
|
100
|
+
args = []
|
101
|
+
else
|
102
|
+
# construct all the possible arguments you could send
|
103
|
+
args = [buttons[index]]
|
104
|
+
# add the first input if this is not the default
|
105
|
+
if alert.alertViewStyle != UIAlertViewStyleDefault
|
106
|
+
args << alert.textFieldAtIndex(0).text
|
107
|
+
end
|
108
|
+
# add the second one if this is a login+password input
|
109
|
+
if alert.alertViewStyle == UIAlertViewStyleLoginAndPasswordInput
|
110
|
+
args << alert.textFieldAtIndex(1).text
|
111
|
+
end
|
112
|
+
|
113
|
+
# and maybe you want the index, too
|
114
|
+
args << index
|
115
|
+
|
116
|
+
# but only send the ones they asked for
|
117
|
+
args = args[0...handler.arity]
|
104
118
|
end
|
105
|
-
# add the second one if this is a login+password input
|
106
|
-
if alert.alertViewStyle == UIAlertViewStyleLoginAndPasswordInput
|
107
|
-
args << alert.textFieldAtIndex(1).text
|
108
|
-
end
|
109
|
-
|
110
|
-
# but only send the ones they asked for
|
111
|
-
args = args[0...handler.arity]
|
112
119
|
handler.call(*args)
|
113
120
|
end
|
114
121
|
|
@@ -187,6 +187,9 @@ private
|
|
187
187
|
|
188
188
|
# Adds the recognizer and keeps a strong reference to the Proc object.
|
189
189
|
def sugarcube_add_gesture(proc, recognizer)
|
190
|
+
unless self.userInteractionEnabled?
|
191
|
+
puts("SugarCube: userInteractionEnabled is false on #{self.inspect}. Adding a gesture will have no effect.")
|
192
|
+
end
|
190
193
|
self.addGestureRecognizer(recognizer)
|
191
194
|
|
192
195
|
@sugarcube_recognizers = {} unless @sugarcube_recognizers
|
@@ -150,7 +150,7 @@ class NSDate
|
|
150
150
|
# (main)> t.time_array
|
151
151
|
# => [11, 29, 12]
|
152
152
|
def time_array
|
153
|
-
return [self.hour, self.min, self.sec]
|
153
|
+
return [self.hour, self.send(:min), self.sec]
|
154
154
|
end
|
155
155
|
|
156
156
|
# (main)> t = Time.new
|
@@ -158,7 +158,7 @@ class NSDate
|
|
158
158
|
# (main)> t.time_array
|
159
159
|
# => [2012, 9, 12, 11, 29, 12]
|
160
160
|
def datetime_array
|
161
|
-
return [self.year, self.month, self.day, self.hour, self.min, self.sec]
|
161
|
+
return [self.year, self.month, self.day, self.hour, self.send(:min), self.sec]
|
162
162
|
end
|
163
163
|
|
164
164
|
# (main)> t = Time.new
|
@@ -76,25 +76,35 @@ class UIView
|
|
76
76
|
# the future, if this argument becomes something that accepts multiple values,
|
77
77
|
# those two are sacred.
|
78
78
|
def uiimage(use_content_size=false)
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
79
|
+
scale = UIScreen.mainScreen.scale
|
80
|
+
if use_content_size
|
81
|
+
UIGraphicsBeginImageContextWithOptions(contentSize, false, scale)
|
82
|
+
context = UIGraphicsGetCurrentContext()
|
83
|
+
subviews.each do |subview|
|
84
|
+
CGContextSaveGState(context)
|
85
|
+
CGContextTranslateCTM(context, subview.frame.origin.x, subview.frame.origin.y)
|
86
|
+
subview.layer.renderInContext(context)
|
87
|
+
CGContextRestoreGState(context)
|
88
|
+
end
|
89
|
+
image = UIGraphicsGetImageFromCurrentImageContext()
|
90
|
+
UIGraphicsEndImageContext()
|
91
|
+
else
|
92
|
+
UIGraphicsBeginImageContextWithOptions(bounds.size, false, scale)
|
93
|
+
layer.renderInContext(UIGraphicsGetCurrentContext())
|
94
|
+
image = UIGraphicsGetImageFromCurrentImageContext()
|
95
|
+
UIGraphicsEndImageContext()
|
96
|
+
end
|
97
|
+
return image
|
98
|
+
end
|
99
|
+
|
100
|
+
# Returns the receiver's bounds in the coordinate system of `destination`
|
101
|
+
def convert_bounds(destination)
|
102
|
+
self.convertRect(self.bounds, toView:destination)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Returns the receiver's bounds in the coordinate system of `destination`
|
106
|
+
def convert_origin(destination)
|
107
|
+
self.convertPoint([0, 0], toView:destination)
|
108
|
+
end
|
99
109
|
|
100
110
|
end
|
data/spec/uiactionsheet_spec.rb
CHANGED
@@ -71,7 +71,7 @@ describe 'UIActionSheet' do
|
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'should call block with "OK" pressed' do
|
74
|
-
alert = UIActionSheet.alert('test') { |button| @touched = button }
|
74
|
+
alert = UIActionSheet.alert('test') { |button, index| @touched, @touched_index = button, index }
|
75
75
|
proper_wait 0.6
|
76
76
|
alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)
|
77
77
|
@touched.should == 'OK'
|
@@ -81,7 +81,7 @@ describe 'UIActionSheet' do
|
|
81
81
|
|
82
82
|
before do
|
83
83
|
@touched = nil
|
84
|
-
@alert = UIActionSheet.alert('test', buttons: ['cancel', 'destructive', 'ok']) { |button| @touched = button }
|
84
|
+
@alert = UIActionSheet.alert('test', buttons: ['cancel', 'destructive', 'ok']) { |button, index| @touched, @touched_index = button, index }
|
85
85
|
proper_wait 0.6
|
86
86
|
end
|
87
87
|
|
@@ -109,7 +109,7 @@ describe 'UIActionSheet' do
|
|
109
109
|
|
110
110
|
before do
|
111
111
|
@touched = nil
|
112
|
-
@alert = UIActionSheet.alert('test', buttons: ['cancel', 'destructive']) { |button| @touched = button }
|
112
|
+
@alert = UIActionSheet.alert('test', buttons: ['cancel', 'destructive']) { |button, index| @touched, @touched_index = button, index }
|
113
113
|
proper_wait 0.6
|
114
114
|
end
|
115
115
|
|
@@ -121,12 +121,14 @@ describe 'UIActionSheet' do
|
|
121
121
|
@alert.cancelButtonIndex.should == 1
|
122
122
|
@alert.dismissWithClickedButtonIndex(@alert.cancelButtonIndex, animated: false)
|
123
123
|
@touched.should == 'cancel'
|
124
|
+
@touched_index.should == @alert.cancelButtonIndex
|
124
125
|
end
|
125
126
|
|
126
127
|
it 'should call block with "destructive" when destructive button is pressed' do
|
127
128
|
@alert.destructiveButtonIndex.should == 0
|
128
129
|
@alert.dismissWithClickedButtonIndex(@alert.destructiveButtonIndex, animated: false)
|
129
130
|
@touched.should == 'destructive'
|
131
|
+
@touched_index.should == @alert.destructiveButtonIndex
|
130
132
|
end
|
131
133
|
|
132
134
|
it 'should not have other buttons' do
|
@@ -139,7 +141,7 @@ describe 'UIActionSheet' do
|
|
139
141
|
|
140
142
|
before do
|
141
143
|
@touched = nil
|
142
|
-
@alert = UIActionSheet.alert('test', buttons: ['cancel', nil, 'ok']) { |button| @touched = button }
|
144
|
+
@alert = UIActionSheet.alert('test', buttons: ['cancel', nil, 'ok']) { |button, index| @touched, @touched_index = button, index }
|
143
145
|
proper_wait 0.6
|
144
146
|
end
|
145
147
|
|
@@ -151,6 +153,7 @@ describe 'UIActionSheet' do
|
|
151
153
|
@alert.cancelButtonIndex.should == 1
|
152
154
|
@alert.dismissWithClickedButtonIndex(@alert.cancelButtonIndex, animated: false)
|
153
155
|
@touched.should == 'cancel'
|
156
|
+
@touched_index.should == @alert.cancelButtonIndex
|
154
157
|
end
|
155
158
|
|
156
159
|
it 'should not have destructive button' do
|
@@ -161,6 +164,7 @@ describe 'UIActionSheet' do
|
|
161
164
|
@alert.firstOtherButtonIndex.should == 0
|
162
165
|
@alert.dismissWithClickedButtonIndex(@alert.firstOtherButtonIndex, animated: false)
|
163
166
|
@touched.should == 'ok'
|
167
|
+
@touched_index.should == @alert.firstOtherButtonIndex
|
164
168
|
end
|
165
169
|
|
166
170
|
end
|
@@ -169,7 +173,7 @@ describe 'UIActionSheet' do
|
|
169
173
|
|
170
174
|
before do
|
171
175
|
@touched = nil
|
172
|
-
@alert = UIActionSheet.alert('test', buttons: [nil, 'destructive', 'ok']) { |button| @touched = button }
|
176
|
+
@alert = UIActionSheet.alert('test', buttons: [nil, 'destructive', 'ok']) { |button, index| @touched, @touched_index = button, index }
|
173
177
|
proper_wait 0.6
|
174
178
|
end
|
175
179
|
|
@@ -177,20 +181,22 @@ describe 'UIActionSheet' do
|
|
177
181
|
@alert.dismissWithClickedButtonIndex(-1, animated: false) if @alert.visible?
|
178
182
|
end
|
179
183
|
|
180
|
-
it 'should
|
184
|
+
it 'should not have cancel button' do
|
181
185
|
@alert.cancelButtonIndex.should == -1
|
182
186
|
end
|
183
187
|
|
184
|
-
it 'should
|
188
|
+
it 'should call block with "destructive" when destructive button is pressed' do
|
185
189
|
@alert.destructiveButtonIndex.should == 0
|
186
190
|
@alert.dismissWithClickedButtonIndex(@alert.destructiveButtonIndex, animated: false)
|
187
191
|
@touched.should == 'destructive'
|
192
|
+
@touched_index.should == @alert.destructiveButtonIndex
|
188
193
|
end
|
189
194
|
|
190
195
|
it 'should call block with "ok" when other button is pressed' do
|
191
196
|
@alert.firstOtherButtonIndex.should == 1
|
192
197
|
@alert.dismissWithClickedButtonIndex(@alert.firstOtherButtonIndex, animated: false)
|
193
198
|
@touched.should == 'ok'
|
199
|
+
@touched_index.should == @alert.firstOtherButtonIndex
|
194
200
|
end
|
195
201
|
|
196
202
|
end
|
@@ -199,7 +205,7 @@ describe 'UIActionSheet' do
|
|
199
205
|
|
200
206
|
before do
|
201
207
|
@touched = nil
|
202
|
-
@alert = UIActionSheet.alert('test', buttons: [nil, nil, 'test1', 'test2']) { |button| @touched = button }
|
208
|
+
@alert = UIActionSheet.alert('test', buttons: [nil, nil, 'test1', 'test2']) { |button, index| @touched, @touched_index = button, index }
|
203
209
|
proper_wait 0.6
|
204
210
|
end
|
205
211
|
|
@@ -219,11 +225,13 @@ describe 'UIActionSheet' do
|
|
219
225
|
@alert.firstOtherButtonIndex.should == 0
|
220
226
|
@alert.dismissWithClickedButtonIndex(@alert.firstOtherButtonIndex, animated: false)
|
221
227
|
@touched.should == 'test1'
|
228
|
+
@touched_index.should == @alert.firstOtherButtonIndex
|
222
229
|
end
|
223
230
|
|
224
231
|
it 'should call block with "test2" when second button is pressed' do
|
225
232
|
@alert.dismissWithClickedButtonIndex(@alert.firstOtherButtonIndex + 1, animated: false)
|
226
233
|
@touched.should == 'test2'
|
234
|
+
@touched_index.should == @alert.firstOtherButtonIndex + 1
|
227
235
|
end
|
228
236
|
|
229
237
|
end
|
@@ -236,7 +244,7 @@ describe 'UIActionSheet' do
|
|
236
244
|
buttons: ['cancel', 'destructive', 'test1', 'test2'],
|
237
245
|
cancel: ->{ @touched = :cancel },
|
238
246
|
destructive: ->{ @touched = :destructive },
|
239
|
-
success: ->(button){ @touched = button },
|
247
|
+
success: ->(button, index){ @touched, @touched_index = button, index },
|
240
248
|
)
|
241
249
|
proper_wait 0.6
|
242
250
|
end
|
@@ -257,11 +265,13 @@ describe 'UIActionSheet' do
|
|
257
265
|
@alert.firstOtherButtonIndex.should == 1
|
258
266
|
@alert.dismissWithClickedButtonIndex(@alert.firstOtherButtonIndex, animated: false)
|
259
267
|
@touched.should == 'test1'
|
268
|
+
@touched_index.should == @alert.firstOtherButtonIndex
|
260
269
|
end
|
261
270
|
|
262
271
|
it 'should call block with "test2" when second button is pressed' do
|
263
272
|
@alert.dismissWithClickedButtonIndex(@alert.firstOtherButtonIndex + 1, animated: false)
|
264
273
|
@touched.should == 'test2'
|
274
|
+
@touched_index.should == @alert.firstOtherButtonIndex + 1
|
265
275
|
end
|
266
276
|
|
267
277
|
end
|
data/spec/uialertview_spec.rb
CHANGED
@@ -99,6 +99,15 @@ describe 'UIAlertView' do
|
|
99
99
|
@touched.should == 'OK'
|
100
100
|
end
|
101
101
|
|
102
|
+
it 'should call the block and pass the button and index when dismissed' do
|
103
|
+
alert = UIAlertView.alert('test') { |button, index| @touched, @touched_index = button, index }
|
104
|
+
proper_wait 0.6
|
105
|
+
alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)
|
106
|
+
|
107
|
+
@touched.should == 'OK'
|
108
|
+
@touched_index.should == 0
|
109
|
+
end
|
110
|
+
|
102
111
|
it 'should call the block when dismissed no matter when cancel button pressed' do
|
103
112
|
alert = UIAlertView.alert('test', buttons:['cancel','ok']) { @touched = true }
|
104
113
|
alert.numberOfButtons.should == 2
|
@@ -116,6 +125,15 @@ describe 'UIAlertView' do
|
|
116
125
|
@touched.should == 'cancel'
|
117
126
|
end
|
118
127
|
|
128
|
+
it 'should call the block and pass the button and index when dismissed with multiple buttons' do
|
129
|
+
alert = UIAlertView.alert('test', buttons: ['cancel', 'ok']) { |button, index| @touched, @touched_index = button, index }
|
130
|
+
proper_wait 0.6
|
131
|
+
alert.dismissWithClickedButtonIndex(alert.cancelButtonIndex, animated: false)
|
132
|
+
|
133
|
+
@touched.should == 'cancel'
|
134
|
+
@touched_index.should == 0
|
135
|
+
end
|
136
|
+
|
119
137
|
describe 'Should call the appropriate block when :cancel and :success handlers are used' do
|
120
138
|
|
121
139
|
before do
|
@@ -182,6 +200,20 @@ describe 'UIAlertView' do
|
|
182
200
|
@text.should == 'test text 1 + test text 2'
|
183
201
|
end
|
184
202
|
|
203
|
+
it 'should work with :login_and_password_input and pass the index' do
|
204
|
+
alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'], style: :login_and_password_input) { |button, text1, text2, index|
|
205
|
+
@text = "#{text1} + #{text2}"
|
206
|
+
@touched_index = index
|
207
|
+
}
|
208
|
+
proper_wait 0.6
|
209
|
+
alert.textFieldAtIndex(0).text = 'test text 1'
|
210
|
+
alert.textFieldAtIndex(1).text = 'test text 2'
|
211
|
+
alert.dismissWithClickedButtonIndex(alert.cancelButtonIndex, animated: false)
|
212
|
+
|
213
|
+
@text.should == 'test text 1 + test text 2'
|
214
|
+
@touched_index.should == alert.cancelButtonIndex
|
215
|
+
end
|
216
|
+
|
185
217
|
end
|
186
218
|
|
187
219
|
end
|
data/spec/uiview_spec.rb
CHANGED
@@ -28,4 +28,28 @@ describe "UIView" do
|
|
28
28
|
image.scale.should == UIScreen.mainScreen.scale
|
29
29
|
end
|
30
30
|
|
31
|
+
it "should convert bounds" do
|
32
|
+
view1 = UIView.alloc.initWithFrame([[0, 0], [100, 100]])
|
33
|
+
view2 = UIView.alloc.initWithFrame([[10, 5], [80, 90]])
|
34
|
+
view1 << view2
|
35
|
+
view3 = UIView.alloc.initWithFrame([[10, 5], [60, 80]])
|
36
|
+
view2 << view3
|
37
|
+
frame = view3.convert_bounds(view1)
|
38
|
+
frame.origin.x.should == 20
|
39
|
+
frame.origin.y.should == 10
|
40
|
+
frame.size.width.should == 60
|
41
|
+
frame.size.height.should == 80
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should convert point" do
|
45
|
+
view1 = UIView.alloc.initWithFrame([[0, 0], [100, 100]])
|
46
|
+
view2 = UIView.alloc.initWithFrame([[10, 5], [80, 90]])
|
47
|
+
view1 << view2
|
48
|
+
view3 = UIView.alloc.initWithFrame([[10, 5], [60, 80]])
|
49
|
+
view2 << view3
|
50
|
+
point = view3.convert_origin(view1)
|
51
|
+
point.x.should == 20
|
52
|
+
point.y.should == 10
|
53
|
+
end
|
54
|
+
|
31
55
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sugarcube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2013-
|
15
|
+
date: 2013-08-02 00:00:00.000000000 Z
|
16
16
|
dependencies: []
|
17
17
|
description: ! '== Description
|
18
18
|
|