sugarcube 0.1.4 → 0.1.5
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.
- data/README.md +49 -3
- data/lib/sugarcube/document.rb +14 -0
- data/lib/sugarcube/notifications.rb +33 -0
- data/lib/sugarcube/string.rb +7 -3
- data/lib/sugarcube/version.rb +1 -1
- metadata +9 -17
data/README.md
CHANGED
@@ -15,7 +15,23 @@ Some UI classes are opened up as well, like adding the '<<' operator to a UIView
|
|
15
15
|
instance, instead of view.addSubview(subview), you can use the more idiomatic:
|
16
16
|
view << subview.
|
17
17
|
|
18
|
-
|
18
|
+
The basic idea of sugarcube is to turn some operations on their head. Insead of
|
19
|
+
|
20
|
+
NSUIApplication.sharedApplication.openURL(NSUrl.URLWithString(url))
|
21
|
+
|
22
|
+
How about:
|
23
|
+
|
24
|
+
url.nsurl.open
|
25
|
+
|
26
|
+
**DISCLAIMER**
|
27
|
+
|
28
|
+
It is possible that you *will not like sugarcube*. That is perfectly fine!
|
29
|
+
Some people take milk in their coffee, some take sugar. Some crazy maniacs
|
30
|
+
don't even *drink* coffee, if you can imagine that... All I'm saying is: to each
|
31
|
+
their own. You should checkout [BubbleWrap][] for another take on
|
32
|
+
Cocoa-wrappage.
|
33
|
+
|
34
|
+
Examples
|
19
35
|
========
|
20
36
|
|
21
37
|
Fixnum
|
@@ -38,6 +54,26 @@ examples
|
|
38
54
|
# create a percentage
|
39
55
|
100.0.percent # => 1.00
|
40
56
|
55.0.percent # => 0.55
|
57
|
+
```
|
58
|
+
|
59
|
+
NSNotificationCenter
|
60
|
+
----------------------
|
61
|
+
|
62
|
+
Makes it easy to post a notification to some or all objects.
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
# this one is handy, I think:
|
66
|
+
"my notification".post_notification # => NSNotificationCenter.defaultCenter.postNotificationName("my notification", object:nil)
|
67
|
+
"my notification".post_notification(obj) # => NSNotificationCenter.defaultCenter.postNotificationName("my notification", object:obj)
|
68
|
+
"my notification".post_notification(obj, user: 'dict') # => NSNotificationCenter.defaultCenter.postNotificationName("my notification", object:obj, userInfo:{user: 'dict'})
|
69
|
+
```
|
70
|
+
|
71
|
+
NSURL
|
72
|
+
-------
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
# see String for easy URL creation
|
76
|
+
"https://github.com".nsurl.open # => UIApplication.sharedApplication.openURL(NSURL.URLWithString("https://github.com"))
|
41
77
|
```
|
42
78
|
|
43
79
|
String
|
@@ -62,7 +98,15 @@ examples
|
|
62
98
|
|
63
99
|
# NSLocalizedString from string
|
64
100
|
"hello".localized # => NSBundle.mainBundle.localizedStringForKey("hello", value:nil, table:nil)
|
101
|
+
"hello"._ # == "hello".localized
|
65
102
|
"hello".localized('Hello!', 'hello_table') # => ...("hello", value:'Hello!', table:'hello_table')
|
103
|
+
|
104
|
+
# file location
|
105
|
+
"my.plist".exists? # => NSFileManager.defaultManager.fileExistsAtPath("my.plist")
|
106
|
+
"my.plist".document # => NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0].stringByAppendingPathComponent("my.plist")
|
107
|
+
|
108
|
+
# NSURL
|
109
|
+
"https://github.com".nsurl # => NSURL.URLWithString("https://github.com")
|
66
110
|
```
|
67
111
|
|
68
112
|
Symbol
|
@@ -106,8 +150,8 @@ self.view << subview # => self.view.addSubview(subview)
|
|
106
150
|
UIControl
|
107
151
|
-----------
|
108
152
|
|
109
|
-
Inspired by BubbleWrap's `when` method, but I prefer jQuery-style
|
110
|
-
sugarcube symbols.
|
153
|
+
Inspired by [BubbleWrap's][BubbleWrap] `when` method, but I prefer jQuery-style
|
154
|
+
verbs and sugarcube symbols.
|
111
155
|
|
112
156
|
```ruby
|
113
157
|
button = UIButton.alloc.initWithFrame([0, 0, 10, 10])
|
@@ -125,3 +169,5 @@ button.off(:all)
|
|
125
169
|
|
126
170
|
You can only remove handlers by "type", not by the action. e.g. If you bind
|
127
171
|
three `:touch` events, calling `button.off(:touch)` will remove all three.
|
172
|
+
|
173
|
+
[BubbleWrap]: https://github.com/rubymotion/BubbleWrap
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
class String
|
4
|
+
|
5
|
+
def document
|
6
|
+
@docs ||= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0]
|
7
|
+
@docs.stringByAppendingPathComponent(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
def exists?
|
11
|
+
NSFileManager.defaultManager.fileExistsAtPath(self)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
=begin
|
2
|
+
"my notification".observe(obj, :notified)
|
3
|
+
# => NSNotificationCenter.defaultCenter.addObserver(obj, selector::'notified:', name:"my notification", object: nil)
|
4
|
+
"my notification".observe(obj) { |notification| puts notification }
|
5
|
+
# => NSNotificationCenter.defaultCenter.addObserver(obj, selector::'__sugarcube_notified__:', name:"my notification", object: Proc.new { |notification| puts notification })
|
6
|
+
"my notification".observe { |notification| puts notification }
|
7
|
+
# => NSNotificationCenter.defaultCenter.addObserverForName("my notification", object: nil, queue:NSOperationQueue.mainQueue, usingBlock:{ |notification| puts notification })
|
8
|
+
|
9
|
+
"my notification".removeObserver(obj)
|
10
|
+
# => NSNotificationCenter.defaultCenter.removeObserver(object, name:"my notification", object: nil)
|
11
|
+
"my notification".removeObserver(obj, obj2)
|
12
|
+
# => NSNotificationCenter.defaultCenter.removeObserver(object, name:"my notification", object: obj2)
|
13
|
+
=end
|
14
|
+
|
15
|
+
class String
|
16
|
+
|
17
|
+
def post_notification(object=nil, user_info=nil)
|
18
|
+
if user_info and not Hash === user_info
|
19
|
+
raise TypeError("Invalid argument #{user_info.class.name} sent to String.post_notification")
|
20
|
+
end
|
21
|
+
|
22
|
+
if user_info
|
23
|
+
NSNotificationCenter.defaultCenter.postNotificationName(self, object:object, userInfo:user_info)
|
24
|
+
else
|
25
|
+
NSNotificationCenter.defaultCenter.postNotificationName(self, object:object)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
class Object
|
33
|
+
end
|
data/lib/sugarcube/string.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
class String
|
2
2
|
|
3
|
+
def nsurl
|
4
|
+
@url ||= NSURL.alloc.initWithString(self)
|
5
|
+
end
|
6
|
+
|
3
7
|
def uiimage
|
4
|
-
UIImage.imageNamed(self)
|
8
|
+
@uiimage = UIImage.imageNamed(self)
|
5
9
|
end
|
6
10
|
|
7
11
|
def uifont(size=UIFont.systemFontSize)
|
8
|
-
UIFont.fontWithName(self, size:size)
|
12
|
+
@uifont = UIFont.fontWithName(self, size:size)
|
9
13
|
end
|
10
14
|
|
11
15
|
def uicolor(alpha=nil)
|
@@ -28,7 +32,7 @@ class String
|
|
28
32
|
# This can be called as `"Hello".localized` or `"Hello"._`. The `str._`
|
29
33
|
# syntax is meant to be reminiscent of gettext-style `_(str)`.
|
30
34
|
def localized(value=nil, table=nil)
|
31
|
-
NSBundle.mainBundle.localizedStringForKey(self, value:value, table:table)
|
35
|
+
@localized = NSBundle.mainBundle.localizedStringForKey(self, value:value, table:table)
|
32
36
|
end
|
33
37
|
alias :_ :localized
|
34
38
|
|
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: 0.1.
|
4
|
+
version: 0.1.5
|
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-07-
|
13
|
+
date: 2012-07-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
17
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirement: &70177756873200 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,15 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements:
|
26
|
-
none: false
|
27
|
-
requirements:
|
28
|
-
- - ! '>='
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
version: '0'
|
25
|
+
version_requirements: *70177756873200
|
31
26
|
- !ruby/object:Gem::Dependency
|
32
27
|
name: rspec
|
33
|
-
requirement: !ruby/object:Gem::Requirement
|
28
|
+
requirement: &70177756872620 !ruby/object:Gem::Requirement
|
34
29
|
none: false
|
35
30
|
requirements:
|
36
31
|
- - ! '>='
|
@@ -38,12 +33,7 @@ dependencies:
|
|
38
33
|
version: '0'
|
39
34
|
type: :development
|
40
35
|
prerelease: false
|
41
|
-
version_requirements:
|
42
|
-
none: false
|
43
|
-
requirements:
|
44
|
-
- - ! '>='
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '0'
|
36
|
+
version_requirements: *70177756872620
|
47
37
|
description: ! 'CocoaTouch/iOS is a *verbose* framework. These extensions hope to
|
48
38
|
make
|
49
39
|
|
@@ -75,9 +65,11 @@ files:
|
|
75
65
|
- Rakefile
|
76
66
|
- lib/sugarcube.rb
|
77
67
|
- lib/sugarcube/core_graphics.rb
|
68
|
+
- lib/sugarcube/document.rb
|
78
69
|
- lib/sugarcube/exceptions.rb
|
79
70
|
- lib/sugarcube/fixnum.rb
|
80
71
|
- lib/sugarcube/float.rb
|
72
|
+
- lib/sugarcube/notifications.rb
|
81
73
|
- lib/sugarcube/string.rb
|
82
74
|
- lib/sugarcube/symbol.rb
|
83
75
|
- lib/sugarcube/symbol/symbol_uicolor.rb
|
@@ -107,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
99
|
version: '0'
|
108
100
|
requirements: []
|
109
101
|
rubyforge_project:
|
110
|
-
rubygems_version: 1.8.
|
102
|
+
rubygems_version: 1.8.11
|
111
103
|
signing_key:
|
112
104
|
specification_version: 3
|
113
105
|
summary: Extensions for Ruby to make Rubymotion development more enjoyable, and hopefully
|