sugarcube 0.20.13 → 0.20.15
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/sugarcube/adjust.rb +1 -1
- data/lib/sugarcube/date_parser.rb +1 -1
- data/lib/sugarcube/nsstring.rb +16 -1
- data/lib/sugarcube/symbol.rb +27 -0
- data/lib/sugarcube/uiactionsheet.rb +100 -60
- data/lib/sugarcube/uialertview.rb +31 -9
- data/lib/sugarcube/uiview.rb +27 -1
- data/lib/sugarcube/version.rb +1 -1
- data/spec/nsstring_timezone_spec.rb +23 -0
- data/spec/uiactionsheet_spec.rb +253 -0
- data/spec/uialertview_spec.rb +187 -0
- data/spec/uiview_animation_spec.rb +9 -1
- metadata +8 -2
data/Gemfile.lock
CHANGED
data/lib/sugarcube/adjust.rb
CHANGED
data/lib/sugarcube/nsstring.rb
CHANGED
@@ -18,7 +18,9 @@ class NSString
|
|
18
18
|
|
19
19
|
# @return [UIImage]
|
20
20
|
def uiimage
|
21
|
-
UIImage.imageNamed(self)
|
21
|
+
UIImage.imageNamed(self).tap do |retval|
|
22
|
+
NSLog("No image named #{self}") unless retval
|
23
|
+
end
|
22
24
|
end
|
23
25
|
|
24
26
|
# @return [UIImageView]
|
@@ -89,4 +91,17 @@ class NSString
|
|
89
91
|
end
|
90
92
|
alias _ localized
|
91
93
|
|
94
|
+
def nstimezone
|
95
|
+
case self
|
96
|
+
when /([+-]?\d{4})/
|
97
|
+
sec = $1[-4,2].to_i * 3600
|
98
|
+
NSTimeZone.timeZoneForSecondsFromGMT(sec)
|
99
|
+
when /(GMT|UTC)([+-]\d{1,2})?/
|
100
|
+
sec = $2 ? $2.to_i * 3600 : 0
|
101
|
+
NSTimeZone.timeZoneForSecondsFromGMT(sec)
|
102
|
+
else
|
103
|
+
NSTimeZone.timeZoneWithName(self)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
92
107
|
end
|
data/lib/sugarcube/symbol.rb
CHANGED
@@ -62,6 +62,9 @@ class Symbol
|
|
62
62
|
attr :tableview_cellselectionstyle
|
63
63
|
attr :tableview_cellseparatorstyle
|
64
64
|
|
65
|
+
attr :alert_view_styles
|
66
|
+
attr :action_sheet_styles
|
67
|
+
|
65
68
|
attr :image_sourcetypes
|
66
69
|
attr :image_capturemode
|
67
70
|
attr :image_cameradevice
|
@@ -354,6 +357,20 @@ class Symbol
|
|
354
357
|
etched: UITableViewCellSeparatorStyleSingleLineEtched,
|
355
358
|
}
|
356
359
|
|
360
|
+
@alert_view_styles = {
|
361
|
+
default: UIAlertViewStyleDefault,
|
362
|
+
secure_text_input: UIAlertViewStyleSecureTextInput,
|
363
|
+
plain_text_input: UIAlertViewStylePlainTextInput,
|
364
|
+
login_and_password_input: UIAlertViewStyleLoginAndPasswordInput,
|
365
|
+
}
|
366
|
+
|
367
|
+
@action_sheet_styles = {
|
368
|
+
automatic: UIActionSheetStyleAutomatic,
|
369
|
+
default: UIActionSheetStyleDefault,
|
370
|
+
black_translucent: UIActionSheetStyleBlackTranslucent,
|
371
|
+
black_opaque: UIActionSheetStyleBlackOpaque,
|
372
|
+
}
|
373
|
+
|
357
374
|
@statusbar_styles = {
|
358
375
|
default: UIStatusBarStyleDefault,
|
359
376
|
black: UIStatusBarStyleBlackOpaque,
|
@@ -628,6 +645,16 @@ class Symbol
|
|
628
645
|
sugarcube_look_in(Symbol.tableview_cellseparatorstyle)
|
629
646
|
end
|
630
647
|
|
648
|
+
def uialertstyle
|
649
|
+
sugarcube_look_in(Symbol.alert_view_styles)
|
650
|
+
end
|
651
|
+
alias uialertviewstyle uialertstyle
|
652
|
+
|
653
|
+
def uiactionstyle
|
654
|
+
sugarcube_look_in(Symbol.action_sheet_styles)
|
655
|
+
end
|
656
|
+
alias uiactionsheetstyle uiactionstyle
|
657
|
+
|
631
658
|
def uistatusbarstyle
|
632
659
|
sugarcube_look_in(Symbol.statusbar_styles)
|
633
660
|
end
|
@@ -1,18 +1,26 @@
|
|
1
1
|
class UIActionSheet
|
2
2
|
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
3
|
+
# For the purposes of whether the cancel or success handler gets called, the
|
4
|
+
# first button is considered the 'cancel' button, the second button is the
|
5
|
+
# 'destructive' button, and the rest are plain old buttons.
|
6
|
+
#
|
7
|
+
# If you use just one block, it will be used for *all* of the buttons.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# # use a different handler for each button type
|
11
|
+
# UIActionSheet.alert("title",
|
12
|
+
# buttons: %w"Cancel Delete No-way",
|
13
|
+
# cancel: proc{ puts "nevermind" },
|
14
|
+
# destructive: proc{ puts "OHHH YEAAH!" },
|
15
|
+
# success: proc{ |pressed| puts "pressed: #{pressed}" },
|
16
|
+
# )
|
17
|
+
# # use one handler for all buttons
|
18
|
+
# UIActionSheet.alert("title", buttons: [...]) { |button| }
|
12
19
|
def self.alert(title, options={}, &block)
|
13
20
|
# create the delegate
|
14
21
|
delegate = SugarCube::ActionSheetDelegate.new
|
15
|
-
delegate.
|
22
|
+
delegate.on_default = block
|
23
|
+
delegate.on_success = options[:success]
|
16
24
|
delegate.on_destructive = options[:destructive]
|
17
25
|
delegate.on_cancel = options[:cancel]
|
18
26
|
delegate.send(:retain)
|
@@ -24,61 +32,87 @@ class UIActionSheet
|
|
24
32
|
buttons.concat(options[:buttons]) if options[:buttons]
|
25
33
|
|
26
34
|
if buttons.empty?
|
27
|
-
# cancelButtonTitle:
|
28
|
-
if options[:cancel]
|
29
|
-
buttons << 'Cancel'
|
30
|
-
else
|
31
|
-
buttons << nil
|
32
|
-
end
|
33
|
-
|
34
|
-
# destructiveButtonTitle, check for destructive handler
|
35
|
-
if options[:destructive]
|
36
|
-
buttons << 'Delete'
|
37
|
-
else
|
38
|
-
buttons << nil
|
39
|
-
end
|
40
|
-
elsif buttons.length == 1 and (options[:cancel] or options[:destructive])
|
41
|
-
raise 'If you only have one button, use a :success handler, not :cancel or :destructive'
|
42
|
-
end
|
43
|
-
|
44
|
-
# uses localized buttons in the actual alert
|
45
|
-
if buttons.length == 0
|
46
|
-
buttons = [nil, nil]
|
47
|
-
elsif buttons.length == 1
|
35
|
+
# cancelButtonTitle:
|
48
36
|
buttons << nil
|
49
|
-
end
|
50
37
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
button_index_map = {}
|
55
|
-
if buttons[1] # destructive
|
56
|
-
button_index_map[0] = buttons[1]
|
57
|
-
offset += 1
|
58
|
-
else
|
59
|
-
last_index -= 1
|
60
|
-
end
|
38
|
+
# destructiveButtonTitle
|
39
|
+
buttons << nil
|
61
40
|
|
62
|
-
|
63
|
-
|
41
|
+
# otherButtonTitles:
|
42
|
+
buttons << 'OK'
|
43
|
+
elsif buttons.length == 1 && (options[:cancel] || options[:destructive])
|
44
|
+
raise 'If you only have one button, use a :success handler, not :cancel or :destructive'
|
64
45
|
end
|
65
46
|
|
66
|
-
|
67
|
-
button_index_map[index + offset] = button
|
68
|
-
}
|
69
|
-
# the button titles, mapped to how UIActionSheet orders them. These are passed to the success handler.
|
70
|
-
delegate.button_index_map = button_index_map
|
71
|
-
|
47
|
+
# cancelButtonTitle:destructiveButtonTitle:otherButtonTitles:
|
72
48
|
args.concat(buttons.map{ |s| s ? s.localized : nil })
|
73
49
|
args << nil # otherButtonTitles:..., nil
|
74
50
|
|
51
|
+
# the button titles, mapped to how UIActionSheet orders them. These are
|
52
|
+
# passed to the success handler.
|
53
|
+
buttons_mapped = {}
|
54
|
+
if args[2] && args[3] # cancel && destructive buttons
|
55
|
+
buttons_mapped[0] = buttons[1] # destructiveIndex == 0, button == 1
|
56
|
+
buttons_mapped[buttons.length - 1] = buttons[0] # cancelIndex == last, button == 0
|
57
|
+
# from first+1 to last-1
|
58
|
+
buttons[2..-1].each_with_index do |button,index|
|
59
|
+
buttons_mapped[index + 1] = button
|
60
|
+
end
|
61
|
+
elsif args[3] # destructive button
|
62
|
+
buttons_mapped[0] = buttons[1] # destructiveIndex == 0, button == 1
|
63
|
+
# from first+1 to last-1
|
64
|
+
buttons[2..-1].each_with_index do |button,index|
|
65
|
+
buttons_mapped[index + 1] = button
|
66
|
+
end
|
67
|
+
elsif args[2] # cancel button
|
68
|
+
buttons_mapped[buttons.length - 2] = buttons[0] # cancelIndex == last, button == 0
|
69
|
+
buttons[2..-1].each_with_index do |button,index|
|
70
|
+
buttons_mapped[index] = button
|
71
|
+
end
|
72
|
+
else
|
73
|
+
buttons[2..-1].each_with_index do |button,index|
|
74
|
+
buttons_mapped[index] = button
|
75
|
+
end
|
76
|
+
end
|
77
|
+
delegate.buttons = buttons_mapped
|
78
|
+
|
75
79
|
alert = self.alloc
|
76
80
|
alert.send('initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles:', *args)
|
77
|
-
|
78
|
-
|
81
|
+
if options.key?(:style)
|
82
|
+
style = options[:style]
|
83
|
+
style = style.uiactionstyle unless style.is_a?(Fixnum)
|
84
|
+
alert.actionSheetStyle = style
|
85
|
+
end
|
86
|
+
if options.fetch(:show, true)
|
87
|
+
if options.key?(:from)
|
88
|
+
from = options[:from]
|
89
|
+
else
|
90
|
+
from = UIApplication.sharedApplication.windows[0]
|
91
|
+
end
|
92
|
+
|
93
|
+
case from
|
94
|
+
when CGRect
|
95
|
+
view = UIApplication.sharedApplication.windows[0]
|
96
|
+
alert.showInRect(from, inView: view, animated: true)
|
97
|
+
when UIBarButtonItem
|
98
|
+
alert.showFromBarButtonItem(from)
|
99
|
+
when UIToolbar
|
100
|
+
alert.showFromToolbar(from)
|
101
|
+
when UITabBar
|
102
|
+
alert.showFromTabBar(from)
|
103
|
+
when UIView
|
104
|
+
alert.showInView(from)
|
105
|
+
else
|
106
|
+
raise "Unknown :from option #{from.inspect}"
|
107
|
+
end
|
108
|
+
end
|
79
109
|
alert
|
80
110
|
end
|
81
111
|
|
112
|
+
def <<(title)
|
113
|
+
addButtonWithTitle(title)
|
114
|
+
end
|
115
|
+
|
82
116
|
private
|
83
117
|
def dummy
|
84
118
|
self.initWithTitle(nil, delegate:nil, cancelButtonTitle:nil, destructiveButtonTitle:nil, otherButtonTitles:nil)
|
@@ -89,22 +123,28 @@ end
|
|
89
123
|
|
90
124
|
module SugarCube
|
91
125
|
class ActionSheetDelegate
|
92
|
-
attr_accessor :
|
126
|
+
attr_accessor :buttons
|
127
|
+
attr_accessor :on_default
|
93
128
|
attr_accessor :on_cancel
|
94
129
|
attr_accessor :on_destructive
|
95
130
|
attr_accessor :on_success
|
96
131
|
|
97
132
|
def actionSheet(alert, didDismissWithButtonIndex:index)
|
133
|
+
handler = nil
|
98
134
|
if index == alert.destructiveButtonIndex && on_destructive
|
99
|
-
on_destructive
|
135
|
+
handler = on_destructive || on_default
|
100
136
|
elsif index == alert.cancelButtonIndex && on_cancel
|
101
|
-
on_cancel
|
102
|
-
|
103
|
-
|
104
|
-
|
137
|
+
handler = on_cancel || on_default
|
138
|
+
else
|
139
|
+
handler = on_success || on_default
|
140
|
+
end
|
141
|
+
|
142
|
+
if handler
|
143
|
+
if handler.arity == 0
|
144
|
+
handler.call
|
105
145
|
else
|
106
|
-
button =
|
107
|
-
|
146
|
+
button = buttons[index]
|
147
|
+
handler.call(button)
|
108
148
|
end
|
109
149
|
end
|
110
150
|
|
@@ -8,9 +8,12 @@ class UIAlertView
|
|
8
8
|
# cancel: proc{ puts "nevermind" },
|
9
9
|
# success: proc{ |pressed| puts "pressed: #{pressed}" },
|
10
10
|
# )
|
11
|
-
|
11
|
+
#
|
12
|
+
# If you choose
|
13
|
+
def self.alert(title, options={}, more_options={}, &block)
|
12
14
|
if options.is_a? String
|
13
|
-
|
15
|
+
more_options[:message] = options
|
16
|
+
options = more_options
|
14
17
|
end
|
15
18
|
|
16
19
|
# create the delegate
|
@@ -33,7 +36,7 @@ class UIAlertView
|
|
33
36
|
|
34
37
|
# otherButtonTitles:
|
35
38
|
if buttons.empty?
|
36
|
-
|
39
|
+
args << nil # cancel button => nil
|
37
40
|
buttons << "OK" # other buttons => "OK"
|
38
41
|
elsif options[:success]
|
39
42
|
buttons << "OK"
|
@@ -51,10 +54,21 @@ class UIAlertView
|
|
51
54
|
|
52
55
|
alert = self.alloc
|
53
56
|
alert.send(:"initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:", *args)
|
54
|
-
|
57
|
+
if options.key?(:style)
|
58
|
+
style = options[:style]
|
59
|
+
style = style.uialertstyle unless style.is_a?(Fixnum)
|
60
|
+
alert.alertViewStyle = style
|
61
|
+
end
|
62
|
+
if options.fetch(:show, true)
|
63
|
+
alert.show
|
64
|
+
end
|
55
65
|
alert
|
56
66
|
end
|
57
67
|
|
68
|
+
def <<(title)
|
69
|
+
addButtonWithTitle(title)
|
70
|
+
end
|
71
|
+
|
58
72
|
private
|
59
73
|
def dummy
|
60
74
|
self.initWithTitle(nil, message:nil, delegate:nil, cancelButtonTitle:nil, otherButtonTitles:nil)
|
@@ -82,12 +96,20 @@ module SugarCube
|
|
82
96
|
end
|
83
97
|
|
84
98
|
if handler
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
99
|
+
# construct all the possible arguments you could send
|
100
|
+
args = [buttons[index]]
|
101
|
+
# add the first input if this is not the default
|
102
|
+
if alert.alertViewStyle != :default.uialertstyle
|
103
|
+
args << alert.textFieldAtIndex(0).text
|
104
|
+
end
|
105
|
+
# add the second one if this is a login+password input
|
106
|
+
if alert.alertViewStyle == :login_and_password_input.uialertstyle
|
107
|
+
args << alert.textFieldAtIndex(1).text
|
90
108
|
end
|
109
|
+
|
110
|
+
# but only send the ones they asked for
|
111
|
+
args = args[0...handler.arity]
|
112
|
+
handler.call(*args)
|
91
113
|
end
|
92
114
|
|
93
115
|
self.send(:autorelease)
|
data/lib/sugarcube/uiview.rb
CHANGED
@@ -240,6 +240,32 @@ class UIView
|
|
240
240
|
self
|
241
241
|
end
|
242
242
|
|
243
|
+
def resize_to(size, options={}, &after)
|
244
|
+
if options.is_a? Numeric
|
245
|
+
options = { duration: options }
|
246
|
+
end
|
247
|
+
|
248
|
+
options[:after] = after
|
249
|
+
|
250
|
+
animate(options) {
|
251
|
+
f = self.frame
|
252
|
+
f.size = SugarCube::CoreGraphics::Size(size)
|
253
|
+
self.frame = f
|
254
|
+
}
|
255
|
+
end
|
256
|
+
|
257
|
+
def reframe_to(frame, options={}, &after)
|
258
|
+
if options.is_a? Numeric
|
259
|
+
options = { duration: options }
|
260
|
+
end
|
261
|
+
|
262
|
+
options[:after] = after
|
263
|
+
|
264
|
+
animate(options) {
|
265
|
+
self.frame = frame
|
266
|
+
}
|
267
|
+
end
|
268
|
+
|
243
269
|
# Changes the current rotation to `new_angle`
|
244
270
|
# (`rotate` rotates relative to the current rotation)
|
245
271
|
def rotate_to(options={}, more_options={}, &after)
|
@@ -368,7 +394,7 @@ class UIView
|
|
368
394
|
end
|
369
395
|
|
370
396
|
self.animate(options) {
|
371
|
-
window = UIApplication.sharedApplication.
|
397
|
+
window = UIApplication.sharedApplication.windows[0]
|
372
398
|
top = self.convertPoint([0, 0], toView:nil).y
|
373
399
|
height = window.frame.size.height - top
|
374
400
|
offset = CGPoint.new(0, height * 1.5)
|
data/lib/sugarcube/version.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
describe "NSString to NSTimeZone" do
|
2
|
+
|
3
|
+
it "should parse timezone as UTC" do
|
4
|
+
"UTC".nstimezone.secondsFromGMT.should == 0
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should parse timezone as Asia/Tokyo" do
|
8
|
+
"Asia/Tokyo".nstimezone.secondsFromGMT.should == 9 * 60 * 60
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should parse timezone as Asia/Tokyo" do
|
12
|
+
"UTC+9".nstimezone.secondsFromGMT.should == 9 * 60 * 60
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should parse timezone as Asia/Tokyo" do
|
16
|
+
"GMT+9".nstimezone.secondsFromGMT.should == 9 * 60 * 60
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should parse timezone as Asia/Tokyo" do
|
20
|
+
"+0900".nstimezone.secondsFromGMT.should == 9 * 60 * 60
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,253 @@
|
|
1
|
+
describe 'UIActionSheet' do
|
2
|
+
tests UIViewController # this is just needed so that a window is available
|
3
|
+
|
4
|
+
before do
|
5
|
+
@touched = nil
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should have :show option (show: false)' do
|
9
|
+
alert = UIActionSheet.alert('test', show: false)
|
10
|
+
proper_wait 0.6
|
11
|
+
alert.visible?.should == false
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should have :show option (show: true)' do
|
15
|
+
alert = UIActionSheet.alert('test', show: true)
|
16
|
+
proper_wait 0.6
|
17
|
+
alert.visible?.should == true
|
18
|
+
alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should show by default' do
|
22
|
+
alert = UIActionSheet.alert('test')
|
23
|
+
proper_wait 0.6
|
24
|
+
alert.visible?.should == true
|
25
|
+
alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should assign the title' do
|
29
|
+
alert = UIActionSheet.alert('test title', show: false)
|
30
|
+
alert.title.should == 'test title'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should have << method' do
|
34
|
+
alert = UIActionSheet.alert('test', show: false)
|
35
|
+
-> {
|
36
|
+
alert << 'title'
|
37
|
+
}.should.not.raise
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should have :style option' do
|
41
|
+
Symbol.action_sheet_styles.each do |style, value|
|
42
|
+
# as symbol
|
43
|
+
alert = UIActionSheet.alert('test', show: false, style: style)
|
44
|
+
alert.actionSheetStyle.should == value
|
45
|
+
|
46
|
+
# as constant
|
47
|
+
alert = UIActionSheet.alert('test', show: false, style: value)
|
48
|
+
alert.actionSheetStyle.should == value
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should add a button with << method' do
|
53
|
+
alert = UIActionSheet.alert('test', show: false)
|
54
|
+
alert << 'title'
|
55
|
+
alert.buttonTitleAtIndex(alert.firstOtherButtonIndex + 1).should == 'title'
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should show "OK" by default' do
|
59
|
+
alert = UIActionSheet.alert('test', show: false)
|
60
|
+
alert.cancelButtonIndex.should == -1
|
61
|
+
alert.destructiveButtonIndex.should == -1
|
62
|
+
alert.firstOtherButtonIndex.should == 0
|
63
|
+
alert.buttonTitleAtIndex(alert.firstOtherButtonIndex).should == 'OK'
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should call block when pressed' do
|
67
|
+
alert = UIActionSheet.alert('test') { @touched = true }
|
68
|
+
proper_wait 0.6
|
69
|
+
alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)
|
70
|
+
@touched.should == true
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should call block with "OK" pressed' do
|
74
|
+
alert = UIActionSheet.alert('test') { |button| @touched = button }
|
75
|
+
proper_wait 0.6
|
76
|
+
alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)
|
77
|
+
@touched.should == 'OK'
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'with all :buttons defined' do
|
81
|
+
|
82
|
+
before do
|
83
|
+
@touched = nil
|
84
|
+
@alert = UIActionSheet.alert('test', buttons: ['cancel', 'destructive', 'ok']) { |button| @touched = button }
|
85
|
+
proper_wait 0.6
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should call block with "cancel" when cancel button is pressed' do
|
89
|
+
@alert.cancelButtonIndex.should == 2
|
90
|
+
@alert.dismissWithClickedButtonIndex(@alert.cancelButtonIndex, animated: false)
|
91
|
+
@touched.should == 'cancel'
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should call block with "destructive" when destructive button is pressed' do
|
95
|
+
@alert.destructiveButtonIndex.should == 0
|
96
|
+
@alert.dismissWithClickedButtonIndex(@alert.destructiveButtonIndex, animated: false)
|
97
|
+
@touched.should == 'destructive'
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should call block with "ok" when other button is pressed' do
|
101
|
+
@alert.firstOtherButtonIndex.should == 1
|
102
|
+
@alert.dismissWithClickedButtonIndex(@alert.firstOtherButtonIndex, animated: false)
|
103
|
+
@touched.should == 'ok'
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
describe 'with cancel and destructive :buttons defined' do
|
109
|
+
|
110
|
+
before do
|
111
|
+
@touched = nil
|
112
|
+
@alert = UIActionSheet.alert('test', buttons: ['cancel', 'destructive']) { |button| @touched = button }
|
113
|
+
proper_wait 0.6
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should call block with "cancel" when cancel button is pressed' do
|
117
|
+
@alert.cancelButtonIndex.should == 1
|
118
|
+
@alert.dismissWithClickedButtonIndex(@alert.cancelButtonIndex, animated: false)
|
119
|
+
@touched.should == 'cancel'
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should call block with "destructive" when destructive button is pressed' do
|
123
|
+
@alert.destructiveButtonIndex.should == 0
|
124
|
+
@alert.dismissWithClickedButtonIndex(@alert.destructiveButtonIndex, animated: false)
|
125
|
+
@touched.should == 'destructive'
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'should not have other buttons' do
|
129
|
+
@alert.firstOtherButtonIndex.should == -1
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
describe 'with cancel and other :buttons defined' do
|
135
|
+
|
136
|
+
before do
|
137
|
+
@touched = nil
|
138
|
+
@alert = UIActionSheet.alert('test', buttons: ['cancel', nil, 'ok']) { |button| @touched = button }
|
139
|
+
proper_wait 0.6
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should call block with "cancel" when cancel button is pressed' do
|
143
|
+
@alert.cancelButtonIndex.should == 1
|
144
|
+
@alert.dismissWithClickedButtonIndex(@alert.cancelButtonIndex, animated: false)
|
145
|
+
@touched.should == 'cancel'
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'should not have destructive button' do
|
149
|
+
@alert.destructiveButtonIndex.should == -1
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'should call block with "ok" when other button is pressed' do
|
153
|
+
@alert.firstOtherButtonIndex.should == 0
|
154
|
+
@alert.dismissWithClickedButtonIndex(@alert.firstOtherButtonIndex, animated: false)
|
155
|
+
@touched.should == 'ok'
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
describe 'with destructive and other :buttons defined' do
|
161
|
+
|
162
|
+
before do
|
163
|
+
@touched = nil
|
164
|
+
@alert = UIActionSheet.alert('test', buttons: [nil, 'destructive', 'ok']) { |button| @touched = button }
|
165
|
+
proper_wait 0.6
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'should call block with "cancel" when cancel button is pressed' do
|
169
|
+
@alert.cancelButtonIndex.should == -1
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should not have destructive button' do
|
173
|
+
@alert.destructiveButtonIndex.should == 0
|
174
|
+
@alert.dismissWithClickedButtonIndex(@alert.destructiveButtonIndex, animated: false)
|
175
|
+
@touched.should == 'destructive'
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'should call block with "ok" when other button is pressed' do
|
179
|
+
@alert.firstOtherButtonIndex.should == 1
|
180
|
+
@alert.dismissWithClickedButtonIndex(@alert.firstOtherButtonIndex, animated: false)
|
181
|
+
@touched.should == 'ok'
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
describe 'with other :buttons defined' do
|
187
|
+
|
188
|
+
before do
|
189
|
+
@touched = nil
|
190
|
+
@alert = UIActionSheet.alert('test', buttons: [nil, nil, 'test1', 'test2']) { |button| @touched = button }
|
191
|
+
proper_wait 0.6
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should call block with "cancel" when cancel button is pressed' do
|
195
|
+
@alert.cancelButtonIndex.should == -1
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'should not have destructive button' do
|
199
|
+
@alert.destructiveButtonIndex.should == -1
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'should call block with "test1" when first button is pressed' do
|
203
|
+
@alert.firstOtherButtonIndex.should == 0
|
204
|
+
@alert.dismissWithClickedButtonIndex(@alert.firstOtherButtonIndex, animated: false)
|
205
|
+
@touched.should == 'test1'
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'should call block with "test2" when second button is pressed' do
|
209
|
+
@alert.dismissWithClickedButtonIndex(@alert.firstOtherButtonIndex + 1, animated: false)
|
210
|
+
@touched.should == 'test2'
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
describe 'with all handlers defined' do
|
216
|
+
|
217
|
+
before do
|
218
|
+
@touched = nil
|
219
|
+
@alert = UIActionSheet.alert('test',
|
220
|
+
buttons: ['cancel', 'destructive', 'test1', 'test2'],
|
221
|
+
cancel: ->{ @touched = :cancel },
|
222
|
+
destructive: ->{ @touched = :destructive },
|
223
|
+
success: ->(button){ @touched = button },
|
224
|
+
)
|
225
|
+
proper_wait 0.6
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'should call block with "cancel" when cancel button is pressed' do
|
229
|
+
@alert.cancelButtonIndex.should == 3
|
230
|
+
@alert.dismissWithClickedButtonIndex(@alert.cancelButtonIndex, animated: false)
|
231
|
+
@touched.should == :cancel
|
232
|
+
end
|
233
|
+
|
234
|
+
it 'should call block with "destructive" when destructive button is pressed' do
|
235
|
+
@alert.destructiveButtonIndex.should == 0
|
236
|
+
@alert.dismissWithClickedButtonIndex(@alert.destructiveButtonIndex, animated: false)
|
237
|
+
@touched.should == :destructive
|
238
|
+
end
|
239
|
+
|
240
|
+
it 'should call block with "test1" when first button is pressed' do
|
241
|
+
@alert.firstOtherButtonIndex.should == 1
|
242
|
+
@alert.dismissWithClickedButtonIndex(@alert.firstOtherButtonIndex, animated: false)
|
243
|
+
@touched.should == 'test1'
|
244
|
+
end
|
245
|
+
|
246
|
+
it 'should call block with "test2" when second button is pressed' do
|
247
|
+
@alert.dismissWithClickedButtonIndex(@alert.firstOtherButtonIndex + 1, animated: false)
|
248
|
+
@touched.should == 'test2'
|
249
|
+
end
|
250
|
+
|
251
|
+
end
|
252
|
+
|
253
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
describe 'UIAlertView' do
|
2
|
+
tests UIViewController # this is just needed so that a window is available
|
3
|
+
|
4
|
+
it 'should have :show option (show: false)' do
|
5
|
+
alert = UIAlertView.alert('test', show: false)
|
6
|
+
proper_wait 0.6
|
7
|
+
alert.visible?.should == false
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should have :show option (show: true)' do
|
11
|
+
alert = UIAlertView.alert('test', show: true)
|
12
|
+
proper_wait 0.6
|
13
|
+
alert.visible?.should == true
|
14
|
+
alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should show by default' do
|
18
|
+
alert = UIAlertView.alert('test')
|
19
|
+
proper_wait 0.6
|
20
|
+
alert.visible?.should == true
|
21
|
+
alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should assign the title' do
|
25
|
+
alert = UIAlertView.alert('test title', show: false)
|
26
|
+
alert.title.should == 'test title'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should support three args' do
|
30
|
+
alert = UIAlertView.alert('test title', 'test message', show: false)
|
31
|
+
alert.visible?.should == false
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'should assign the message' do
|
35
|
+
|
36
|
+
it 'should use the second arg' do
|
37
|
+
alert = UIAlertView.alert('test title', 'test message', show: false)
|
38
|
+
alert.message.should == 'test message'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should use the :message option' do
|
42
|
+
alert = UIAlertView.alert('test title', message: 'test message', show: false)
|
43
|
+
alert.message.should == 'test message'
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should have << method' do
|
49
|
+
alert = UIAlertView.alert('test', show: false)
|
50
|
+
-> {
|
51
|
+
alert << 'title'
|
52
|
+
}.should.not.raise
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should add a button with << method' do
|
56
|
+
alert = UIAlertView.alert('test', show: false)
|
57
|
+
alert << 'title'
|
58
|
+
alert.buttonTitleAtIndex(alert.firstOtherButtonIndex + 1).should == 'title'
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should display "OK" when no buttons are specified' do
|
62
|
+
alert = UIAlertView.alert('test', show: false)
|
63
|
+
alert.cancelButtonIndex.should == -1
|
64
|
+
alert.buttonTitleAtIndex(alert.firstOtherButtonIndex).should == 'OK'
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should use a cancel button if any buttons are specified' do
|
68
|
+
alert = UIAlertView.alert('test', buttons: ['a', 'b'], show: false)
|
69
|
+
alert.buttonTitleAtIndex(alert.cancelButtonIndex).should == 'a'
|
70
|
+
alert.buttonTitleAtIndex(alert.firstOtherButtonIndex).should == 'b'
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should have :style option' do
|
74
|
+
Symbol.alert_view_styles.each do |style, value|
|
75
|
+
# as symbol
|
76
|
+
alert = UIAlertView.alert('test', show: false, style: style)
|
77
|
+
alert.alertViewStyle.should == value
|
78
|
+
|
79
|
+
# as constant
|
80
|
+
alert = UIAlertView.alert('test', show: false, style: value)
|
81
|
+
alert.alertViewStyle.should == value
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should call the block when dismissed' do
|
86
|
+
alert = UIAlertView.alert('test') { @touched = true }
|
87
|
+
alert.numberOfButtons.should == 1
|
88
|
+
proper_wait 0.6
|
89
|
+
alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)
|
90
|
+
|
91
|
+
@touched.should == true
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should call the block and pass the button when dismissed' do
|
95
|
+
alert = UIAlertView.alert('test') { |button| @touched = button }
|
96
|
+
proper_wait 0.6
|
97
|
+
alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)
|
98
|
+
|
99
|
+
@touched.should == 'OK'
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should call the block when dismissed no matter when cancel button pressed' do
|
103
|
+
alert = UIAlertView.alert('test', buttons:['cancel','ok']) { @touched = true }
|
104
|
+
alert.numberOfButtons.should == 2
|
105
|
+
proper_wait 0.6
|
106
|
+
alert.dismissWithClickedButtonIndex(alert.cancelButtonIndex, animated: false)
|
107
|
+
|
108
|
+
@touched.should == true
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should call the block and pass the button when dismissed with multiple buttons' do
|
112
|
+
alert = UIAlertView.alert('test', buttons: ['cancel', 'ok']) { |button| @touched = button }
|
113
|
+
proper_wait 0.6
|
114
|
+
alert.dismissWithClickedButtonIndex(alert.cancelButtonIndex, animated: false)
|
115
|
+
|
116
|
+
@touched.should == 'cancel'
|
117
|
+
end
|
118
|
+
|
119
|
+
describe 'Should call the appropriate block when :cancel and :success handlers are used' do
|
120
|
+
|
121
|
+
before do
|
122
|
+
@touched = nil
|
123
|
+
@alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'],
|
124
|
+
cancel: ->{ @touched = :cancel },
|
125
|
+
success: ->{ @touched = :success }
|
126
|
+
)
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should work for :cancel' do
|
130
|
+
proper_wait 0.6
|
131
|
+
@alert.dismissWithClickedButtonIndex(@alert.cancelButtonIndex, animated: false)
|
132
|
+
|
133
|
+
@touched.should == :cancel
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should work for :success' do
|
137
|
+
proper_wait 0.6
|
138
|
+
@alert.dismissWithClickedButtonIndex(@alert.firstOtherButtonIndex, animated: false)
|
139
|
+
|
140
|
+
@touched.should == :success
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
describe 'should call the block and pass the button and inputs' do
|
146
|
+
|
147
|
+
before do
|
148
|
+
@text = nil
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'should work with :secure_text_input' do
|
152
|
+
alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'], style: :secure_text_input) { |button, text|
|
153
|
+
@text = text
|
154
|
+
}
|
155
|
+
proper_wait 0.6
|
156
|
+
alert.textFieldAtIndex(0).text = 'test text'
|
157
|
+
alert.dismissWithClickedButtonIndex(alert.cancelButtonIndex, animated: false)
|
158
|
+
|
159
|
+
@text.should == 'test text'
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'should work with :plain_text_input' do
|
163
|
+
alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'], style: :plain_text_input) { |button, text|
|
164
|
+
@text = text
|
165
|
+
}
|
166
|
+
proper_wait 0.6
|
167
|
+
alert.textFieldAtIndex(0).text = 'test text'
|
168
|
+
alert.dismissWithClickedButtonIndex(alert.cancelButtonIndex, animated: false)
|
169
|
+
|
170
|
+
@text.should == 'test text'
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'should work with :login_and_password_input' do
|
174
|
+
alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'], style: :login_and_password_input) { |button, text1, text2|
|
175
|
+
@text = "#{text1} + #{text2}"
|
176
|
+
}
|
177
|
+
proper_wait 0.6
|
178
|
+
alert.textFieldAtIndex(0).text = 'test text 1'
|
179
|
+
alert.textFieldAtIndex(1).text = 'test text 2'
|
180
|
+
alert.dismissWithClickedButtonIndex(alert.cancelButtonIndex, animated: false)
|
181
|
+
|
182
|
+
@text.should == 'test text 1 + test text 2'
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
@@ -7,7 +7,15 @@ describe "UIView animation methods" do
|
|
7
7
|
@view.delta_to([1,2]).frame.should == CGRectMake(2,4,3,4)
|
8
8
|
end
|
9
9
|
|
10
|
-
it 'should
|
10
|
+
it 'should resize_to w:5 h:6' do
|
11
|
+
@view.resize_to([5,6]).frame.should == CGRectMake(1,2,5,6)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should reframe_to ' do
|
15
|
+
@view.reframe_to([[2,4],[5,6]]).frame.should == CGRectMake(2,4,5,6)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should move_to x:2 y:4' do
|
11
19
|
@view.move_to([2,4]).frame.should == CGRectMake(2,4,3,4)
|
12
20
|
end
|
13
21
|
|
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: 0.20.
|
4
|
+
version: 0.20.15
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2013-04-
|
16
|
+
date: 2013-04-24 00:00:00.000000000 Z
|
17
17
|
dependencies: []
|
18
18
|
description: ! '== Description
|
19
19
|
|
@@ -155,11 +155,14 @@ files:
|
|
155
155
|
- spec/nsset_spec.rb
|
156
156
|
- spec/nsstring_files_spec.rb
|
157
157
|
- spec/nsstring_spec.rb
|
158
|
+
- spec/nsstring_timezone_spec.rb
|
158
159
|
- spec/nsurl_spec.rb
|
159
160
|
- spec/numeric_spec.rb
|
160
161
|
- spec/symbol_spec.rb
|
161
162
|
- spec/symbol_uicolor_spec.rb
|
162
163
|
- spec/timer_spec.rb
|
164
|
+
- spec/uiactionsheet_spec.rb
|
165
|
+
- spec/uialertview_spec.rb
|
163
166
|
- spec/uibarbuttonitem_spec.rb
|
164
167
|
- spec/uicolor_components_spec.rb
|
165
168
|
- spec/uicolor_other_representations_spec.rb
|
@@ -221,11 +224,14 @@ test_files:
|
|
221
224
|
- spec/nsset_spec.rb
|
222
225
|
- spec/nsstring_files_spec.rb
|
223
226
|
- spec/nsstring_spec.rb
|
227
|
+
- spec/nsstring_timezone_spec.rb
|
224
228
|
- spec/nsurl_spec.rb
|
225
229
|
- spec/numeric_spec.rb
|
226
230
|
- spec/symbol_spec.rb
|
227
231
|
- spec/symbol_uicolor_spec.rb
|
228
232
|
- spec/timer_spec.rb
|
233
|
+
- spec/uiactionsheet_spec.rb
|
234
|
+
- spec/uialertview_spec.rb
|
229
235
|
- spec/uibarbuttonitem_spec.rb
|
230
236
|
- spec/uicolor_components_spec.rb
|
231
237
|
- spec/uicolor_other_representations_spec.rb
|