sugarcube 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -17,7 +17,7 @@ view << subview.
17
17
 
18
18
  The basic idea of sugarcube is to turn some operations on their head. Insead of
19
19
 
20
- NSUIApplication.sharedApplication.openURL(NSUrl.URLWithString(url))
20
+ UIApplication.sharedApplication.openURL(NSUrl.URLWithString(url))
21
21
 
22
22
  How about:
23
23
 
@@ -209,14 +209,15 @@ test[:my] = 'new'
209
209
  ###### Is it `CGMakeRect` or `CGRectMake`?
210
210
 
211
211
  Instead, just use `Rect`, `Size` and `Point`. These are namespaced in
212
- `SugarCube` module, but I recommend you `include SugarCube` in app_delegate.rb.
212
+ `SugarCube::CoreGraphics` module, but I recommend you `include
213
+ SugarCube::CoreGraphics` in app_delegate.rb.
213
214
 
214
215
  ```ruby
215
- f = SugarCube::Rect(view.frame) # converts a CGRect into a CGRectArray
216
- o = SugarCube::Point(view.frame.origin) # converts a CGPoint into a CGPointArray
217
- s = SugarCube::Size(view.frame.size) # converts a CGSize into a CGSizeArray
216
+ f = Rect(view.frame) # converts a CGRect into a CGRectArray
217
+ o = Point(view.frame.origin) # converts a CGPoint into a CGPointArray
218
+ s = Size(view.frame.size) # converts a CGSize into a CGSizeArray
218
219
 
219
- # lots of other conversions are possible. Let's assume `include SugarCube`, too
220
+ # lots of other conversions are possible.
220
221
  # 4 numbers
221
222
  f = Rect(x, y, w, h)
222
223
  # or two arrays
@@ -234,11 +235,11 @@ jQuery-like animation methods.
234
235
 
235
236
  ```ruby
236
237
  # default timeout is 0.3
237
- view.fadeout { |view|
238
+ view.fade_out { |view|
238
239
  view.removeFromSuperview
239
240
  }
240
241
  # options:
241
- view.fadeout(0.5, delay: 0,
242
+ view.fade_out(0.5, delay: 0,
242
243
  options: UIViewAnimationOptionCurveLinear,
243
244
  opacity: 0.5) { |view|
244
245
  view.removeFromSuperview
@@ -253,28 +254,30 @@ view.delta_to([0, 100]) # move over 0, down 100, from current position
253
254
  Pixel pushing is an unfortunate but necessary evil. Well, at least we can make
254
255
  it a little less painful.
255
256
 
256
- These methods help you adjust the frame of a view. They are in the `SugarCube`
257
- module so as not to conflict. If you don't want the prefix, `include SugarCube` in
258
- app_delegate.rb
257
+ These methods help you adjust the frame of a view. They are in the
258
+ `SugarCube::Adjust` module so as not to conflict. If you don't want the prefix,
259
+ `include SugarCube::Adjust` in app_delegate.rb
260
+
261
+ Assume I ran `include SugarCube::Adjust` in these examples.
259
262
 
260
263
  ```ruby
261
264
  # if you are in the REPL, you might not be able to click on the view you want...
262
- > SugarCube::adjust superview.subviews[4].subviews[1]
263
- > SugarCube::up 1
264
- > SugarCube::down 1 # same as up -1, obviously
265
- > SugarCube::left 1
266
- > SugarCube::right 1 # same as up -1, obviously
267
- > SugarCube::origin 10, 12 # move to x:10, y:12
268
- > SugarCube::wider 1
269
- > SugarCube::thinner 1
270
- > SugarCube::taller 1
271
- > SugarCube::shorter 1
272
- > SugarCube::size 100, 10 # set size to width:100, height: 10
273
- > SugarCube::restore
265
+ > adjust superview.subviews[4].subviews[1]
266
+ > up 1
267
+ > down 1 # same as up -1, obviously
268
+ > left 1
269
+ > right 1 # same as up -1, obviously
270
+ > origin 10, 12 # move to x:10, y:12
271
+ > wider 1
272
+ > thinner 1
273
+ > taller 1
274
+ > shorter 1
275
+ > size 100, 10 # set size to width:100, height: 10
276
+ > restore # original frame is saved when you call adjust
274
277
  ```
275
278
 
276
279
  ```ruby
277
- > # short versions! and let's assume I ran `include SC`
280
+ > # short versions!
278
281
  > a superview.subviews[4].subviews[1] # this is not uncommon in the REPL
279
282
  > u # up, default value=1
280
283
  > d # down
@@ -1,93 +1,95 @@
1
1
  module SugarCube
2
- module_function
2
+ module Adjust
3
+ module_function
3
4
 
4
- def adjust view=nil
5
- return @@sugarcube_view if not view
5
+ def adjust view=nil
6
+ return @@sugarcube_view if not view
6
7
 
7
- @@sugarcube_view = view
8
- @@sugarcube_restore = view.frame
9
- view
10
- end
11
- alias :a :adjust
8
+ @@sugarcube_view = view
9
+ @@sugarcube_restore = view.frame
10
+ view
11
+ end
12
+ alias :a :adjust
12
13
 
13
- ##| ORIGIN
14
- def left val=1
15
- SugarCube::right -val
16
- end
17
- alias :l :left
14
+ ##| ORIGIN
15
+ def left val=1
16
+ SugarCube::right -val
17
+ end
18
+ alias :l :left
18
19
 
19
- def right val=1
20
- f = @@sugarcube_view.frame
21
- f.origin.x += val
22
- @@sugarcube_view.frame = f
23
- end
24
- alias :r :right
20
+ def right val=1
21
+ f = @@sugarcube_view.frame
22
+ f.origin.x += val
23
+ @@sugarcube_view.frame = f
24
+ end
25
+ alias :r :right
25
26
 
26
- def up val=1
27
- SugarCube::down -val
28
- end
29
- alias :u :up
27
+ def up val=1
28
+ SugarCube::down -val
29
+ end
30
+ alias :u :up
30
31
 
31
- def down val=1
32
- f = @@sugarcube_view.frame
33
- f.origin.y += val
34
- @@sugarcube_view.frame = f
35
- end
36
- alias :d :down
32
+ def down val=1
33
+ f = @@sugarcube_view.frame
34
+ f.origin.y += val
35
+ @@sugarcube_view.frame = f
36
+ end
37
+ alias :d :down
37
38
 
38
- def origin x, y=nil
39
- f = @@sugarcube_view.frame
40
- if y
41
- f.origin.x = x
42
- f.origin.y = y
43
- else
44
- f.origin = x
39
+ def origin x, y=nil
40
+ f = @@sugarcube_view.frame
41
+ if y
42
+ f.origin.x = x
43
+ f.origin.y = y
44
+ else
45
+ f.origin = x
46
+ end
47
+ @@sugarcube_view.frame = f
45
48
  end
46
- @@sugarcube_view.frame = f
47
- end
48
- alias :o :origin
49
+ alias :o :origin
49
50
 
50
- ##| SIZE
51
- def thinner val=1
52
- SugarCube::wider -val
53
- end
54
- alias :n :thinner
51
+ ##| SIZE
52
+ def thinner val=1
53
+ SugarCube::wider -val
54
+ end
55
+ alias :n :thinner
55
56
 
56
- def wider val=1
57
- f = @@sugarcube_view.frame
58
- f.size.width += val
59
- @@sugarcube_view.frame = f
60
- end
61
- alias :w :wider
57
+ def wider val=1
58
+ f = @@sugarcube_view.frame
59
+ f.size.width += val
60
+ @@sugarcube_view.frame = f
61
+ end
62
+ alias :w :wider
62
63
 
63
- def taller val=1
64
- SugarCube::shorter -val
65
- end
66
- alias :t :taller
64
+ def taller val=1
65
+ SugarCube::shorter -val
66
+ end
67
+ alias :t :taller
67
68
 
68
- def shorter val=1
69
- f = @@sugarcube_view.frame
70
- f.size.height += val
71
- @@sugarcube_view.frame = f
72
- end
73
- alias :s :shorter
69
+ def shorter val=1
70
+ f = @@sugarcube_view.frame
71
+ f.size.height += val
72
+ @@sugarcube_view.frame = f
73
+ end
74
+ alias :s :shorter
74
75
 
75
- def size w, h=nil
76
- f = @@sugarcube_view.frame
77
- if h
78
- f.size.width = w
79
- f.size.height = h
80
- else
81
- f.size = w
76
+ def size w, h=nil
77
+ f = @@sugarcube_view.frame
78
+ if h
79
+ f.size.width = w
80
+ f.size.height = h
81
+ else
82
+ f.size = w
83
+ end
84
+ @@sugarcube_view.frame = f
82
85
  end
83
- @@sugarcube_view.frame = f
84
- end
85
- alias :z :size
86
+ alias :z :size
86
87
 
87
- ##| RESTORE
88
- def restore
89
- @@sugarcube_view.frame = @@sugarcube_restore
90
- end
91
- alias :r :restore
88
+ ##| RESTORE
89
+ def restore
90
+ @@sugarcube_view.frame = @@sugarcube_restore
91
+ end
92
+ alias :r :restore
92
93
 
94
+ end
93
95
  end
@@ -76,74 +76,76 @@ end
76
76
 
77
77
 
78
78
  module SugarCube
79
- module_function
80
-
81
- def Size(w_or_size, h=nil)
82
- if not h
83
- if CGSize === w_or_size
84
- w = w_or_size.width
85
- h = w_or_size.height
86
- elsif Array === w_or_size
87
- w = w_or_size[0]
88
- h = w_or_size[1]
79
+ module CoreGraphics
80
+ module_function
81
+
82
+ def Size(w_or_size, h=nil)
83
+ if not h
84
+ if CGSize === w_or_size
85
+ w = w_or_size.width
86
+ h = w_or_size.height
87
+ elsif Array === w_or_size
88
+ w = w_or_size[0]
89
+ h = w_or_size[1]
90
+ else
91
+ raise RuntimeError.new("Invalid argument sent to Size(#{w_or_size.inspect})")
92
+ end
89
93
  else
90
- raise RuntimeError.new("Invalid argument sent to Size(#{w_or_size.inspect})")
94
+ w = w_or_size
91
95
  end
92
- else
93
- w = w_or_size
96
+ return CGSizeArray.new([w, h])
94
97
  end
95
- return CGSizeArray.new([w, h])
96
- end
97
98
 
98
- def Point(x_or_origin, y=nil)
99
- if not y
100
- if CGPoint === x_or_origin
101
- x = x_or_origin.x
102
- y = x_or_origin.y
103
- elsif Array === x_or_origin
104
- x = x_or_origin[0]
105
- y = x_or_origin[1]
99
+ def Point(x_or_origin, y=nil)
100
+ if not y
101
+ if CGPoint === x_or_origin
102
+ x = x_or_origin.x
103
+ y = x_or_origin.y
104
+ elsif Array === x_or_origin
105
+ x = x_or_origin[0]
106
+ y = x_or_origin[1]
107
+ else
108
+ raise RuntimeError.new("Invalid argument sent to Point(#{x_or_origin.inspect})")
109
+ end
106
110
  else
107
- raise RuntimeError.new("Invalid argument sent to Point(#{x_or_origin.inspect})")
111
+ x = x_or_origin
108
112
  end
109
- else
110
- x = x_or_origin
113
+ return CGPointArray.new([x, y])
111
114
  end
112
- return CGPointArray.new([x, y])
113
- end
114
115
 
115
- # Accepts 2 or 4 arguments. 2 arguments should be a point and a size,
116
- # 4 should be x, y, w, h
117
- def Rect(x_or_origin, y_or_size=nil, w=nil, h=nil)
118
- if not y_or_size
119
- if CGRectArray === x_or_origin
120
- x = x_or_origin[0][0]
121
- y = x_or_origin[0][1]
122
- w = x_or_origin[1][0]
123
- h = x_or_origin[1][1]
124
- elsif CGRect === x_or_origin
125
- x = x_or_origin.origin.x
126
- y = x_or_origin.origin.y
127
- w = x_or_origin.size.width
128
- h = x_or_origin.size.height
129
- elsif Array === x_or_origin
130
- x = x_or_origin[0]
131
- y = x_or_origin[1]
132
- w = x_or_origin[2]
133
- h = x_or_origin[3]
116
+ # Accepts 2 or 4 arguments. 2 arguments should be a point and a size,
117
+ # 4 should be x, y, w, h
118
+ def Rect(x_or_origin, y_or_size=nil, w=nil, h=nil)
119
+ if not y_or_size
120
+ if CGRectArray === x_or_origin
121
+ x = x_or_origin[0][0]
122
+ y = x_or_origin[0][1]
123
+ w = x_or_origin[1][0]
124
+ h = x_or_origin[1][1]
125
+ elsif CGRect === x_or_origin
126
+ x = x_or_origin.origin.x
127
+ y = x_or_origin.origin.y
128
+ w = x_or_origin.size.width
129
+ h = x_or_origin.size.height
130
+ elsif Array === x_or_origin
131
+ x = x_or_origin[0]
132
+ y = x_or_origin[1]
133
+ w = x_or_origin[2]
134
+ h = x_or_origin[3]
135
+ else
136
+ raise RuntimeError.new("Invalid argument sent to Rect(#{x_or_origin.inspect})")
137
+ end
138
+ elsif not w and not h
139
+ x = x_or_origin.x
140
+ y = x_or_origin.y
141
+ w = y_or_size.width
142
+ h = y_or_size.height
134
143
  else
135
- raise RuntimeError.new("Invalid argument sent to Rect(#{x_or_origin.inspect})")
144
+ x = x_or_origin
145
+ y = y_or_size
136
146
  end
137
- elsif not w and not h
138
- x = x_or_origin.x
139
- y = x_or_origin.y
140
- w = y_or_size.width
141
- h = y_or_size.height
142
- else
143
- x = x_or_origin
144
- y = y_or_size
147
+ return CGRectArray.new([[x, y], [w, h]])
145
148
  end
146
- return CGRectArray.new([[x, y], [w, h]])
147
- end
148
149
 
150
+ end
149
151
  end
@@ -13,7 +13,3 @@ class NSString
13
13
  end
14
14
 
15
15
  end
16
-
17
-
18
- class Object
19
- end
File without changes
@@ -0,0 +1,7 @@
1
+ class NSURL
2
+
3
+ def open
4
+ NSUIApplication.sharedApplication.openURL(NSUrl.URLWithString(self))
5
+ end
6
+
7
+ end
@@ -12,7 +12,7 @@ class UIView
12
12
  "#{self.superview ? ' child of ' + self.superview.class.name : ''}"
13
13
  end
14
14
 
15
- def fadeout(duration=0.3, options={}, &after)
15
+ def fade_out(duration=0.3, options={}, &after)
16
16
  UIView.animateWithDuration(duration,
17
17
  delay: options[:delay] || 0,
18
18
  options: options[:options] || UIViewAnimationOptionCurveLinear,
@@ -1,3 +1,3 @@
1
1
  module SugarCube
2
- Version = '0.2.0'
2
+ Version = '0.2.1'
3
3
  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.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ date: 2012-07-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
17
- requirement: &70353599174140 !ruby/object:Gem::Requirement
17
+ requirement: &70111935636200 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70353599174140
25
+ version_requirements: *70111935636200
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rspec
28
- requirement: &70353599189900 !ruby/object:Gem::Requirement
28
+ requirement: &70111935651940 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70353599189900
36
+ version_requirements: *70111935651940
37
37
  description: ! 'CocoaTouch/iOS is a *verbose* framework. These extensions hope to
38
38
  make
39
39
 
@@ -72,7 +72,8 @@ files:
72
72
  - lib/sugarcube/fixnum.rb
73
73
  - lib/sugarcube/float.rb
74
74
  - lib/sugarcube/notifications.rb
75
- - lib/sugarcube/string.rb
75
+ - lib/sugarcube/nsstring.rb
76
+ - lib/sugarcube/nsurl.rb
76
77
  - lib/sugarcube/symbol.rb
77
78
  - lib/sugarcube/symbol/symbol_uicolor.rb
78
79
  - lib/sugarcube/uicolor.rb