sugarcube 0.20.7 → 0.20.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +21 -8
- data/lib/sugarcube/adjust.rb +13 -2
- data/lib/sugarcube/nsdata.rb +1 -1
- data/lib/sugarcube/nsdate.rb +37 -1
- data/lib/sugarcube/nsindexpath.rb +9 -0
- data/lib/sugarcube/nsstring.rb +1 -1
- data/lib/sugarcube/nsurl.rb +4 -0
- data/lib/sugarcube/timer.rb +11 -0
- data/lib/sugarcube/uialertview.rb +30 -14
- data/lib/sugarcube/version.rb +1 -1
- data/lib/sugarcube-repl/object.rb +97 -0
- data/lib/sugarcube-repl.rb +23 -0
- data/spec/nsdata_spec.rb +17 -5
- data/spec/nsdate_spec.rb +8 -0
- metadata +4 -2
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -314,6 +314,15 @@ recurring events)
|
|
314
314
|
(main)> feb_1_2013.end_of_day
|
315
315
|
# NOTE! end_of_day is the NEXT DAY. this is not an accident, it makes comparisons cleaner. deal with it.
|
316
316
|
=> 2013-02-02 00:00:00 -0700
|
317
|
+
(main)> feb_1_2013.start_of_week # in the USA, start of week is Sunday
|
318
|
+
=> 2013-01-27 00:00:00 -0700
|
319
|
+
=> 2013-01-28 00:00:00 -0700 # in most other countries you will get Monday
|
320
|
+
(main)> feb_1_2013.start_of_week(:monday) # or you can specify it!
|
321
|
+
=> 2013-01-28 00:00:00 -0700
|
322
|
+
(main)> feb_1_2013.end_of_week # Just like end_of_day, end_of_week returns midnight of the *next day*
|
323
|
+
=> 2013-02-03 00:00:00 -0700
|
324
|
+
(main)> feb_1_2013.end_of_week(:monday)
|
325
|
+
=> 2013-02-04 00:00:00 -0700
|
317
326
|
(main)> feb_1_2013.days_in_month
|
318
327
|
=> 28
|
319
328
|
(main)> feb_1_2013.days_in_year
|
@@ -661,21 +670,25 @@ some problems with on RubyMotion (it worked, but not *always*. Very strange).
|
|
661
670
|
UIAlertView
|
662
671
|
--------
|
663
672
|
|
664
|
-
Accepts multiple buttons and
|
665
|
-
|
673
|
+
Accepts multiple buttons and handlers. In its simplest form, you can pass just
|
674
|
+
a title and block.
|
666
675
|
|
667
676
|
```ruby
|
668
677
|
# simple
|
669
678
|
UIAlertView.alert "This is happening, OK?" { self.happened! }
|
670
|
-
|
679
|
+
|
680
|
+
# a little more complex - the cancel button should be first, and the block will
|
681
|
+
# receive a string, not an index
|
671
682
|
UIAlertView.alert("This is happening, OK?", buttons: ["Nevermind", "OK"],
|
672
|
-
message: "Don't worry, it'll be fine.") {
|
673
|
-
|
683
|
+
message: "Don't worry, it'll be fine.") { |button|
|
684
|
+
if button == "OK"
|
685
|
+
self.happened!
|
686
|
+
end
|
674
687
|
}
|
675
688
|
|
676
|
-
# Full on whiz-bangery.
|
677
|
-
#
|
678
|
-
#
|
689
|
+
# Full on whiz-bangery. The cancel button should be the first entry in
|
690
|
+
# `buttons:`. When you specify the success and cancel button handlers this way,
|
691
|
+
# you need not assign both.
|
679
692
|
UIAlertView.alert "I mean, is this cool?", buttons: %w[No! Sure! Hmmmm],
|
680
693
|
message: "No going back now",
|
681
694
|
cancel: proc { self.cancel },
|
data/lib/sugarcube/adjust.rb
CHANGED
@@ -244,9 +244,19 @@ module SugarCube
|
|
244
244
|
end
|
245
245
|
alias h shadow
|
246
246
|
|
247
|
-
|
247
|
+
# @param item this can be a tree-like item (UIView, UIViewController,
|
248
|
+
# CALayer) or an integer, in which case it will select that window from
|
249
|
+
# UIApplication.sharedApplication.window. Defalt is to display the
|
250
|
+
# keyWindow
|
251
|
+
# @param selector If you pass an unsupported object to tree, you will need
|
252
|
+
# to pass a selector as well - this method should return an array of
|
253
|
+
# items which are passed recursively to tree
|
254
|
+
# @block sel_blk If a block is passed, it will be used to build the array of
|
255
|
+
# items that are called recursively
|
248
256
|
def tree(item=nil, selector=nil, &sel_blk)
|
249
|
-
|
257
|
+
if item.is_a?(Fixnum)
|
258
|
+
item = UIApplication.sharedApplication.windows[item]
|
259
|
+
elsif ! item
|
250
260
|
item = UIApplication.sharedApplication.keyWindow
|
251
261
|
end
|
252
262
|
if not item
|
@@ -291,6 +301,7 @@ module SugarCube
|
|
291
301
|
return item
|
292
302
|
end
|
293
303
|
|
304
|
+
# Draws the tree items
|
294
305
|
def draw_tree(item, selector, tab=nil, is_last=true, items_index=0)
|
295
306
|
space = ' '
|
296
307
|
if items_index < 10
|
data/lib/sugarcube/nsdata.rb
CHANGED
data/lib/sugarcube/nsdate.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class NSDate
|
2
|
-
# these formatters are used in `string_with_format`. Symbols are
|
2
|
+
# these formatters are used in `string_with_format`. Symbols are converted to
|
3
3
|
# a string using string_with_format's templating, and strings are concatenated
|
4
4
|
# as-is
|
5
5
|
SugarCubeFormats = {
|
@@ -174,6 +174,24 @@ class NSDate
|
|
174
174
|
return self + time_interval
|
175
175
|
end
|
176
176
|
|
177
|
+
# (main)> t = Time.new
|
178
|
+
# => 2012-09-27 11:29:12 +0900
|
179
|
+
# (main)> t.start_of_week
|
180
|
+
# => 2012-09-23 00:00:00 +0900
|
181
|
+
def start_of_week(start_day=nil)
|
182
|
+
result = self - days_to_week_start(start_day).days
|
183
|
+
result.start_of_day
|
184
|
+
end
|
185
|
+
|
186
|
+
# (main)> t = Time.new
|
187
|
+
# => 2012-09-27 11:29:12 +0900
|
188
|
+
# (main)> t.start_of_week
|
189
|
+
# => 2012-09-30 00:00:00 +0900
|
190
|
+
def end_of_week(start_day=nil)
|
191
|
+
result = self - days_to_week_start(start_day).days + 6.days
|
192
|
+
result.end_of_day
|
193
|
+
end
|
194
|
+
|
177
195
|
# (main)> t = Time.new
|
178
196
|
# => 2012-09-27 11:29:12 +0900
|
179
197
|
# (main)> t.start_of_month
|
@@ -202,4 +220,22 @@ class NSDate
|
|
202
220
|
def _calendar_components(components)
|
203
221
|
return NSCalendar.currentCalendar.components(components, fromDate:self)
|
204
222
|
end
|
223
|
+
|
224
|
+
def days_to_week_start(start_day=nil)
|
225
|
+
start_day_number = week_day_index(start_day) || local_week_start
|
226
|
+
current_day_number = _calendar_components(NSWeekdayCalendarUnit).weekday
|
227
|
+
(current_day_number - start_day_number) % 7
|
228
|
+
end
|
229
|
+
|
230
|
+
def local_week_start
|
231
|
+
NSCalendar.currentCalendar.firstWeekday
|
232
|
+
end
|
233
|
+
|
234
|
+
def week_day_index(week_day=:monday)
|
235
|
+
day = week_day.to_s.capitalizedString
|
236
|
+
index = NSDateFormatter.new.weekdaySymbols.index(day)
|
237
|
+
return nil unless index
|
238
|
+
index + 1
|
239
|
+
end
|
240
|
+
|
205
241
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
class NSIndexPath
|
2
|
+
|
2
3
|
def to_a
|
3
4
|
indexes_ptr = Pointer.new(:uint, self.length)
|
4
5
|
self.getIndexes indexes_ptr
|
@@ -8,9 +9,17 @@ class NSIndexPath
|
|
8
9
|
end
|
9
10
|
a
|
10
11
|
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
"<NSIndexPath #{to_a.to_s}>"
|
15
|
+
end
|
16
|
+
|
11
17
|
end
|
12
18
|
|
13
19
|
|
20
|
+
# This class is used in `switch` statements. Easy pattern matching, so instead
|
21
|
+
# of `if index_path.row...index_path.section`, you can use
|
22
|
+
# `when IndexPath[row, section]`
|
14
23
|
class IndexPath
|
15
24
|
|
16
25
|
def self.[] *values
|
data/lib/sugarcube/nsstring.rb
CHANGED
data/lib/sugarcube/nsurl.rb
CHANGED
data/lib/sugarcube/timer.rb
CHANGED
@@ -15,8 +15,9 @@ class UIAlertView
|
|
15
15
|
|
16
16
|
# create the delegate
|
17
17
|
delegate = SugarCube::AlertViewDelegate.new
|
18
|
-
delegate.on_success = options[:success]
|
18
|
+
delegate.on_success = options[:success]
|
19
19
|
delegate.on_cancel = options[:cancel]
|
20
|
+
delegate.on_default = block
|
20
21
|
delegate.send(:retain)
|
21
22
|
|
22
23
|
args = [title] # initWithTitle:
|
@@ -26,10 +27,18 @@ class UIAlertView
|
|
26
27
|
buttons = options[:buttons] || []
|
27
28
|
if buttons.empty?
|
28
29
|
# cancelButtonTitle: is first, so check for cancel
|
29
|
-
|
30
|
+
if options[:cancel]
|
31
|
+
buttons << "Cancel"
|
32
|
+
end
|
33
|
+
|
30
34
|
# otherButtonTitles:
|
31
|
-
|
32
|
-
|
35
|
+
if buttons.empty?
|
36
|
+
buttons << nil # cancel button => nil
|
37
|
+
buttons << "OK" # other buttons => "OK"
|
38
|
+
elsif options[:success]
|
39
|
+
buttons << "OK"
|
40
|
+
end
|
41
|
+
elsif buttons.length == 1 && options[:cancel]
|
33
42
|
raise "If you only have one button, use a :success handler, not :cancel (and definitely not BOTH)"
|
34
43
|
end
|
35
44
|
|
@@ -37,7 +46,7 @@ class UIAlertView
|
|
37
46
|
delegate.buttons = buttons
|
38
47
|
|
39
48
|
# uses localized buttons in the actual alert
|
40
|
-
args.concat(buttons.map{ |
|
49
|
+
args.concat(buttons.map { |m| m && m.localized })
|
41
50
|
args << nil # otherButtonTitles:..., nil
|
42
51
|
|
43
52
|
alert = self.alloc
|
@@ -59,17 +68,24 @@ module SugarCube
|
|
59
68
|
attr_accessor :buttons
|
60
69
|
attr_accessor :on_cancel
|
61
70
|
attr_accessor :on_success
|
71
|
+
attr_accessor :on_default
|
62
72
|
|
63
73
|
def alertView(alert, didDismissWithButtonIndex:index)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
74
|
+
cancel_handler = on_cancel || on_default
|
75
|
+
success_handler = on_success || on_default
|
76
|
+
handler = nil
|
77
|
+
|
78
|
+
if index == alert.cancelButtonIndex
|
79
|
+
handler = cancel_handler
|
80
|
+
else
|
81
|
+
handler = success_handler
|
82
|
+
end
|
83
|
+
|
84
|
+
if handler.arity == 0
|
85
|
+
handler.call
|
86
|
+
else
|
87
|
+
button = buttons[index]
|
88
|
+
handler.call(button)
|
73
89
|
end
|
74
90
|
|
75
91
|
self.send(:autorelease)
|
data/lib/sugarcube/version.rb
CHANGED
@@ -0,0 +1,97 @@
|
|
1
|
+
class Object
|
2
|
+
|
3
|
+
private
|
4
|
+
def adjust(*args)
|
5
|
+
SugarCube::Adjust.adjust(*args)
|
6
|
+
end
|
7
|
+
def a(*args)
|
8
|
+
SugarCube::Adjust.adjust(*args)
|
9
|
+
end
|
10
|
+
def frame(*args)
|
11
|
+
SugarCube::Adjust.frame(*args)
|
12
|
+
end
|
13
|
+
def f(*args)
|
14
|
+
SugarCube::Adjust.frame(*args)
|
15
|
+
end
|
16
|
+
def left(*args)
|
17
|
+
SugarCube::Adjust.left(*args)
|
18
|
+
end
|
19
|
+
def l(*args)
|
20
|
+
SugarCube::Adjust.left(*args)
|
21
|
+
end
|
22
|
+
def right(*args)
|
23
|
+
SugarCube::Adjust.right(*args)
|
24
|
+
end
|
25
|
+
def r(*args)
|
26
|
+
SugarCube::Adjust.right(*args)
|
27
|
+
end
|
28
|
+
def up(*args)
|
29
|
+
SugarCube::Adjust.up(*args)
|
30
|
+
end
|
31
|
+
def u(*args)
|
32
|
+
SugarCube::Adjust.up(*args)
|
33
|
+
end
|
34
|
+
def down(*args)
|
35
|
+
SugarCube::Adjust.down(*args)
|
36
|
+
end
|
37
|
+
def d(*args)
|
38
|
+
SugarCube::Adjust.down(*args)
|
39
|
+
end
|
40
|
+
def origin(*args)
|
41
|
+
SugarCube::Adjust.origin(*args)
|
42
|
+
end
|
43
|
+
def o(*args)
|
44
|
+
SugarCube::Adjust.origin(*args)
|
45
|
+
end
|
46
|
+
def thinner(*args)
|
47
|
+
SugarCube::Adjust.thinner(*args)
|
48
|
+
end
|
49
|
+
def n(*args)
|
50
|
+
SugarCube::Adjust.thinner(*args)
|
51
|
+
end
|
52
|
+
def wider(*args)
|
53
|
+
SugarCube::Adjust.wider(*args)
|
54
|
+
end
|
55
|
+
def w(*args)
|
56
|
+
SugarCube::Adjust.wider(*args)
|
57
|
+
end
|
58
|
+
def shorter(*args)
|
59
|
+
SugarCube::Adjust.shorter(*args)
|
60
|
+
end
|
61
|
+
def s(*args)
|
62
|
+
SugarCube::Adjust.shorter(*args)
|
63
|
+
end
|
64
|
+
def taller(*args)
|
65
|
+
SugarCube::Adjust.taller(*args)
|
66
|
+
end
|
67
|
+
def t(*args)
|
68
|
+
SugarCube::Adjust.taller(*args)
|
69
|
+
end
|
70
|
+
def size(*args)
|
71
|
+
SugarCube::Adjust.size(*args)
|
72
|
+
end
|
73
|
+
def z(*args)
|
74
|
+
SugarCube::Adjust.size(*args)
|
75
|
+
end
|
76
|
+
def center(*args)
|
77
|
+
SugarCube::Adjust.center(*args)
|
78
|
+
end
|
79
|
+
def c(*args)
|
80
|
+
SugarCube::Adjust.center(*args)
|
81
|
+
end
|
82
|
+
def shadow(*args)
|
83
|
+
SugarCube::Adjust.shadow(*args)
|
84
|
+
end
|
85
|
+
def h(*args)
|
86
|
+
SugarCube::Adjust.shadow(*args)
|
87
|
+
end
|
88
|
+
def tree(*args)
|
89
|
+
SugarCube::Adjust.tree(*args)
|
90
|
+
end
|
91
|
+
def root(*args)
|
92
|
+
SugarCube::Adjust.root(*args)
|
93
|
+
end
|
94
|
+
def restore(*args)
|
95
|
+
SugarCube::Adjust.restore(*args)
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
unless defined?(Motion::Project::Config)
|
2
|
+
raise "The sugarcube gem must be required within a RubyMotion project Rakefile."
|
3
|
+
end
|
4
|
+
|
5
|
+
|
6
|
+
Motion::Project::App.setup do |app|
|
7
|
+
# scans app.files until it finds app/ (the default)
|
8
|
+
# if found, it inserts just before those files, otherwise it will insert to
|
9
|
+
# the end of the list
|
10
|
+
insert_point = 0
|
11
|
+
app.files.each_index do |index|
|
12
|
+
file = app.files[index]
|
13
|
+
if file =~ /^(?:\.\/)?app\//
|
14
|
+
# found app/, so stop looking
|
15
|
+
break
|
16
|
+
end
|
17
|
+
insert_point = index + 1
|
18
|
+
end
|
19
|
+
|
20
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'sugarcube-repl/**/*.rb')).reverse.each do |file|
|
21
|
+
app.files.insert(insert_point, file)
|
22
|
+
end
|
23
|
+
end
|
data/spec/nsdata_spec.rb
CHANGED
@@ -26,13 +26,13 @@ describe "NSData" do
|
|
26
26
|
it "should be able to create a turkey string from data" do
|
27
27
|
"\u00ab\u03c4\u03b1\u0411\u042c\u2113\u03c3\u00bb".nsdata.nsstring.should == "\u00ab\u03c4\u03b1\u0411\u042c\u2113\u03c3\u00bb"
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
describe "write_to" do
|
31
|
-
|
31
|
+
|
32
32
|
after do
|
33
33
|
"a-z".document.remove!
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it "should write data to spcified path" do
|
37
37
|
path = "a-z".document
|
38
38
|
contents = (:a..:z).to_a.join
|
@@ -40,7 +40,7 @@ describe "NSData" do
|
|
40
40
|
path.exists?.should == true
|
41
41
|
path.fileurl.nsdata.nsstring.should == contents
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
it "should write data to spcified url" do
|
45
45
|
url = NSURL.alloc.initFileURLWithPath "a-z".document
|
46
46
|
contents = (:a..:z).to_a.join
|
@@ -49,7 +49,19 @@ describe "NSData" do
|
|
49
49
|
path.exists?.should == true
|
50
50
|
url.nsdata.nsstring.should == contents
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
describe 'base64' do
|
56
|
+
|
57
|
+
it 'should convert nsstring data to base64' do
|
58
|
+
'much longer test'.nsdata.base64.should == 'bXVjaCBsb25nZXIgdGVzdA=='
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should convert image data (PNG) to base64' do
|
62
|
+
'test'.uiimage.nsdata.base64.should == 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAHgCAIAAADrGJBNAAAAHElEQVQ4jWO4a8TAxMAwikfxKB7Fo3gUj2I6YgAAiQTO+8u2PwAAAABJRU5ErkJggg=='
|
63
|
+
end
|
64
|
+
|
53
65
|
end
|
54
66
|
|
55
67
|
end
|
data/spec/nsdate_spec.rb
CHANGED
@@ -118,6 +118,14 @@ describe "NSDate" do
|
|
118
118
|
@date.end_of_day.datetime_array.should == [2013, 1, 3, 0, 0, 0]
|
119
119
|
end
|
120
120
|
|
121
|
+
it "should have an NSDate#start_of_week method" do
|
122
|
+
@date.start_of_week(:sunday).datetime_array.should == [2012, 12, 30, 0, 0, 0]
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should have an NSDate#end_of_week method" do
|
126
|
+
@date.end_of_week(:sunday).datetime_array.should == [2013, 1, 6, 0, 0, 0]
|
127
|
+
end
|
128
|
+
|
121
129
|
it "should have an NSDate#start_of_month method" do
|
122
130
|
@date.start_of_month.datetime_array.should == [2013, 1, 1, 0, 0, 0]
|
123
131
|
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: 0.20.
|
4
|
+
version: 0.20.8
|
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-19 00:00:00.000000000 Z
|
17
17
|
dependencies: []
|
18
18
|
description: ! '== Description
|
19
19
|
|
@@ -62,6 +62,8 @@ files:
|
|
62
62
|
- lib/sugarcube-attributedstring/nsattributedstring.rb
|
63
63
|
- lib/sugarcube-gestures.rb
|
64
64
|
- lib/sugarcube-gestures/gestures.rb
|
65
|
+
- lib/sugarcube-repl.rb
|
66
|
+
- lib/sugarcube-repl/object.rb
|
65
67
|
- lib/sugarcube-unholy.rb
|
66
68
|
- lib/sugarcube-unholy/ivar.rb
|
67
69
|
- lib/sugarcube.rb
|