sugarcube 0.20.25 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -1
- data/Gemfile.lock +1 -1
- data/README.md +897 -1306
- data/Rakefile +3 -7
- data/app/uicontrol_controller.rb +2 -2
- data/lib/sugarcube-568.rb +1 -9
- data/lib/sugarcube-all.rb +18 -0
- data/lib/sugarcube-animations.rb +15 -0
- data/lib/{sugarcube → sugarcube-animations}/animation_chain.rb +0 -0
- data/lib/{sugarcube → sugarcube-animations}/uiview.rb +41 -111
- data/lib/sugarcube-anonymous.rb +1 -9
- data/lib/sugarcube-attributedstring.rb +1 -9
- data/lib/sugarcube-attributedstring/nsattributedstring.rb +2 -11
- data/lib/sugarcube-awesome.rb +15 -0
- data/lib/sugarcube-awesome/awesome_exts.rb +22 -0
- data/lib/sugarcube-classic.rb +26 -0
- data/lib/sugarcube-color.rb +15 -0
- data/lib/sugarcube-color/fixnum.rb +18 -0
- data/lib/sugarcube-color/nsarray.rb +11 -0
- data/lib/sugarcube-color/nsstring.rb +16 -0
- data/lib/{sugarcube/symbol/symbol_uicolor.rb → sugarcube-color/symbol.rb} +12 -4
- data/lib/{sugarcube → sugarcube-color}/uicolor.rb +16 -2
- data/lib/sugarcube-color/uiimage.rb +13 -0
- data/lib/sugarcube-common.rb +22 -0
- data/lib/sugarcube-constants.rb +15 -0
- data/lib/sugarcube-constants/symbol.rb +759 -0
- data/lib/sugarcube-coregraphics.rb +15 -0
- data/lib/{sugarcube → sugarcube-coregraphics}/core_graphics.rb +0 -0
- data/lib/sugarcube-corelocation.rb +17 -0
- data/lib/{sugarcube → sugarcube-corelocation}/core_location.rb +0 -0
- data/lib/sugarcube-events.rb +15 -0
- data/lib/{sugarcube → sugarcube-events}/uicontrol.rb +3 -3
- data/lib/{sugarcube → sugarcube-events}/uitextview.rb +0 -0
- data/lib/sugarcube-factories.rb +15 -0
- data/lib/{sugarcube → sugarcube-factories}/nserror.rb +0 -0
- data/lib/{sugarcube → sugarcube-factories}/uiactionsheet.rb +3 -1
- data/lib/sugarcube-factories/uiactivityindicator.rb +17 -0
- data/lib/{sugarcube → sugarcube-factories}/uialertview.rb +3 -3
- data/lib/{sugarcube → sugarcube-factories}/uibarbuttonitem.rb +19 -3
- data/lib/{sugarcube → sugarcube-factories}/uibutton.rb +10 -10
- data/lib/{sugarcube → sugarcube-factories}/uisegmentedcontrol.rb +4 -4
- data/lib/{sugarcube → sugarcube-factories}/uitableview.rb +0 -0
- data/lib/{sugarcube → sugarcube-factories}/uitableviewcell.rb +3 -7
- data/lib/sugarcube-files.rb +15 -0
- data/lib/{sugarcube/nsstring_files.rb → sugarcube-files/nsstring.rb} +0 -0
- data/lib/sugarcube-foundation.rb +15 -0
- data/lib/{sugarcube → sugarcube-foundation}/nsarray.rb +0 -18
- data/lib/sugarcube-foundation/nsindexpath.rb +13 -0
- data/lib/{sugarcube → sugarcube-foundation}/nsindexset.rb +0 -0
- data/lib/sugarcube-foundation/nsstring.rb +31 -0
- data/lib/{sugarcube → sugarcube-foundation}/nsurl.rb +0 -4
- data/lib/sugarcube-gestures.rb +1 -9
- data/lib/sugarcube-image.rb +15 -0
- data/lib/sugarcube-image/cicolor.rb +7 -0
- data/lib/sugarcube-image/cifilter.rb +772 -0
- data/lib/sugarcube-image/ciimage.rb +22 -0
- data/lib/sugarcube-image/uicolor.rb +7 -0
- data/lib/{sugarcube → sugarcube-image}/uiimage.rb +38 -41
- data/lib/sugarcube-indexpath.rb +15 -0
- data/lib/{sugarcube/nsindexpath.rb → sugarcube-indexpath/indexpath.rb} +12 -21
- data/lib/sugarcube-legacy.rb +15 -0
- data/lib/{sugarcube → sugarcube-legacy}/activesupport.rb +0 -0
- data/lib/sugarcube-legacy/log.rb +45 -0
- data/lib/sugarcube-legacy/symbol.rb +219 -0
- data/lib/sugarcube-localized.rb +15 -0
- data/lib/sugarcube-localized/nserror.rb +8 -0
- data/lib/sugarcube-localized/nsstring.rb +10 -0
- data/lib/sugarcube-modal.rb +15 -0
- data/lib/{sugarcube → sugarcube-modal}/modal.rb +0 -0
- data/lib/sugarcube-notifications.rb +15 -0
- data/lib/{sugarcube → sugarcube-notifications}/notifications.rb +0 -0
- data/lib/sugarcube-nscoder.rb +15 -0
- data/lib/{sugarcube → sugarcube-nscoder}/nscoder.rb +0 -0
- data/lib/sugarcube-nsdata.rb +15 -0
- data/lib/{sugarcube → sugarcube-nsdata}/nsdata.rb +0 -0
- data/lib/sugarcube-nsdata/nsstring.rb +9 -0
- data/lib/sugarcube-nsdata/nsurl.rb +7 -0
- data/lib/sugarcube-nsdata/uiimage.rb +8 -0
- data/lib/sugarcube-nsdate.rb +15 -0
- data/lib/{sugarcube → sugarcube-nsdate}/date_parser.rb +0 -0
- data/lib/sugarcube-nsdate/fixnum.rb +23 -0
- data/lib/{sugarcube → sugarcube-nsdate}/nsdate.rb +6 -1
- data/lib/{sugarcube → sugarcube-nsdate}/nsdate_delta.rb +0 -0
- data/lib/sugarcube-nsdate/nsstring.rb +16 -0
- data/lib/sugarcube-nsuserdefaults.rb +15 -0
- data/lib/{sugarcube → sugarcube-nsuserdefaults}/nsuserdefaults.rb +0 -0
- data/lib/sugarcube-numbers.rb +15 -0
- data/lib/sugarcube-numbers/fixnum.rb +25 -0
- data/lib/sugarcube-numbers/nsstring.rb +13 -0
- data/lib/{sugarcube → sugarcube-numbers}/numeric.rb +44 -4
- data/lib/sugarcube-osx/adjust.rb +373 -0
- data/lib/sugarcube-pipes.rb +15 -0
- data/lib/sugarcube-pipes/pipes.rb +78 -0
- data/lib/sugarcube-pointer.rb +15 -0
- data/lib/sugarcube-pointer/nsarray.rb +13 -0
- data/lib/sugarcube-repl.rb +1 -9
- data/lib/sugarcube-resources.rb +15 -0
- data/lib/sugarcube-timer.rb +15 -0
- data/lib/{sugarcube → sugarcube-timer}/timer.rb +0 -0
- data/lib/sugarcube-to_s.rb +15 -0
- data/lib/{sugarcube/to_s → sugarcube-to_s}/nserror.rb +1 -4
- data/lib/sugarcube-to_s/nsindexpath.rb +7 -0
- data/lib/{sugarcube/to_s → sugarcube-to_s}/nslayoutconstraint.rb +0 -0
- data/lib/{sugarcube/to_s → sugarcube-to_s}/nsnotification.rb +0 -0
- data/lib/{sugarcube/to_s → sugarcube-to_s}/nsset.rb +0 -0
- data/lib/{sugarcube/to_s → sugarcube-to_s}/nsurl.rb +0 -0
- data/lib/{sugarcube/to_s → sugarcube-to_s}/uicolor.rb +0 -0
- data/lib/{sugarcube/to_s → sugarcube-to_s}/uievent.rb +0 -0
- data/lib/{sugarcube/to_s → sugarcube-to_s}/uilabel.rb +0 -0
- data/lib/{sugarcube/to_s → sugarcube-to_s}/uitextfield.rb +0 -0
- data/lib/{sugarcube/to_s → sugarcube-to_s}/uitouch.rb +0 -0
- data/lib/{sugarcube/to_s → sugarcube-to_s}/uiview.rb +0 -0
- data/lib/{sugarcube/to_s → sugarcube-to_s}/uiviewcontroller.rb +0 -0
- data/lib/sugarcube-uicolor.rb +1 -0
- data/lib/sugarcube-uifont.rb +15 -0
- data/lib/sugarcube-uiimage.rb +1 -0
- data/lib/sugarcube-uikit.rb +15 -0
- data/lib/{sugarcube → sugarcube-uikit}/calayer.rb +0 -0
- data/lib/sugarcube-uikit/nsattributedstring.rb +12 -0
- data/lib/sugarcube-uikit/nsstring.rb +38 -0
- data/lib/sugarcube-uikit/symbol.rb +67 -0
- data/lib/{sugarcube → sugarcube-uikit}/uifont.rb +1 -4
- data/lib/sugarcube-uikit/uiimage.rb +9 -0
- data/lib/{sugarcube → sugarcube-uikit}/uilabel.rb +0 -0
- data/lib/{sugarcube → sugarcube-uikit}/uipickerview.rb +0 -0
- data/lib/sugarcube-uikit/uiview.rb +100 -0
- data/lib/{sugarcube → sugarcube-uikit}/uiviewcontroller.rb +0 -0
- data/lib/{sugarcube → sugarcube-uikit}/uiwebview.rb +0 -0
- data/lib/sugarcube-unholy.rb +1 -9
- data/lib/sugarcube.rb +4 -9
- data/lib/sugarcube/adjust.rb +1 -0
- data/lib/sugarcube/look_in.rb +22 -0
- data/lib/sugarcube/version.rb +1 -1
- data/runtests +1 -1
- data/spec/{uicolor_components_spec.rb → color_components_spec.rb} +0 -0
- data/spec/{uicolor_other_representations_spec.rb → color_other_representations_spec.rb} +0 -0
- data/spec/{uicolor_spec.rb → color_spec.rb} +0 -0
- data/spec/image_cifilters_spec.rb +549 -0
- data/spec/{uiimage_color_at_spec.rb → image_color_at_spec.rb} +0 -0
- data/spec/{uiimage_scale_spec.rb → image_scale_spec.rb} +0 -0
- data/spec/image_uiimage_filters_spec.rb +47 -0
- data/spec/nsdate_spec.rb +11 -0
- data/spec/nsurl_spec.rb +1 -1
- data/spec/numeric_spec.rb +10 -0
- data/spec/pipes_spec.rb +135 -0
- data/spec/sugarcube_legacy.rb +59 -0
- data/spec/symbol_constants_spec.rb +809 -0
- data/spec/symbol_uicolor_spec.rb +20 -4
- data/spec/symbol_uifont_spec.rb +30 -0
- data/spec/uiactionsheet_spec.rb +1 -1
- data/spec/uialertview_spec.rb +1 -1
- data/spec/uibarbuttonitem_spec.rb +46 -46
- data/sugarcube.gemspec +1 -1
- metadata +142 -74
- data/lib/sugarcube/exceptions.rb +0 -2
- data/lib/sugarcube/fixnum.rb +0 -59
- data/lib/sugarcube/nsstring.rb +0 -107
- data/lib/sugarcube/symbol.rb +0 -766
- data/lib/sugarcube/uiactivityindicator.rb +0 -17
- data/lib/sugarcube/uuid.rb +0 -10
- data/spec/activesupport_spec.rb +0 -96
- data/spec/symbol_spec.rb +0 -32
@@ -0,0 +1,15 @@
|
|
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 = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
|
11
|
+
|
12
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'sugarcube-localized/**/*.rb')).reverse.each do |file|
|
13
|
+
app.files.insert(insert_point, file)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class NSString
|
2
|
+
|
3
|
+
# This can be called as `"Hello".localized` or `"Hello"._`. The `str._`
|
4
|
+
# syntax is meant to be reminiscent of gettext-style `_(str)`.
|
5
|
+
def localized(value=nil, table=nil)
|
6
|
+
@localized = NSBundle.mainBundle.localizedStringForKey(self, value:value, table:table)
|
7
|
+
end
|
8
|
+
alias _ localized
|
9
|
+
|
10
|
+
end
|
@@ -0,0 +1,15 @@
|
|
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 = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
|
11
|
+
|
12
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'sugarcube-modal/**/*.rb')).reverse.each do |file|
|
13
|
+
app.files.insert(insert_point, file)
|
14
|
+
end
|
15
|
+
end
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
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 = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
|
11
|
+
|
12
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'sugarcube-notifications/**/*.rb')).reverse.each do |file|
|
13
|
+
app.files.insert(insert_point, file)
|
14
|
+
end
|
15
|
+
end
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
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 = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
|
11
|
+
|
12
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'sugarcube-nscoder/**/*.rb')).reverse.each do |file|
|
13
|
+
app.files.insert(insert_point, file)
|
14
|
+
end
|
15
|
+
end
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
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 = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
|
11
|
+
|
12
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'sugarcube-nsdata/**/*.rb')).reverse.each do |file|
|
13
|
+
app.files.insert(insert_point, file)
|
14
|
+
end
|
15
|
+
end
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
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 = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
|
11
|
+
|
12
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'sugarcube-nsdate/**/*.rb')).reverse.each do |file|
|
13
|
+
app.files.insert(insert_point, file)
|
14
|
+
end
|
15
|
+
end
|
File without changes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Fixnum
|
2
|
+
|
3
|
+
def nstimezone
|
4
|
+
NSTimeZone.timeZoneForSecondsFromGMT(self)
|
5
|
+
end
|
6
|
+
|
7
|
+
def before(date)
|
8
|
+
date - self
|
9
|
+
end
|
10
|
+
|
11
|
+
def ago
|
12
|
+
self.before(NSDate.new)
|
13
|
+
end
|
14
|
+
|
15
|
+
def after(date)
|
16
|
+
date + self
|
17
|
+
end
|
18
|
+
|
19
|
+
def hence
|
20
|
+
self.after(NSDate.new)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -17,6 +17,11 @@ class NSDate
|
|
17
17
|
return calendar.dateFromComponents(date_components)
|
18
18
|
end
|
19
19
|
|
20
|
+
# Time.now is defined, but not NSDate.now.
|
21
|
+
def self.now
|
22
|
+
NSDate.new
|
23
|
+
end
|
24
|
+
|
20
25
|
def self.today
|
21
26
|
NSDate.new.start_of_day
|
22
27
|
end
|
@@ -44,7 +49,7 @@ class NSDate
|
|
44
49
|
# See
|
45
50
|
# <https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html#//apple_ref/doc/uid/TP40002369-SW1>
|
46
51
|
# and
|
47
|
-
# <http://www.unicode.org/reports/tr35/tr35-19.html#
|
52
|
+
# <http://www.unicode.org/reports/tr35/tr35-19.html#Date_Field_Symbol_Table>
|
48
53
|
# for more information about date format strings.
|
49
54
|
def string_with_format(format)
|
50
55
|
if format.is_a?(Symbol)
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class NSString
|
2
|
+
|
3
|
+
def nstimezone
|
4
|
+
case self
|
5
|
+
when /([+-]?\d{4})/
|
6
|
+
sec = $1[-4,2].to_i * 3600
|
7
|
+
NSTimeZone.timeZoneForSecondsFromGMT(sec)
|
8
|
+
when /(GMT|UTC)([+-]\d{1,2})?/
|
9
|
+
sec = $2 ? $2.to_i * 3600 : 0
|
10
|
+
NSTimeZone.timeZoneForSecondsFromGMT(sec)
|
11
|
+
else
|
12
|
+
NSTimeZone.timeZoneWithName(self)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
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 = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
|
11
|
+
|
12
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'sugarcube-nsuserdefaults/**/*.rb')).reverse.each do |file|
|
13
|
+
app.files.insert(insert_point, file)
|
14
|
+
end
|
15
|
+
end
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
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 = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
|
11
|
+
|
12
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'sugarcube-numbers/**/*.rb')).reverse.each do |file|
|
13
|
+
app.files.insert(insert_point, file)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Fixnum
|
2
|
+
|
3
|
+
def nth
|
4
|
+
# if the first two digits of rank are between 11 and 20, it's an
|
5
|
+
# 'up-teenth' kinda number
|
6
|
+
modulo_100 = self % 100
|
7
|
+
if modulo_100 < 10 || modulo_100 > 20
|
8
|
+
case self % 10
|
9
|
+
when 1
|
10
|
+
return "st"
|
11
|
+
when 2
|
12
|
+
return "nd"
|
13
|
+
when 3
|
14
|
+
return "rd"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
return "th"
|
19
|
+
end
|
20
|
+
|
21
|
+
def ordinalize
|
22
|
+
return "#{self}#{nth}"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -1,9 +1,21 @@
|
|
1
1
|
class Numeric
|
2
2
|
|
3
|
+
##|
|
4
|
+
##| MISC
|
5
|
+
##|
|
6
|
+
|
3
7
|
def percent
|
4
8
|
self / 100.0
|
5
9
|
end
|
6
10
|
|
11
|
+
def g
|
12
|
+
self * 9.78033
|
13
|
+
end
|
14
|
+
|
15
|
+
def in_g
|
16
|
+
self / 9.78033
|
17
|
+
end
|
18
|
+
|
7
19
|
def radians
|
8
20
|
self
|
9
21
|
end
|
@@ -36,7 +48,7 @@ class Numeric
|
|
36
48
|
end
|
37
49
|
|
38
50
|
def kilometers
|
39
|
-
self * 1000.0
|
51
|
+
self * 1000.0 # 1000 m / km
|
40
52
|
end
|
41
53
|
alias kilometer kilometers
|
42
54
|
|
@@ -45,7 +57,7 @@ class Numeric
|
|
45
57
|
end
|
46
58
|
|
47
59
|
def miles
|
48
|
-
self * 1609.344
|
60
|
+
self * 1609.344 # 1609.344 m / mi
|
49
61
|
end
|
50
62
|
alias mile miles
|
51
63
|
|
@@ -54,7 +66,7 @@ class Numeric
|
|
54
66
|
end
|
55
67
|
|
56
68
|
def feet
|
57
|
-
self / 3.28084
|
69
|
+
self / 3.28084 # 3.28084 m / ft
|
58
70
|
end
|
59
71
|
alias foot feet
|
60
72
|
|
@@ -97,8 +109,36 @@ class Numeric
|
|
97
109
|
end
|
98
110
|
alias exabyte exabytes
|
99
111
|
|
112
|
+
def in_bytes
|
113
|
+
self
|
114
|
+
end
|
115
|
+
|
116
|
+
def in_kilobytes
|
117
|
+
self / 1024**1
|
118
|
+
end
|
119
|
+
|
120
|
+
def in_megabytes
|
121
|
+
self / 1024**2
|
122
|
+
end
|
123
|
+
|
124
|
+
def in_gigabytes
|
125
|
+
self / 1024**3
|
126
|
+
end
|
127
|
+
|
128
|
+
def in_terabytes
|
129
|
+
self / 1024**4
|
130
|
+
end
|
131
|
+
|
132
|
+
def in_petabytes
|
133
|
+
self / 1024**5
|
134
|
+
end
|
135
|
+
|
136
|
+
def in_exabytes
|
137
|
+
self / 1024**6
|
138
|
+
end
|
139
|
+
|
100
140
|
def string_with_style(style=NSNumberFormatterDecimalStyle)
|
101
|
-
if style.
|
141
|
+
if style.respond_to?(:nsnumberstyle)
|
102
142
|
style = style.nsnumberstyle
|
103
143
|
end
|
104
144
|
NSNumberFormatter.localizedStringFromNumber(self, numberStyle:style)
|
@@ -0,0 +1,373 @@
|
|
1
|
+
$sugarcube_view = nil
|
2
|
+
$sugarcube_items = nil
|
3
|
+
$sugarcube_restore = nil
|
4
|
+
|
5
|
+
module SugarCube
|
6
|
+
module Adjust
|
7
|
+
module_function
|
8
|
+
|
9
|
+
def repl_format(format=nil)
|
10
|
+
if format
|
11
|
+
@@repl_format = format
|
12
|
+
else
|
13
|
+
# if adjust has not been called, the instance variable has not yet been set
|
14
|
+
@@repl_format ||= :ruby
|
15
|
+
end
|
16
|
+
@@repl_format
|
17
|
+
end
|
18
|
+
|
19
|
+
def adjust(view=nil, format=nil)
|
20
|
+
SugarCube::Adjust::repl_format(format.to_sym) if format
|
21
|
+
return $sugarcube_view if not view
|
22
|
+
|
23
|
+
if view.is_a? Fixnum
|
24
|
+
window = NSApplication.sharedApplication.keyWindow
|
25
|
+
window ||= NSApplication.sharedApplication.mainWindow
|
26
|
+
window ||= NSApplication.sharedApplication.windows[0]
|
27
|
+
$sugarcube_items ||= SugarCube::Adjust::build_tree(window, :subviews)
|
28
|
+
view = $sugarcube_items[view]
|
29
|
+
end
|
30
|
+
|
31
|
+
# a/adjust will return this object
|
32
|
+
$sugarcube_view = view
|
33
|
+
|
34
|
+
if view.is_a?(NSView)
|
35
|
+
$sugarcube_restore = {
|
36
|
+
frame: SugarCube::Adjust.frame,
|
37
|
+
}
|
38
|
+
|
39
|
+
if format
|
40
|
+
puts format_frame view.frame
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
view
|
45
|
+
end
|
46
|
+
alias a adjust
|
47
|
+
|
48
|
+
##| FRAME
|
49
|
+
def frame f=nil
|
50
|
+
raise "no view has been assigned to SugarCube::Adjust::adjust" unless $sugarcube_view
|
51
|
+
|
52
|
+
return $sugarcube_view.frame if not f
|
53
|
+
|
54
|
+
f = SugarCube::CoreGraphics::Rect(f)
|
55
|
+
$sugarcube_view.frame = f
|
56
|
+
puts format_frame(f)
|
57
|
+
|
58
|
+
$sugarcube_view
|
59
|
+
end
|
60
|
+
alias f frame
|
61
|
+
|
62
|
+
##| ORIGIN
|
63
|
+
def left val=1
|
64
|
+
SugarCube::Adjust::right -val
|
65
|
+
end
|
66
|
+
alias l left
|
67
|
+
|
68
|
+
def right val=1
|
69
|
+
raise "no view has been assigned to SugarCube::Adjust::adjust" unless $sugarcube_view
|
70
|
+
|
71
|
+
f = $sugarcube_view.frame
|
72
|
+
f.origin.x += val
|
73
|
+
$sugarcube_view.frame = f
|
74
|
+
puts format_frame(f)
|
75
|
+
|
76
|
+
$sugarcube_view
|
77
|
+
end
|
78
|
+
alias r right
|
79
|
+
|
80
|
+
def up val=1
|
81
|
+
SugarCube::Adjust::down -val
|
82
|
+
end
|
83
|
+
alias u up
|
84
|
+
|
85
|
+
def down val=1
|
86
|
+
raise "no view has been assigned to SugarCube::Adjust::adjust" unless $sugarcube_view
|
87
|
+
|
88
|
+
f = $sugarcube_view.frame
|
89
|
+
f.origin.y += val
|
90
|
+
$sugarcube_view.frame = f
|
91
|
+
puts format_frame(f)
|
92
|
+
|
93
|
+
$sugarcube_view
|
94
|
+
end
|
95
|
+
alias d down
|
96
|
+
|
97
|
+
def origin x=nil, y=nil
|
98
|
+
raise "no view has been assigned to SugarCube::Adjust::adjust" unless $sugarcube_view
|
99
|
+
|
100
|
+
f = $sugarcube_view.frame
|
101
|
+
return f.origin if not x
|
102
|
+
|
103
|
+
if y
|
104
|
+
f.origin.x = x
|
105
|
+
f.origin.y = y
|
106
|
+
else
|
107
|
+
f.origin = SugarCube::CoreGraphics::Point(x)
|
108
|
+
end
|
109
|
+
$sugarcube_view.frame = f
|
110
|
+
puts format_frame(f)
|
111
|
+
|
112
|
+
$sugarcube_view
|
113
|
+
end
|
114
|
+
alias o origin
|
115
|
+
|
116
|
+
##| SIZE
|
117
|
+
def thinner val=1
|
118
|
+
SugarCube::Adjust::wider -val
|
119
|
+
end
|
120
|
+
alias n thinner
|
121
|
+
|
122
|
+
def wider val=1
|
123
|
+
raise "no view has been assigned to SugarCube::Adjust::adjust" unless $sugarcube_view
|
124
|
+
|
125
|
+
f = $sugarcube_view.frame
|
126
|
+
f.size.width += val
|
127
|
+
$sugarcube_view.frame = f
|
128
|
+
puts format_frame(f)
|
129
|
+
|
130
|
+
$sugarcube_view
|
131
|
+
end
|
132
|
+
alias w wider
|
133
|
+
|
134
|
+
def shorter val=1
|
135
|
+
SugarCube::Adjust::taller -val
|
136
|
+
end
|
137
|
+
alias s shorter
|
138
|
+
|
139
|
+
def taller val=1
|
140
|
+
raise "no view has been assigned to SugarCube::Adjust::adjust" unless $sugarcube_view
|
141
|
+
|
142
|
+
f = $sugarcube_view.frame
|
143
|
+
f.size.height += val
|
144
|
+
$sugarcube_view.frame = f
|
145
|
+
puts format_frame(f)
|
146
|
+
|
147
|
+
$sugarcube_view
|
148
|
+
end
|
149
|
+
alias t taller
|
150
|
+
|
151
|
+
def size w=nil, h=nil
|
152
|
+
raise "no view has been assigned to SugarCube::Adjust::adjust" unless $sugarcube_view
|
153
|
+
|
154
|
+
f = $sugarcube_view.frame
|
155
|
+
return f.size if not w
|
156
|
+
|
157
|
+
if h
|
158
|
+
f.size.width = w
|
159
|
+
f.size.height = h
|
160
|
+
else
|
161
|
+
f.size = SugarCube::CoreGraphics::Size(w)
|
162
|
+
end
|
163
|
+
$sugarcube_view.frame = f
|
164
|
+
puts format_frame(f)
|
165
|
+
|
166
|
+
$sugarcube_view
|
167
|
+
end
|
168
|
+
alias z size
|
169
|
+
|
170
|
+
def center(*args)
|
171
|
+
raise "no view has been assigned to SugarCube::Adjust::adjust" unless $sugarcube_view
|
172
|
+
|
173
|
+
element = nil
|
174
|
+
total = nil
|
175
|
+
direction = 'h'
|
176
|
+
args.each do |option|
|
177
|
+
case option
|
178
|
+
when String, Symbol # accept string or symbol
|
179
|
+
direction = option.to_s
|
180
|
+
when Numeric
|
181
|
+
if not total
|
182
|
+
total = option
|
183
|
+
elsif not element
|
184
|
+
element = option
|
185
|
+
else
|
186
|
+
raise "I don't know what to do with #{option.inspect}"
|
187
|
+
end
|
188
|
+
else
|
189
|
+
raise "I don't know what to do with #{option.inspect}"
|
190
|
+
end
|
191
|
+
end
|
192
|
+
element = 1 unless element
|
193
|
+
total = 1 unless total
|
194
|
+
|
195
|
+
view = $sugarcube_view
|
196
|
+
|
197
|
+
left = view.origin.x
|
198
|
+
top = view.origin.y
|
199
|
+
|
200
|
+
if /h|x/.match(direction.downcase)
|
201
|
+
swidth = view.frame.width
|
202
|
+
pwidth = view.superview.frame.width / total
|
203
|
+
left = (pwidth - swidth) / 2 + pwidth * (element - 1)
|
204
|
+
end
|
205
|
+
if /v|y/.match(direction.downcase)
|
206
|
+
sheight = view.frame.height
|
207
|
+
pheight = view.superview.frame.height / total
|
208
|
+
top = (pheight - sheight) / 2 + pheight * (element - 1)
|
209
|
+
end
|
210
|
+
|
211
|
+
self.origin left, top
|
212
|
+
end
|
213
|
+
alias c center
|
214
|
+
|
215
|
+
# @param item this can be a tree-like item (UIView, UIViewController,
|
216
|
+
# CALayer) or an integer, in which case it will select that window from
|
217
|
+
# UIApplication.sharedApplication.window. Defalt is to display the
|
218
|
+
# keyWindow
|
219
|
+
# @param selector If you pass an unsupported object to tree, you will need
|
220
|
+
# to pass a selector as well - this method should return an array of
|
221
|
+
# items which are passed recursively to tree
|
222
|
+
# @block sel_blk If a block is passed, it will be used to build the array of
|
223
|
+
# items that are called recursively
|
224
|
+
def tree(item=nil, selector=nil, &sel_blk)
|
225
|
+
if item.is_a?(Fixnum)
|
226
|
+
item = NSApplication.sharedApplication.windows[item]
|
227
|
+
elsif ! item
|
228
|
+
item = NSApplication.sharedApplication.keyWindow || NSApplication.sharedApplication.mainWindow || NSApplication.sharedApplication.windows[0]
|
229
|
+
end
|
230
|
+
unless item
|
231
|
+
puts 'View is nil (no window, view, or controller to display)'
|
232
|
+
return
|
233
|
+
end
|
234
|
+
|
235
|
+
if sel_blk
|
236
|
+
if selector
|
237
|
+
raise "You can't hand me a block AND a selector. I don't know what to do with them!"
|
238
|
+
end
|
239
|
+
if sel_blk.arity != 1
|
240
|
+
raise "The block you passed should accept one and only one object"
|
241
|
+
end
|
242
|
+
selector = sel_blk
|
243
|
+
elsif ! selector
|
244
|
+
if item.is_a? NSView
|
245
|
+
selector = :subviews
|
246
|
+
elsif item.is_a? NSWindow
|
247
|
+
item = item.contentView
|
248
|
+
selector = :subviews
|
249
|
+
elsif item.is_a? NSViewController
|
250
|
+
selector = lambda { |ctlr|
|
251
|
+
ret = Array.new ctlr.childViewControllers
|
252
|
+
if ctlr.presentedViewController && ctlr.presentedViewController.presentingViewController == ctlr
|
253
|
+
ret << ctlr.presentedViewController
|
254
|
+
end
|
255
|
+
ret
|
256
|
+
}
|
257
|
+
elsif item.is_a? CALayer
|
258
|
+
selector = :sublayers
|
259
|
+
else
|
260
|
+
raise "Unable to determine a SugarCube::Adjust::tree selector for #{item.class.name}"
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
$sugarcube_items = SugarCube::Adjust::build_tree(item, selector)
|
265
|
+
if self.respond_to? :draw_tree
|
266
|
+
draw_tree(item, selector)
|
267
|
+
else
|
268
|
+
SugarCube::Adjust::draw_tree(item, selector)
|
269
|
+
end
|
270
|
+
puts ''
|
271
|
+
|
272
|
+
return item
|
273
|
+
end
|
274
|
+
|
275
|
+
# Draws the tree items
|
276
|
+
def draw_tree(item, selector, tab=nil, is_last=true, items_index=0)
|
277
|
+
space = ' '
|
278
|
+
if items_index < 10
|
279
|
+
print ' '
|
280
|
+
elsif items_index < 100
|
281
|
+
print ' '
|
282
|
+
elsif items_index > 999 # good god, man!
|
283
|
+
space = ''
|
284
|
+
end
|
285
|
+
print items_index.to_s + ":" + space
|
286
|
+
|
287
|
+
if tab
|
288
|
+
print tab
|
289
|
+
if is_last
|
290
|
+
print '`-- '
|
291
|
+
tab += ' '
|
292
|
+
else
|
293
|
+
print '+-- '
|
294
|
+
tab += '| '
|
295
|
+
end
|
296
|
+
else
|
297
|
+
print '. '
|
298
|
+
tab = ''
|
299
|
+
end
|
300
|
+
|
301
|
+
if self == item || $sugarcube_view == item
|
302
|
+
print "\033[1m"
|
303
|
+
end
|
304
|
+
if item.is_a? NSView
|
305
|
+
puts "#{item} frame: [[#{item.frame.origin.x}, #{item.frame.origin.y}], [#{item.frame.size.width}, #{item.frame.size.height}]]"
|
306
|
+
else
|
307
|
+
puts item.to_s
|
308
|
+
end
|
309
|
+
if self == item || $sugarcube_view == item
|
310
|
+
print "\033[0m"
|
311
|
+
end
|
312
|
+
|
313
|
+
if selector.is_a? Proc
|
314
|
+
items = selector.call(item)
|
315
|
+
else
|
316
|
+
items = item.send(selector)
|
317
|
+
end
|
318
|
+
items ||= []
|
319
|
+
|
320
|
+
items.each_with_index { |subview, index|
|
321
|
+
items_index += 1
|
322
|
+
if self.respond_to? :draw_tree
|
323
|
+
items_index = draw_tree(subview, selector, tab, index == items.length - 1, items_index)
|
324
|
+
else
|
325
|
+
items_index = SugarCube::Adjust::draw_tree(subview, selector, tab, index == items.length - 1, items_index)
|
326
|
+
end
|
327
|
+
}
|
328
|
+
|
329
|
+
return items_index
|
330
|
+
end
|
331
|
+
|
332
|
+
def build_tree(item, selector)
|
333
|
+
if selector.is_a? Proc
|
334
|
+
items = selector.call(item)
|
335
|
+
else
|
336
|
+
items = item.send(selector)
|
337
|
+
end
|
338
|
+
items ||= []
|
339
|
+
|
340
|
+
ret = [item]
|
341
|
+
items.each_with_index { |subview, index|
|
342
|
+
ret.concat SugarCube::Adjust::build_tree(subview, selector)
|
343
|
+
}
|
344
|
+
ret
|
345
|
+
end
|
346
|
+
|
347
|
+
def root
|
348
|
+
(NSApplication.sharedApplication.keyWindow || NSApplication.sharedApplication.windows[0]).windowController
|
349
|
+
end
|
350
|
+
|
351
|
+
##| RESTORE
|
352
|
+
def restore
|
353
|
+
raise 'no view has been assigned to SugarCube::Adjust::adjust' unless $sugarcube_view
|
354
|
+
|
355
|
+
$sugarcube_restore.each do |msg, value|
|
356
|
+
SugarCube::Adjust.send(msg, value)
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
def format_frame(frame)
|
361
|
+
case SugarCube::Adjust::repl_format
|
362
|
+
when :json then
|
363
|
+
"{x: #{frame.origin.x}, y: #{frame.origin.y}, width: #{frame.size.width}, height: #{frame.size.height}}"
|
364
|
+
when :ruby then
|
365
|
+
"[[#{frame.origin.x}, #{frame.origin.y}], [#{frame.size.width}, #{frame.size.height}]]"
|
366
|
+
when :objc
|
367
|
+
frame.to_s
|
368
|
+
else
|
369
|
+
raise "Unknown repl_format #{SugarCube::Adjust::repl_format.inspect}"
|
370
|
+
end
|
371
|
+
end
|
372
|
+
end
|
373
|
+
end
|