sugarcube 3.0.8 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -2
- data/lib/cocoa/sugarcube-base64/nsdata.rb +16 -0
- data/lib/cocoa/sugarcube-base64/nsstring.rb +20 -0
- data/lib/ios/sugarcube-base64/uiimage.rb +9 -0
- data/lib/osx/sugarcube-base64/nsimage.rb +9 -0
- data/lib/sugarcube-base64.rb +10 -0
- data/lib/version.rb +1 -1
- data/spec/cocoa/base64_spec.rb +41 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a745c8ca1508da0db8c5282c8e467a95da3c764
|
4
|
+
data.tar.gz: 3dd4c5bdaf1344b81d1c530692213410c4336eae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b708aa93d0816e2d7d49b0bc5855927492e59f98301d52ef4438200c6b31fd0ee3db126661d14c7785da237cd194636a963ee4d65b9d19e36c987a2489d2fca
|
7
|
+
data.tar.gz: 29df8410a6f249ada0716b5babbebadf1d94d575dc706cf4f9afa7b77b5b975adab882ff1e7096a5c2129cd650270eb3696e5a16f63fc98288e548fa4336c9a8
|
data/README.md
CHANGED
@@ -1585,8 +1585,7 @@ NSUserDefaults['test'] = test # saved
|
|
1585
1585
|
CoreGraphics
|
1586
1586
|
--------------
|
1587
1587
|
|
1588
|
-
*This package is
|
1589
|
-
on it. It does not add any methods to built-in classes.*
|
1588
|
+
*This package is included by a few of the other packages, like repl, animations, and image.*
|
1590
1589
|
|
1591
1590
|
###### Is it `CGMakeRect` or `CGRectMake`? What arguments does `CGRect.new` take?
|
1592
1591
|
|
@@ -1625,6 +1624,36 @@ f = Rect(p, [w, h])
|
|
1625
1624
|
f = Rect([x, y], s)
|
1626
1625
|
```
|
1627
1626
|
|
1627
|
+
Base64
|
1628
|
+
------
|
1629
|
+
|
1630
|
+
> `require 'sugarcube-base64'`
|
1631
|
+
|
1632
|
+
**Todo: add UIImage/NSImage support**
|
1633
|
+
**Todo: add Android support?**
|
1634
|
+
|
1635
|
+
Uses the `NSData#base64EncodedStringWithOptions` and
|
1636
|
+
`NSData#initWithBase64EncodedData` methods to encode/decode base64 data. Normal
|
1637
|
+
use is to convert your image/binary data into an `NSData` instance, and then
|
1638
|
+
call `to_base64` on that object.
|
1639
|
+
|
1640
|
+
There is a helper on `NSString`, so you can convert an `NSString` instance
|
1641
|
+
directly to base-64, using UTF8 encoding (or any encoding Apple supports).
|
1642
|
+
|
1643
|
+
```ruby
|
1644
|
+
base64_str = 'test string'.to_base64
|
1645
|
+
...
|
1646
|
+
NSString.from_base64(base64_str) == 'test string'
|
1647
|
+
|
1648
|
+
# require 'sugarcube-nsdata'
|
1649
|
+
image = 'some_image'.uiimage
|
1650
|
+
data = image.nsdata # defaults to PNG data
|
1651
|
+
base64_str = data.to_base64
|
1652
|
+
...
|
1653
|
+
data = NSData.from_base64(base64_str)
|
1654
|
+
image = data.uiimage # defaults to reading PNG data
|
1655
|
+
```
|
1656
|
+
|
1628
1657
|
Pointer
|
1629
1658
|
-----
|
1630
1659
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class NSData
|
2
|
+
|
3
|
+
# converts an NSData instance into a base64 string.
|
4
|
+
# @todo Support NSDataBase64EncodingOptions options - easy to add, but I want
|
5
|
+
# to add specs, too, and a hash format (e.g. line_length: 64 =>
|
6
|
+
# NSDataBase64Encoding64CharacterLineLength).
|
7
|
+
def to_base64
|
8
|
+
self.base64EncodedStringWithOptions(0)
|
9
|
+
end
|
10
|
+
|
11
|
+
# factory method to convert a base64 string into NSData.
|
12
|
+
def self.from_base64(base64_data)
|
13
|
+
NSData.alloc.initWithBase64EncodedData(base64_data, options: 0)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class NSString
|
2
|
+
|
3
|
+
# converts an NSString instance into a base64 string, using UTF8 encoding or
|
4
|
+
# a user specified encoding.
|
5
|
+
# @todo Support NSDataBase64EncodingOptions options - easy to add, but I want
|
6
|
+
# to add specs, too, and a hash format (e.g. line_length: 64 =>
|
7
|
+
# NSDataBase64Encoding64CharacterLineLength).
|
8
|
+
def to_base64(enc=NSUTF8StringEncoding)
|
9
|
+
encoded = self.dataUsingEncoding(enc)
|
10
|
+
encoded.to_base64
|
11
|
+
end
|
12
|
+
|
13
|
+
# factory method to convert a base64 string into NSString, using UTF8 or a
|
14
|
+
# user specified encoding.
|
15
|
+
def self.from_base64(base64_str, enc=NSUTF8StringEncoding)
|
16
|
+
data = NSData.from_base64(base64_str.dataUsingEncoding(NSASCIIStringEncoding))
|
17
|
+
NSString.alloc.initWithData(data, encoding:enc)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/version.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
describe 'Base64' do
|
2
|
+
|
3
|
+
describe 'NSData' do
|
4
|
+
it 'should encode data' do
|
5
|
+
str = 'testing'
|
6
|
+
str_data = str.nsdata
|
7
|
+
str_data.to_base64.should == 'dGVzdGluZw=='
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should decode data' do
|
11
|
+
str_data = NSData.from_base64('dGVzdGluZw==')
|
12
|
+
str = NSString.alloc.initWithData(str_data, encoding:NSUTF8StringEncoding)
|
13
|
+
str.should == 'testing'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'NSString' do
|
18
|
+
it 'should encode data' do
|
19
|
+
'testing'.to_base64.should == 'dGVzdGluZw=='
|
20
|
+
end
|
21
|
+
it 'should encode data with encoding' do
|
22
|
+
'testing'.to_base64(NSUnicodeStringEncoding).should == '//50AGUAcwB0AGkAbgBnAA=='
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should decode data' do
|
26
|
+
NSString.from_base64('dGVzdGluZw==').should == 'testing'
|
27
|
+
end
|
28
|
+
it 'should decode data with encoding' do
|
29
|
+
NSString.from_base64('//50AGUAcwB0AGkAbgBnAA==', NSUnicodeStringEncoding).should == 'testing'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'UIImage' do
|
34
|
+
|
35
|
+
it 'should convert image data (PNG) to base64' do
|
36
|
+
'test'.uiimage.nsdata.to_base64.should == 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAHgCAIAAADrGJBNAAAAAXNSR0IArs4c6QAAABxpRE9UAAAAAgAAAAAAAADwAAAAKAAAAPAAAADwAAAAS9r5uVEAAAAXSURBVEgNYrhrxMAwikfDYDQNDMk0AAAAAP//6TQa9AAAABVJREFUY7hrxMAwikfDYDQNDMk0AACNnfwwqs717AAAAABJRU5ErkJggg=='
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
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: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colin T.A. Gray
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-01-
|
14
|
+
date: 2015-01-25 00:00:00.000000000 Z
|
15
15
|
dependencies: []
|
16
16
|
description: |
|
17
17
|
== Description
|
@@ -50,6 +50,8 @@ files:
|
|
50
50
|
- lib/cocoa/sugarcube-anonymous/anonymous_array.rb
|
51
51
|
- lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb
|
52
52
|
- lib/cocoa/sugarcube-awesome/awesome_exts.rb
|
53
|
+
- lib/cocoa/sugarcube-base64/nsdata.rb
|
54
|
+
- lib/cocoa/sugarcube-base64/nsstring.rb
|
53
55
|
- lib/cocoa/sugarcube-corelocation/core_location.rb
|
54
56
|
- lib/cocoa/sugarcube-files/nsarray.rb
|
55
57
|
- lib/cocoa/sugarcube-files/nsdata.rb
|
@@ -98,6 +100,7 @@ files:
|
|
98
100
|
- lib/ios/sugarcube-animations/animation_chain.rb
|
99
101
|
- lib/ios/sugarcube-animations/uiview.rb
|
100
102
|
- lib/ios/sugarcube-attributedstring/nsattributedstring.rb
|
103
|
+
- lib/ios/sugarcube-base64/uiimage.rb
|
101
104
|
- lib/ios/sugarcube-color/fixnum.rb
|
102
105
|
- lib/ios/sugarcube-color/nsarray.rb
|
103
106
|
- lib/ios/sugarcube-color/nsstring.rb
|
@@ -155,6 +158,7 @@ files:
|
|
155
158
|
- lib/ios/sugarcube-ui/uiwebview.rb
|
156
159
|
- lib/osx/sugarcube-animations/nsview.rb
|
157
160
|
- lib/osx/sugarcube-attributedstring/nsattributedstring.rb
|
161
|
+
- lib/osx/sugarcube-base64/nsimage.rb
|
158
162
|
- lib/osx/sugarcube-color/fixnum.rb
|
159
163
|
- lib/osx/sugarcube-color/nsarray.rb
|
160
164
|
- lib/osx/sugarcube-color/nscolor.rb
|
@@ -181,6 +185,7 @@ files:
|
|
181
185
|
- lib/sugarcube-appkit.rb
|
182
186
|
- lib/sugarcube-attributedstring.rb
|
183
187
|
- lib/sugarcube-awesome.rb
|
188
|
+
- lib/sugarcube-base64.rb
|
184
189
|
- lib/sugarcube-classic.rb
|
185
190
|
- lib/sugarcube-color.rb
|
186
191
|
- lib/sugarcube-common.rb
|
@@ -218,6 +223,7 @@ files:
|
|
218
223
|
- README.md
|
219
224
|
- spec/all/anonymous_spec.rb
|
220
225
|
- spec/all/numeric_spec.rb
|
226
|
+
- spec/cocoa/base64_spec.rb
|
221
227
|
- spec/cocoa/caanimation_spec.rb
|
222
228
|
- spec/cocoa/calayer_spec.rb
|
223
229
|
- spec/cocoa/nsarray_files_spec.rb
|
@@ -318,6 +324,7 @@ summary: Extensions for Ruby to make Rubymotion development more enjoyable, and
|
|
318
324
|
test_files:
|
319
325
|
- spec/all/anonymous_spec.rb
|
320
326
|
- spec/all/numeric_spec.rb
|
327
|
+
- spec/cocoa/base64_spec.rb
|
321
328
|
- spec/cocoa/caanimation_spec.rb
|
322
329
|
- spec/cocoa/calayer_spec.rb
|
323
330
|
- spec/cocoa/nsarray_files_spec.rb
|