sugarcube 0.7 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +52 -6
- data/lib/sugarcube/core_graphics.rb +24 -7
- data/lib/sugarcube/document.rb +5 -3
- data/lib/sugarcube/numeric.rb +4 -0
- data/lib/sugarcube/symbol.rb +60 -2
- data/lib/sugarcube/uitableview.rb +7 -4
- data/lib/sugarcube/uiviewcontroller.rb +12 -0
- data/lib/sugarcube/version.rb +1 -1
- metadata +17 -7
data/README.md
CHANGED
@@ -130,6 +130,13 @@ This is the "big daddy". Lots of sugar here...
|
|
130
130
|
:small.uifont # => UIFont.systemFontOfSize(:small.uifontsize)
|
131
131
|
:bold.uifont(:small) # UIFont.boldSystemFontOfSize(:small.uifontsize)
|
132
132
|
:large.uiactivityindicatorstyle # :large, :white, :gray
|
133
|
+
|
134
|
+
# UITableView and UITableViewCell have LOTS of associated constants... I'm
|
135
|
+
# adding them as I come across them.
|
136
|
+
:automatic.uitablerowanimation # or .uitableviewrowanimation
|
137
|
+
:default.uitablecellstyle # or .uitableviewcellstyle
|
138
|
+
:disclosue.uitablecellaccessory # or .uitableviewcellaccessorytype
|
139
|
+
:blue.uitablecellselectionstyle # or .uitableviewcellselectionstyle
|
133
140
|
```
|
134
141
|
|
135
142
|
UIImage
|
@@ -228,10 +235,14 @@ UIButton.contact_add => UIButton.buttonWithType(:contact_add.uibuttontype)
|
|
228
235
|
|
229
236
|
```ruby
|
230
237
|
UITableView.alloc.initWithFrame([[0, 0], [320, 480]], style: :plain.uitableviewstyle)
|
231
|
-
|
238
|
+
# custom frame:
|
239
|
+
UITableView.alloc.initWithFrame([[0, 0], [320, 400]], style: :grouped.uitableviewstyle)
|
240
|
+
|
232
241
|
# =>
|
242
|
+
|
233
243
|
UITableView.plain
|
234
|
-
|
244
|
+
# custom frame:
|
245
|
+
UITableView.grouped([[0, 0], [320, 400]])
|
235
246
|
```
|
236
247
|
|
237
248
|
UIControl
|
@@ -271,6 +282,24 @@ nav_ctlr << new_ctlr
|
|
271
282
|
nav_ctlr.pop
|
272
283
|
nav_ctlr.!
|
273
284
|
nav_ctlr.!(another_view_ctlr)
|
285
|
+
```
|
286
|
+
|
287
|
+
UITabBarController
|
288
|
+
------------------------
|
289
|
+
|
290
|
+
I have mixed feelings about adding this extension, but **I** needed it, so maybe
|
291
|
+
you will, too... Usually `UITabBarController`s have a static number of tabs,
|
292
|
+
but in my case, I needed to be able to add one later, when a certain condition
|
293
|
+
was met.
|
294
|
+
|
295
|
+
```ruby
|
296
|
+
controllers = tabbar_ctlr.viewControllers
|
297
|
+
controllers << new_ctlr
|
298
|
+
tabbar_ctlr.setViewControllers(controllers, animated: true)
|
299
|
+
|
300
|
+
# =>
|
301
|
+
|
302
|
+
tabbar_ctlr << new_ctlr
|
274
303
|
```
|
275
304
|
|
276
305
|
NSNotificationCenter
|
@@ -292,6 +321,11 @@ Makes it easy to post a notification to some or all objects.
|
|
292
321
|
1.second.later do
|
293
322
|
@view.shake
|
294
323
|
end
|
324
|
+
|
325
|
+
# if you have a better name, I'll use it ;-)
|
326
|
+
1.second.every do
|
327
|
+
@view.shake
|
328
|
+
end
|
295
329
|
```
|
296
330
|
|
297
331
|
NSUserDefaults
|
@@ -361,7 +395,7 @@ f = Rect(p, s)
|
|
361
395
|
f = Rect([[x, y], [w, h]])
|
362
396
|
```
|
363
397
|
|
364
|
-
###### {
|
398
|
+
###### CG{Rect,Point,Size} is a *real boy*!
|
365
399
|
|
366
400
|
These methods get defined in a module (`SugarCube::CG{Rect,Size,Point}Extensions`),
|
367
401
|
and included in `CGRect` *and* `Rect`. The idea is that you do not have to
|
@@ -427,16 +461,28 @@ view.frame + a_size # => CGRectInset(view.frame, -a_size.width, -a_size.height)
|
|
427
461
|
# See? It's bigger, but the center hasn't moved.
|
428
462
|
```
|
429
463
|
|
430
|
-
`to_hash/from_hash`, and notice here that I used `
|
431
|
-
|
464
|
+
`to_hash/from_hash`, and notice here that I used `inspect`, to show that it is a
|
465
|
+
little more readable.
|
466
|
+
|
467
|
+
**NOTE** As of today, Aug. 25, 2012, rubymotion v1.22, the `inspect` method in SugarCube is not
|
468
|
+
being called. I think this is a bug... this worked before!
|
432
469
|
|
433
470
|
```ruby
|
434
471
|
> Rect(0, 0, 10, 10).to_hash
|
435
472
|
=> {"Width"=>10.0, "Height"=>10.0, "Y"=>0.0, "X"=>0.0}
|
436
|
-
> puts CGRect.from_hash
|
473
|
+
> puts CGRect.from_hash(Rect(0, 0, 1, 1).to_hash).inspect
|
437
474
|
CGRect([0.0, 0.0],{1.0 × 1.0})
|
438
475
|
```
|
439
476
|
|
477
|
+
`to_s/from_s`, which rely on `NSStringFromCGRect/CGRectFromString` (et. al.)
|
478
|
+
|
479
|
+
```ruby
|
480
|
+
> Rect(0, 0, 10, 10).to_s
|
481
|
+
=> "{{0, 0}, {10, 10}}"
|
482
|
+
> puts CGRect.from_s Rect(0, 0, 10, 10).to_s
|
483
|
+
{{0, 0}, {10, 10}}
|
484
|
+
```
|
485
|
+
|
440
486
|
[CGGeometry Reference]: https://developer.apple.com/library/mac/documentation/graphicsimaging/reference/CGGeometry/Reference/reference.html
|
441
487
|
|
442
488
|
REPL View adjustments
|
@@ -2,7 +2,6 @@ module SugarCube
|
|
2
2
|
# Extensions to make CGRect a "real class"
|
3
3
|
module CGRectExtensions
|
4
4
|
module ClassMethods
|
5
|
-
|
6
5
|
def empty
|
7
6
|
SugarCube::CoreGraphics::Rect(CGRectZero)
|
8
7
|
end
|
@@ -23,6 +22,10 @@ module SugarCube
|
|
23
22
|
nil
|
24
23
|
end
|
25
24
|
end
|
25
|
+
|
26
|
+
def from_s(s)
|
27
|
+
CGRectFromString(s)
|
28
|
+
end
|
26
29
|
end
|
27
30
|
|
28
31
|
def self.included(base)
|
@@ -70,6 +73,10 @@ module SugarCube
|
|
70
73
|
end
|
71
74
|
|
72
75
|
def to_s
|
76
|
+
NSStringFromCGRect(self)
|
77
|
+
end
|
78
|
+
|
79
|
+
def inspect
|
73
80
|
"#{self.class.name}([#{self.origin.x}, #{self.origin.y}],{#{self.size.width} × #{self.size.height}})"
|
74
81
|
end
|
75
82
|
|
@@ -77,8 +84,6 @@ module SugarCube
|
|
77
84
|
CGRectCreateDictionaryRepresentation(self)
|
78
85
|
end
|
79
86
|
|
80
|
-
def inspect ; to_s ; end
|
81
|
-
|
82
87
|
# # returns an intersection of self and rect, or moves the Rect using Point,
|
83
88
|
# or increases the size using Size
|
84
89
|
def +(rect)
|
@@ -141,6 +146,10 @@ module SugarCube
|
|
141
146
|
nil
|
142
147
|
end
|
143
148
|
end
|
149
|
+
|
150
|
+
def from_s(s)
|
151
|
+
CGPointFromString(s)
|
152
|
+
end
|
144
153
|
end
|
145
154
|
|
146
155
|
def self.included(base)
|
@@ -156,6 +165,10 @@ module SugarCube
|
|
156
165
|
end
|
157
166
|
|
158
167
|
def to_s
|
168
|
+
NSStringFromCGPoint(self)
|
169
|
+
end
|
170
|
+
|
171
|
+
def inspect
|
159
172
|
"#{self.class.name}(#{self.x}, #{self.y})"
|
160
173
|
end
|
161
174
|
|
@@ -163,8 +176,6 @@ module SugarCube
|
|
163
176
|
CGPointCreateDictionaryRepresentation(self)
|
164
177
|
end
|
165
178
|
|
166
|
-
def inspect ; to_s ; end
|
167
|
-
|
168
179
|
end
|
169
180
|
|
170
181
|
# Extensions to make CGSize a "real class"
|
@@ -183,6 +194,10 @@ module SugarCube
|
|
183
194
|
nil
|
184
195
|
end
|
185
196
|
end
|
197
|
+
|
198
|
+
def from_s(s)
|
199
|
+
CGSizeFromString(s)
|
200
|
+
end
|
186
201
|
end
|
187
202
|
|
188
203
|
def self.included(base)
|
@@ -199,6 +214,10 @@ module SugarCube
|
|
199
214
|
end
|
200
215
|
|
201
216
|
def to_s
|
217
|
+
NSStringFromCGSize(self)
|
218
|
+
end
|
219
|
+
|
220
|
+
def inspect
|
202
221
|
"#{self.class.name}(#{self.width} × #{self.height})"
|
203
222
|
end
|
204
223
|
|
@@ -206,8 +225,6 @@ module SugarCube
|
|
206
225
|
CGSizeCreateDictionaryRepresentation(self)
|
207
226
|
end
|
208
227
|
|
209
|
-
def inspect ; to_s ; end
|
210
|
-
|
211
228
|
end
|
212
229
|
end
|
213
230
|
|
data/lib/sugarcube/document.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
class NSString
|
2
2
|
|
3
3
|
def document
|
4
|
-
|
5
|
-
|
4
|
+
@@docs ||= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0]
|
5
|
+
return self if self.hasPrefix(@@docs)
|
6
|
+
|
7
|
+
@@docs.stringByAppendingPathComponent(self)
|
6
8
|
end
|
7
9
|
|
8
10
|
def exists?
|
9
|
-
NSFileManager.defaultManager.fileExistsAtPath(self)
|
11
|
+
NSFileManager.defaultManager.fileExistsAtPath(self.document)
|
10
12
|
end
|
11
13
|
|
12
14
|
end
|
data/lib/sugarcube/numeric.rb
CHANGED
@@ -23,4 +23,8 @@ class Numeric
|
|
23
23
|
NSTimer.scheduledTimerWithTimeInterval(self.to_f, target: fire, selector: 'call:', userInfo: user_info, repeats: false)
|
24
24
|
end
|
25
25
|
|
26
|
+
def every(user_info=nil, &fire)
|
27
|
+
NSTimer.scheduledTimerWithTimeInterval(self.to_f, target: fire, selector: 'call:', userInfo: user_info, repeats: true)
|
28
|
+
end
|
29
|
+
|
26
30
|
end
|
data/lib/sugarcube/symbol.rb
CHANGED
@@ -38,6 +38,10 @@ class Symbol
|
|
38
38
|
attr_accessor :returnkeys
|
39
39
|
attr_accessor :activityindicator_styles
|
40
40
|
attr_accessor :tableview_styles
|
41
|
+
attr_accessor :tableview_rowanimation
|
42
|
+
attr_accessor :tableview_cellstyles
|
43
|
+
attr_accessor :tableview_cellaccessorytype
|
44
|
+
attr_accessor :tableview_cellselectionstyle
|
41
45
|
attr_accessor :statusbar_styles
|
42
46
|
attr_accessor :barmetrics
|
43
47
|
attr_accessor :barbuttomitems
|
@@ -108,6 +112,7 @@ class Symbol
|
|
108
112
|
|
109
113
|
@controlevents = {
|
110
114
|
touch: UIControlEventTouchUpInside,
|
115
|
+
touch_up: UIControlEventTouchUpInside,
|
111
116
|
touch_down: UIControlEventTouchDown,
|
112
117
|
|
113
118
|
touch_down_repeat: UIControlEventTouchDownRepeat,
|
@@ -172,9 +177,42 @@ class Symbol
|
|
172
177
|
grouped: UITableViewStyleGrouped,
|
173
178
|
}
|
174
179
|
|
180
|
+
@tableview_rowanimation = {
|
181
|
+
fade: UITableViewRowAnimationFade,
|
182
|
+
right: UITableViewRowAnimationRight,
|
183
|
+
left: UITableViewRowAnimationLeft,
|
184
|
+
top: UITableViewRowAnimationTop,
|
185
|
+
bottom: UITableViewRowAnimationBottom,
|
186
|
+
none: UITableViewRowAnimationNone,
|
187
|
+
middle: UITableViewRowAnimationMiddle,
|
188
|
+
automatic: UITableViewRowAnimationAutomatic,
|
189
|
+
}
|
190
|
+
|
191
|
+
@tableview_cellstyles = {
|
192
|
+
default: UITableViewCellStyleDefault,
|
193
|
+
value1: UITableViewCellStyleValue1,
|
194
|
+
value2: UITableViewCellStyleValue2,
|
195
|
+
subtitle: UITableViewCellStyleSubtitle,
|
196
|
+
}
|
197
|
+
|
198
|
+
@tableview_cellaccessorytype = {
|
199
|
+
none: UITableViewCellAccessoryNone,
|
200
|
+
disclosure: UITableViewCellAccessoryDisclosureIndicator,
|
201
|
+
disclosureindicator: UITableViewCellAccessoryDisclosureIndicator,
|
202
|
+
detail: UITableViewCellAccessoryDetailDisclosureButton,
|
203
|
+
detaildisclosurebutton: UITableViewCellAccessoryDetailDisclosureButton,
|
204
|
+
checkmark: UITableViewCellAccessoryCheckmark,
|
205
|
+
}
|
206
|
+
|
207
|
+
@tableview_cellselectionstyle = {
|
208
|
+
none: UITableViewCellSelectionStyleNone,
|
209
|
+
blue: UITableViewCellSelectionStyleBlue,
|
210
|
+
gray: UITableViewCellSelectionStyleGray,
|
211
|
+
}
|
212
|
+
|
175
213
|
@statusbar_styles = {
|
176
|
-
default:
|
177
|
-
black:
|
214
|
+
default: UIStatusBarStyleDefault,
|
215
|
+
black: UIStatusBarStyleBlackOpaque,
|
178
216
|
translucent: UIStatusBarStyleBlackTranslucent,
|
179
217
|
}
|
180
218
|
|
@@ -281,6 +319,26 @@ class Symbol
|
|
281
319
|
end
|
282
320
|
alias :uitableviewstyle :uitablestyle
|
283
321
|
|
322
|
+
def uitablerowanimation
|
323
|
+
look_in(Symbol.tableview_rowanimation)
|
324
|
+
end
|
325
|
+
alias :uitableviewrowanimation :uitablerowanimation
|
326
|
+
|
327
|
+
def uitablecellstyle
|
328
|
+
look_in(Symbol.tableview_cellstyles)
|
329
|
+
end
|
330
|
+
alias :uitableviewcellstyle :uitablecellstyle
|
331
|
+
|
332
|
+
def uitablecellaccessory
|
333
|
+
look_in(Symbol.tableview_cellaccessorytype)
|
334
|
+
end
|
335
|
+
alias :uitableviewcellaccessorytype :uitablecellaccessory
|
336
|
+
|
337
|
+
def uitablecellselectionstyle
|
338
|
+
look_in(Symbol.tableview_cellselectionstyle)
|
339
|
+
end
|
340
|
+
alias :uitableviewcellselectionstyle :uitablecellselectionstyle
|
341
|
+
|
284
342
|
def uistatusbarstyle
|
285
343
|
look_in(Symbol.statusbar_styles)
|
286
344
|
end
|
@@ -1,10 +1,13 @@
|
|
1
1
|
class UITableView
|
2
2
|
class << self
|
3
|
-
|
4
|
-
|
3
|
+
|
4
|
+
def plain(frame=[[0, 0], [320, 480]])
|
5
|
+
UITableView.alloc.initWithFrame(frame, style: :plain.uitableviewstyle)
|
5
6
|
end
|
6
|
-
|
7
|
-
|
7
|
+
|
8
|
+
def grouped(frame=[[0, 0], [320, 480]])
|
9
|
+
UITableView.alloc.initWithFrame(frame, style: :grouped.uitableviewstyle)
|
8
10
|
end
|
11
|
+
|
9
12
|
end
|
10
13
|
end
|
@@ -25,3 +25,15 @@ class UINavigationController
|
|
25
25
|
end
|
26
26
|
|
27
27
|
end
|
28
|
+
|
29
|
+
|
30
|
+
class UITabBarController
|
31
|
+
|
32
|
+
def <<(view_controller)
|
33
|
+
view_controllers = [] + self.viewControllers
|
34
|
+
viewControllers << view_controller
|
35
|
+
self.setViewControllers(view_controllers, animated: true)
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/lib/sugarcube/version.rb
CHANGED
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:
|
4
|
+
version: 0.7.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-08-
|
13
|
+
date: 2012-08-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
17
|
-
requirement:
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,15 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements:
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
26
31
|
- !ruby/object:Gem::Dependency
|
27
32
|
name: rspec
|
28
|
-
requirement:
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
29
34
|
none: false
|
30
35
|
requirements:
|
31
36
|
- - ! '>='
|
@@ -33,7 +38,12 @@ dependencies:
|
|
33
38
|
version: '0'
|
34
39
|
type: :development
|
35
40
|
prerelease: false
|
36
|
-
version_requirements:
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
37
47
|
description: ! 'CocoaTouch/iOS is a *verbose* framework. These extensions hope to
|
38
48
|
make
|
39
49
|
|
@@ -113,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
123
|
version: '0'
|
114
124
|
requirements: []
|
115
125
|
rubyforge_project:
|
116
|
-
rubygems_version: 1.8.
|
126
|
+
rubygems_version: 1.8.19
|
117
127
|
signing_key:
|
118
128
|
specification_version: 3
|
119
129
|
summary: Extensions for Ruby to make Rubymotion development more enjoyable, and hopefully
|