sugarcube 2.12.3 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/lib/all/sugarcube-repl/repl.rb +191 -0
  4. data/lib/all/sugarcube/log.rb +2 -2
  5. data/lib/android/sugarcube-repl/repl.rb +42 -0
  6. data/lib/android/sugarcube/log.rb +8 -0
  7. data/lib/cocoa/sugarcube-repl/repl.rb +48 -214
  8. data/lib/cocoa/sugarcube/log.rb +1 -1
  9. data/lib/ios/sugarcube-568/uiimage.rb +3 -0
  10. data/lib/ios/sugarcube-repl/repl.rb +27 -30
  11. data/lib/osx/sugarcube-repl/repl.rb +14 -25
  12. data/lib/sugarcube-568.rb +2 -9
  13. data/lib/sugarcube-animations.rb +2 -12
  14. data/lib/sugarcube-anonymous.rb +2 -9
  15. data/lib/sugarcube-appkit.rb +3 -12
  16. data/lib/sugarcube-attributedstring.rb +3 -12
  17. data/lib/sugarcube-awesome.rb +2 -9
  18. data/lib/sugarcube-color.rb +2 -9
  19. data/lib/sugarcube-constants.rb +2 -9
  20. data/lib/sugarcube-coregraphics.rb +3 -9
  21. data/lib/sugarcube-corelocation.rb +6 -9
  22. data/lib/sugarcube-events.rb +2 -9
  23. data/lib/sugarcube-factories.rb +2 -9
  24. data/lib/sugarcube-files.rb +2 -9
  25. data/lib/sugarcube-foundation.rb +3 -9
  26. data/lib/sugarcube-gestures.rb +2 -9
  27. data/lib/sugarcube-image.rb +2 -9
  28. data/lib/sugarcube-indexpath.rb +2 -9
  29. data/lib/sugarcube-legacy.rb +2 -18
  30. data/lib/sugarcube-localized.rb +2 -9
  31. data/lib/sugarcube-modal.rb +2 -9
  32. data/lib/sugarcube-notifications.rb +2 -9
  33. data/lib/sugarcube-nscoder.rb +3 -9
  34. data/lib/sugarcube-nsdata.rb +3 -12
  35. data/lib/sugarcube-nsdate.rb +3 -14
  36. data/lib/sugarcube-nsuserdefaults.rb +3 -9
  37. data/lib/sugarcube-numbers.rb +2 -15
  38. data/lib/sugarcube-pipes.rb +2 -9
  39. data/lib/sugarcube-pointer.rb +2 -9
  40. data/lib/sugarcube-repl.rb +2 -16
  41. data/lib/sugarcube-spritekit.rb +6 -12
  42. data/lib/sugarcube-timer.rb +2 -14
  43. data/lib/sugarcube-to_s.rb +2 -15
  44. data/lib/sugarcube-uikit.rb +3 -12
  45. data/lib/sugarcube-unholy.rb +2 -9
  46. data/lib/sugarcube.rb +33 -19
  47. data/lib/sugarcube_pre_setup.rb +44 -0
  48. data/lib/version.rb +1 -1
  49. data/spec/cocoa/nsindexpath_spec.rb +12 -0
  50. metadata +9 -6
  51. data/lib/ios/sugarcube/sugarcube_cleanup.rb +0 -16
@@ -2,7 +2,7 @@ module SugarCube
2
2
  module_function
3
3
 
4
4
  def stderr(message)
5
- NSLog(message)
5
+ NSLog("%@", message)
6
6
  end
7
7
 
8
8
  end
@@ -3,6 +3,7 @@ class UIImage
3
3
  SugarCube568_TallSuffix = '-568h@2x' # 320 x 568
4
4
  SugarCube667_TallSuffix = '-667h@2x' # 375 x 667
5
5
  SugarCube736_TallSuffix = '-736h@2x' # 414 x 736
6
+ SugarCube1024_TallSuffix = '-1024h@2x' # 768 x 1024
6
7
 
7
8
  def sugarcube568_imageNamed(name)
8
9
  case UIScreen.mainScreen.bounds.size.height
@@ -12,6 +13,8 @@ class UIImage
12
13
  taller_image_ext = SugarCube667_TallSuffix
13
14
  when 736
14
15
  taller_image_ext = SugarCube736_TallSuffix
16
+ when 1024
17
+ taller_image_ext = SugarCube1024_TallSuffix
15
18
  else
16
19
  taller_image_ext = false
17
20
  end
@@ -1,12 +1,14 @@
1
1
  module SugarCube
2
- module Repl
3
- module_function
2
+ class << Repl
4
3
 
5
4
  def window(index=nil)
6
5
  if index
7
6
  UIApplication.sharedApplication.windows[index]
8
7
  else
9
- UIApplication.sharedApplication.keyWindow
8
+ (
9
+ UIApplication.sharedApplication.keyWindow ||
10
+ UIApplication.sharedApplication.windows[0]
11
+ )
10
12
  end
11
13
  end
12
14
 
@@ -16,7 +18,7 @@ module SugarCube
16
18
 
17
19
  def adjust_init(view)
18
20
  if view.is_a?(UIView)
19
- @sugarcube_restore = {
21
+ @restore = {
20
22
  frame: SugarCube::Repl.frame,
21
23
  shadow: SugarCube::Repl.shadow,
22
24
  }
@@ -39,19 +41,19 @@ module SugarCube
39
41
  if key == :color and [Symbol, Fixnum, NSString, UIImage, UIColor].any?{|klass| value.is_a? klass}
40
42
  value = value.uicolor.CGColor
41
43
  end
42
- @sugarcube_view.layer.send(msg, value)
43
- @sugarcube_view.layer.masksToBounds = false
44
- @sugarcube_view.layer.shouldRasterize = true
44
+ @adjust_item.layer.send(msg, value)
45
+ @adjust_item.layer.masksToBounds = false
46
+ @adjust_item.layer.shouldRasterize = true
45
47
  end
46
48
  }
47
- @sugarcube_view
49
+ @adjust_item
48
50
  else
49
51
  {
50
- opacity: @sugarcube_view.layer.shadowOpacity,
51
- radius: @sugarcube_view.layer.shadowRadius,
52
- offset: @sugarcube_view.layer.shadowOffset,
53
- color: @sugarcube_view.layer.shadowColor,
54
- path: @sugarcube_view.layer.shadowPath,
52
+ opacity: @adjust_item.layer.shadowOpacity,
53
+ radius: @adjust_item.layer.shadowRadius,
54
+ offset: @adjust_item.layer.shadowOffset,
55
+ color: @adjust_item.layer.shadowColor,
56
+ path: @adjust_item.layer.shadowPath,
55
57
  }
56
58
  end
57
59
  end
@@ -60,15 +62,15 @@ module SugarCube
60
62
  def blink(color=nil)
61
63
  return unless check_sugarcube_view
62
64
 
63
- blinking_view = UIView.alloc.initWithFrame([[0,0], @sugarcube_view.frame.size])
65
+ blinking_view = UIView.alloc.initWithFrame([[0,0], @adjust_item.frame.size])
64
66
  color = color.uicolor if color.respond_to?(:uicolor)
65
67
  blinking_view.backgroundColor = color
66
68
  blinking_view.alpha = 0
67
- if @sugarcube_view.window
68
- blinking_view.frame = @sugarcube_view.convertRect([[0, 0], @sugarcube_view.frame.size], toView: @sugarcube_view.window)
69
- @sugarcube_view.window.addSubview(blinking_view)
69
+ if @adjust_item.window
70
+ blinking_view.frame = @adjust_item.convertRect([[0, 0], @adjust_item.frame.size], toView: @adjust_item.window)
71
+ @adjust_item.window.addSubview(blinking_view)
70
72
  else
71
- @sugarcube_view.addSubview(blinking_view)
73
+ @adjust_item.addSubview(blinking_view)
72
74
  end
73
75
 
74
76
  duration = 0.2
@@ -83,19 +85,14 @@ module SugarCube
83
85
  end)
84
86
  end
85
87
 
86
- def get_tree_selector(item)
87
- if item.is_a? UIView
88
- return :subviews
89
- elsif item.is_a? UIViewController
90
- return -> (ctlr) do
91
- ret = Array.new ctlr.childViewControllers
92
- if ctlr.presentedViewController && ctlr.presentedViewController.presentingViewController == ctlr
93
- ret << ctlr.presentedViewController
94
- end
95
- ret
88
+ def register_platform_tree_selectors
89
+ register_tree_selector(UIView, :subviews)
90
+ register_tree_selector(UIViewController) do |ctlr|
91
+ ret = Array.new ctlr.childViewControllers
92
+ if ctlr.presentedViewController && ctlr.presentedViewController.presentingViewController == ctlr
93
+ ret << ctlr.presentedViewController
96
94
  end
97
- else
98
- nil
95
+ ret
99
96
  end
100
97
  end
101
98
 
@@ -1,6 +1,5 @@
1
1
  module SugarCube
2
- module Repl
3
- module_function
2
+ class << Repl
4
3
 
5
4
  def window(index=nil)
6
5
  if index
@@ -20,7 +19,7 @@ module SugarCube
20
19
 
21
20
  def adjust_init(view)
22
21
  if view.is_a?(NSView)
23
- @sugarcube_restore = {
22
+ @restore = {
24
23
  frame: SugarCube::Repl.frame,
25
24
  }
26
25
  end
@@ -29,15 +28,15 @@ module SugarCube
29
28
  def blink(color=nil)
30
29
  return unless check_sugarcube_view
31
30
 
32
- blinking_view = NSView.alloc.initWithFrame([[0,0], @sugarcube_view.frame.size])
31
+ blinking_view = NSView.alloc.initWithFrame([[0,0], @adjust_item.frame.size])
33
32
  color = color.nscolor if color.respond_to?(:nscolor)
34
33
  blinking_view.backgroundColor = color
35
34
  blinking_view.alpha = 0
36
- if @sugarcube_view.window
37
- blinking_view.frame = @sugarcube_view.convertRect([[0, 0], @sugarcube_view.frame.size], toView: @sugarcube_view.window)
38
- @sugarcube_view.window.addSubview(blinking_view)
35
+ if @adjust_item.window
36
+ blinking_view.frame = @adjust_item.convertRect([[0, 0], @adjust_item.frame.size], toView: @adjust_item.window)
37
+ @adjust_item.window.addSubview(blinking_view)
39
38
  else
40
- @sugarcube_view.addSubview(blinking_view)
39
+ @adjust_item.addSubview(blinking_view)
41
40
  end
42
41
 
43
42
  duration = 0.2
@@ -64,23 +63,13 @@ module SugarCube
64
63
  end)
65
64
  end
66
65
 
67
- def get_tree_selector(item)
68
- if item.is_a? NSView
69
- return :subviews
70
- elsif item.is_a? NSWindow
71
- item = item.contentView
72
- return :subviews
73
- elsif item.is_a? NSWindowController
74
- return -> (ctlr) { [ctlr.window] }
75
- elsif item.is_a? NSViewController
76
- return -> (ctlr) { [ctlr.view] }
77
- elsif item.is_a? NSMenu
78
- return :itemArray
79
- elsif item.is_a? NSMenuItem
80
- return -> (menu_item) { [menu_item.menu] }
81
- else
82
- nil
83
- end
66
+ def register_platform_tree_selectors
67
+ register_tree_selector(NSView, :subviews)
68
+ register_tree_selector(NSWindow) { |window| window.contentView.subviews }
69
+ register_tree_selector(NSWindowController) { |ctlr| [ctlr.window] }
70
+ register_tree_selector(NSViewController) { |ctlr| [ctlr.view] }
71
+ register_tree_selector(NSMenu, :itemArray)
72
+ register_tree_selector(NSMenuItem) { |menu_item| [menu_item.menu] }
84
73
  end
85
74
 
86
75
  def draw_tree_item(item)
data/lib/sugarcube-568.rb CHANGED
@@ -6,13 +6,6 @@ end
6
6
  require 'sugarcube'
7
7
  SugarCube.ios_only!('568')
8
8
 
9
- Motion::Project::App.setup do |app|
10
- # scans app.files until it finds app/ (the default)
11
- # if found, it inserts just before those files, otherwise it will insert to
12
- # the end of the list
13
- insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
14
-
15
- Dir.glob(File.join(File.dirname(__FILE__), 'ios/sugarcube-568/**/*.rb')).reverse.each do |file|
16
- app.files.insert(insert_point, file)
17
- end
9
+ Motion::Project::App.pre_setup do |app|
10
+ SugarCube.add_app_files(app, 'sugarcube-568')
18
11
  end
@@ -5,16 +5,6 @@ end
5
5
 
6
6
  require 'sugarcube'
7
7
 
8
- Motion::Project::App.setup do |app|
9
- # scans app.files until it finds app/ (the default)
10
- # if found, it inserts just before those files, otherwise it will insert to
11
- # the end of the list
12
- insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
13
-
14
- Dir.glob(File.join(File.dirname(__FILE__), SugarCube.platform, 'sugarcube-animations/**/*.rb')).reverse.each do |file|
15
- app.files.insert(insert_point, file)
16
- end
17
- Dir.glob(File.join(File.dirname(__FILE__), 'cocoa/sugarcube-animations/**/*.rb')).reverse.each do |file|
18
- app.files.insert(insert_point, file)
19
- end
8
+ Motion::Project::App.pre_setup do |app|
9
+ SugarCube.add_app_files(app, 'sugarcube-animations')
20
10
  end
@@ -5,13 +5,6 @@ end
5
5
 
6
6
  require 'sugarcube'
7
7
 
8
- Motion::Project::App.setup do |app|
9
- # scans app.files until it finds app/ (the default)
10
- # if found, it inserts just before those files, otherwise it will insert to
11
- # the end of the list
12
- insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
13
-
14
- Dir.glob(File.join(File.dirname(__FILE__), 'cocoa/sugarcube-anonymous/**/*.rb')).reverse.each do |file|
15
- app.files.insert(insert_point, file)
16
- end
8
+ Motion::Project::App.pre_setup do |app|
9
+ SugarCube.add_app_files(app, 'sugarcube-anonymous')
17
10
  end
@@ -6,16 +6,7 @@ end
6
6
  require 'sugarcube'
7
7
  SugarCube.osx_only!('appkit')
8
8
 
9
- Motion::Project::App.setup do |app|
10
- # scans app.files until it finds app/ (the default)
11
- # if found, it inserts just before those files, otherwise it will insert to
12
- # the end of the list
13
- insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
14
-
15
- Dir.glob(File.join(File.dirname(__FILE__), 'osx/sugarcube-appkit/**/*.rb')).reverse.each do |file|
16
- app.files.insert(insert_point, file)
17
- end
18
- Dir.glob(File.join(File.dirname(__FILE__), 'cocoa/sugarcube-cocoakit/**/*.rb')).reverse.each do |file|
19
- app.files.insert(insert_point, file)
20
- end
9
+ Motion::Project::App.pre_setup do |app|
10
+ SugarCube.add_app_files(app, 'sugarcube-cocoakit')
11
+ SugarCube.add_app_files(app, 'sugarcube-appkit')
21
12
  end
@@ -4,17 +4,8 @@ end
4
4
 
5
5
 
6
6
  require 'sugarcube'
7
+ SugarCube.cocoa_only!('attributedstring')
7
8
 
8
- Motion::Project::App.setup do |app|
9
- # scans app.files until it finds app/ (the default)
10
- # if found, it inserts just before those files, otherwise it will insert to
11
- # the end of the list
12
- insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
13
-
14
- Dir.glob(File.join(File.dirname(__FILE__), SugarCube.platform, 'sugarcube-attributedstring/**/*.rb')).reverse.each do |file|
15
- app.files.insert(insert_point, file)
16
- end
17
- Dir.glob(File.join(File.dirname(__FILE__), 'cocoa/sugarcube-attributedstring/**/*.rb')).reverse.each do |file|
18
- app.files.insert(insert_point, file)
19
- end
9
+ Motion::Project::App.pre_setup do |app|
10
+ SugarCube.add_app_files(app, 'sugarcube-attributedstring')
20
11
  end
@@ -5,13 +5,6 @@ end
5
5
 
6
6
  require 'sugarcube'
7
7
 
8
- Motion::Project::App.setup do |app|
9
- # scans app.files until it finds app/ (the default)
10
- # if found, it inserts just before those files, otherwise it will insert to
11
- # the end of the list
12
- insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
13
-
14
- Dir.glob(File.join(File.dirname(__FILE__), 'cocoa/sugarcube-awesome/**/*.rb')).reverse.each do |file|
15
- app.files.insert(insert_point, file)
16
- end
8
+ Motion::Project::App.pre_setup do |app|
9
+ SugarCube.add_app_files(app, 'sugarcube-awesome')
17
10
  end
@@ -5,13 +5,6 @@ end
5
5
 
6
6
  require 'sugarcube'
7
7
 
8
- Motion::Project::App.setup do |app|
9
- # scans app.files until it finds app/ (the default)
10
- # if found, it inserts just before those files, otherwise it will insert to
11
- # the end of the list
12
- insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
13
-
14
- Dir.glob(File.join(File.dirname(__FILE__), SugarCube.platform, 'sugarcube-color/**/*.rb')).reverse.each do |file|
15
- app.files.insert(insert_point, file)
16
- end
8
+ Motion::Project::App.pre_setup do |app|
9
+ SugarCube.add_app_files(app, 'sugarcube-color')
17
10
  end
@@ -5,13 +5,6 @@ end
5
5
 
6
6
  require 'sugarcube'
7
7
 
8
- Motion::Project::App.setup do |app|
9
- # scans app.files until it finds app/ (the default)
10
- # if found, it inserts just before those files, otherwise it will insert to
11
- # the end of the list
12
- insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
13
-
14
- Dir.glob(File.join(File.dirname(__FILE__), SugarCube.platform, 'sugarcube-constants/**/*.rb')).reverse.each do |file|
15
- app.files.insert(insert_point, file)
16
- end
8
+ Motion::Project::App.pre_setup do |app|
9
+ SugarCube.add_app_files(app, 'sugarcube-constants')
17
10
  end
@@ -4,14 +4,8 @@ end
4
4
 
5
5
 
6
6
  require 'sugarcube'
7
+ SugarCube.cocoa_only!('coregraphics')
7
8
 
8
- Motion::Project::App.setup do |app|
9
- # scans app.files until it finds app/ (the default)
10
- # if found, it inserts just before those files, otherwise it will insert to
11
- # the end of the list
12
- insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
13
-
14
- Dir.glob(File.join(File.dirname(__FILE__), SugarCube.platform, 'sugarcube-coregraphics/**/*.rb')).reverse.each do |file|
15
- app.files.insert(insert_point, file)
16
- end
9
+ Motion::Project::App.pre_setup do |app|
10
+ SugarCube.add_app_files(app, 'sugarcube-coregraphics')
17
11
  end
@@ -4,16 +4,13 @@ end
4
4
 
5
5
 
6
6
  require 'sugarcube'
7
+ SugarCube.cocoa_only!('corelocation')
7
8
 
8
- Motion::Project::App.setup do |app|
9
- # scans app.files until it finds app/ (the default)
10
- # if found, it inserts just before those files, otherwise it will insert to
11
- # the end of the list
12
- insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
9
+ Motion::Project::App.pre_setup do |app|
10
+ SugarCube.add_app_files(app, 'sugarcube-corelocation')
11
+ end
13
12
 
14
- Dir.glob(File.join(File.dirname(__FILE__), 'cocoa/sugarcube-corelocation/**/*.rb')).reverse.each do |file|
15
- app.files.insert(insert_point, file)
16
- end
17
13
 
18
- app.frameworks << 'CoreLocation'
14
+ Motion::Project::App.post_setup do |app|
15
+ app.frameworks += %w{CoreLocation}
19
16
  end
@@ -5,13 +5,6 @@ end
5
5
 
6
6
  require 'sugarcube'
7
7
 
8
- Motion::Project::App.setup do |app|
9
- # scans app.files until it finds app/ (the default)
10
- # if found, it inserts just before those files, otherwise it will insert to
11
- # the end of the list
12
- insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
13
-
14
- Dir.glob(File.join(File.dirname(__FILE__), SugarCube.platform, 'sugarcube-events/**/*.rb')).reverse.each do |file|
15
- app.files.insert(insert_point, file)
16
- end
8
+ Motion::Project::App.pre_setup do |app|
9
+ SugarCube.add_app_files(app, 'sugarcube-events')
17
10
  end
@@ -5,13 +5,6 @@ end
5
5
 
6
6
  require 'sugarcube'
7
7
 
8
- Motion::Project::App.setup do |app|
9
- # scans app.files until it finds app/ (the default)
10
- # if found, it inserts just before those files, otherwise it will insert to
11
- # the end of the list
12
- insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
13
-
14
- Dir.glob(File.join(File.dirname(__FILE__), SugarCube.platform, 'sugarcube-factories/**/*.rb')).reverse.each do |file|
15
- app.files.insert(insert_point, file)
16
- end
8
+ Motion::Project::App.pre_setup do |app|
9
+ SugarCube.add_app_files(app, 'sugarcube-factories')
17
10
  end
@@ -5,13 +5,6 @@ end
5
5
 
6
6
  require 'sugarcube'
7
7
 
8
- Motion::Project::App.setup do |app|
9
- # scans app.files until it finds app/ (the default)
10
- # if found, it inserts just before those files, otherwise it will insert to
11
- # the end of the list
12
- insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
13
-
14
- Dir.glob(File.join(File.dirname(__FILE__), 'cocoa/sugarcube-files/**/*.rb')).reverse.each do |file|
15
- app.files.insert(insert_point, file)
16
- end
8
+ Motion::Project::App.pre_setup do |app|
9
+ SugarCube.add_app_files(app, 'sugarcube-files')
17
10
  end
@@ -4,14 +4,8 @@ end
4
4
 
5
5
 
6
6
  require 'sugarcube'
7
+ SugarCube.cocoa_only!('foundation')
7
8
 
8
- Motion::Project::App.setup do |app|
9
- # scans app.files until it finds app/ (the default)
10
- # if found, it inserts just before those files, otherwise it will insert to
11
- # the end of the list
12
- insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
13
-
14
- Dir.glob(File.join(File.dirname(__FILE__), 'cocoa/sugarcube-foundation/**/*.rb')).reverse.each do |file|
15
- app.files.insert(insert_point, file)
16
- end
9
+ Motion::Project::App.pre_setup do |app|
10
+ SugarCube.add_app_files(app, 'sugarcube-foundation')
17
11
  end