sugarcube 0.13.5 → 0.13.7
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/LICENSE +2 -2
- data/README.md +44 -5
- data/Rakefile +5 -0
- data/lib/sugarcube/fixnum.rb +8 -0
- data/lib/sugarcube/nsstring_files.rb +28 -0
- data/lib/sugarcube/to_s/uicolor.rb +2 -2
- data/lib/sugarcube/uiimage.rb +7 -0
- data/lib/sugarcube/version.rb +1 -1
- data/spec/nsstring_files_spec.rb +68 -0
- data/spec/symbol_uicolor_spec.rb +10 -0
- data/sugarcube.gemspec +1 -1
- metadata +9 -3
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2012,
|
1
|
+
Copyright (c) 2012, RubyMotion Community. http://github.com/rubymotion
|
2
2
|
All rights reserved.
|
3
3
|
|
4
4
|
Redistribution and use in source and binary forms, with or without
|
@@ -23,4 +23,4 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
23
23
|
|
24
24
|
The views and conclusions contained in the software and documentation are those
|
25
25
|
of the authors and should not be interpreted as representing official policies,
|
26
|
-
either expressed or implied, of the
|
26
|
+
either expressed or implied, of the SugarCube Project.
|
data/README.md
CHANGED
@@ -91,6 +91,10 @@ Examples
|
|
91
91
|
13.nth # => 'th'
|
92
92
|
21.nth # => 'st'
|
93
93
|
23.nth # => 'rd'
|
94
|
+
|
95
|
+
NSDate.new # => 2013-01-03 11:42:24 -0700
|
96
|
+
5.days.ago # => 2012-12-29 11:42:24 -0700
|
97
|
+
5.days.hence # => 2013-01-08 11:42:24 -0700
|
94
98
|
```
|
95
99
|
|
96
100
|
Numeric
|
@@ -367,11 +371,19 @@ NSError.new('Error Message', code: 404, userInfo: { warnings: ['blabla'] })
|
|
367
371
|
"hello"._ # == "hello".localized
|
368
372
|
"hello".localized('Hello!', 'hello_table') # => ...("hello", value:'Hello!', table:'hello_table')
|
369
373
|
|
370
|
-
# file
|
374
|
+
# file operations
|
371
375
|
"my.plist".exists? # => NSFileManager.defaultManager.fileExistsAtPath("my.plist")
|
372
376
|
"my.plist".document # => NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0].stringByAppendingPathComponent("my.plist")
|
373
377
|
"my.plist".remove! # => NSFileManager.defaultManager.removeItemAtPath("my.plist".document, error: error) (returns error, if any occurred)
|
374
378
|
|
379
|
+
# get the resource path, useful if you include json files or images you manipulate in the app
|
380
|
+
"my.plist".resource # => NSBundle.mainBundle.resourcePath.stringByAppendingPathComponent("my.plist")
|
381
|
+
# same, but get a URL instead - often used to display a static HTML page that is stored in resources
|
382
|
+
"index.html".resource_url # => NSBundle.mainBundle.URLForResource("index", withExtension:"html")
|
383
|
+
|
384
|
+
# access data from Info.plist
|
385
|
+
"CFBundleVersion".info_plist # => NSBundle.mainBundle.infoDictionary["CFBundleVersion"]
|
386
|
+
|
375
387
|
# NSURL
|
376
388
|
"https://github.com".nsurl # => NSURL.URLWithString("https://github.com")
|
377
389
|
```
|
@@ -533,17 +545,29 @@ self.view.hide # => self.hidden = true
|
|
533
545
|
|
534
546
|
###### Animations
|
535
547
|
|
536
|
-
jQuery-like animation methods.
|
548
|
+
jQuery-like animation methods. They accept a "completed" callback handler that
|
549
|
+
accepts an optional 'completed' boolean (the
|
550
|
+
`UIView.animateWithDuration(delay:options:animations:completion:)`) method
|
551
|
+
provides it to all its completion handlers).
|
537
552
|
|
538
553
|
```ruby
|
539
554
|
# default timeout is 0.3
|
540
|
-
view.fade_out
|
555
|
+
view.fade_out
|
556
|
+
|
557
|
+
# with a callback
|
558
|
+
view.fade_out {
|
559
|
+
view.removeFromSuperview
|
560
|
+
}
|
561
|
+
|
562
|
+
# and the completed argument
|
563
|
+
view.fade_out { |completed|
|
541
564
|
view.removeFromSuperview
|
542
565
|
}
|
543
|
-
|
566
|
+
|
567
|
+
# fade_out options
|
544
568
|
view.fade_out(0.5, delay: 0,
|
545
569
|
options: UIViewAnimationOptionCurveLinear,
|
546
|
-
opacity: 0.5) {
|
570
|
+
opacity: 0.5) {
|
547
571
|
view.removeFromSuperview
|
548
572
|
}
|
549
573
|
|
@@ -565,6 +589,21 @@ view.shake offset: 20, repeat: 10, duration: 5, keypath: 'transform.translation.
|
|
565
589
|
superview.shake offset: 0.1, repeat: 2, duration: 0.5, keypath: 'transform.rotation'
|
566
590
|
```
|
567
591
|
|
592
|
+
Using the completed callback you can string animations together for a low-tech
|
593
|
+
animation sequence.
|
594
|
+
|
595
|
+
```ruby
|
596
|
+
view.slide(:left, 20) {
|
597
|
+
view.slide(:up, 20) {
|
598
|
+
view.slide(:right, 20) {
|
599
|
+
view.slide(:down, 20) {
|
600
|
+
view.fade_out
|
601
|
+
}
|
602
|
+
}
|
603
|
+
}
|
604
|
+
}
|
605
|
+
```
|
606
|
+
|
568
607
|
##### View factories
|
569
608
|
|
570
609
|
###### UIButton
|
data/Rakefile
CHANGED
data/lib/sugarcube/fixnum.rb
CHANGED
@@ -28,4 +28,32 @@ class NSString
|
|
28
28
|
NSFileManager.defaultManager.fileExistsAtPath(self.resource)
|
29
29
|
end
|
30
30
|
|
31
|
+
def resource_url
|
32
|
+
a = self.split(".")
|
33
|
+
ext = a.pop if a.size >= 2
|
34
|
+
NSBundle.mainBundle.URLForResource(a.join("."), withExtension:ext)
|
35
|
+
end
|
36
|
+
|
37
|
+
# It's convenient to store a property which is dependent on an environment to
|
38
|
+
# Info.plist. For instance, to use a different server between development and
|
39
|
+
# release versions.
|
40
|
+
#
|
41
|
+
# In Rakefile
|
42
|
+
# <code>
|
43
|
+
# app.release do
|
44
|
+
# app.info_plist['VerifyURL'] = "https://buy.itunes.apple.com/verifyReceipt"
|
45
|
+
# end
|
46
|
+
# app.development do
|
47
|
+
# app.info_plist['VerifyURL'] = "https://sandbox.itunes.apple.com/verifyReceipt"
|
48
|
+
# end
|
49
|
+
# </code>
|
50
|
+
#
|
51
|
+
# You can easily get this value at run time like this:
|
52
|
+
# <code>
|
53
|
+
# 'VerifyURL'.info_plist
|
54
|
+
# </code>
|
55
|
+
def info_plist
|
56
|
+
NSBundle.mainBundle.infoDictionary.valueForKey self
|
57
|
+
end
|
58
|
+
|
31
59
|
end
|
@@ -3,7 +3,7 @@ class UIColor
|
|
3
3
|
system_color = nil
|
4
4
|
Symbol.uicolors.each_pair do |color, method|
|
5
5
|
if UIColor.send(method) == self
|
6
|
-
if self.alpha < 1
|
6
|
+
if self.alpha && self.alpha < 1
|
7
7
|
system_color = "UIColor.#{method}(#{alpha})"
|
8
8
|
else
|
9
9
|
system_color = "UIColor.#{method}"
|
@@ -20,7 +20,7 @@ class UIColor
|
|
20
20
|
my_color = red + green + blue
|
21
21
|
|
22
22
|
inside = my_color.to_s(16)
|
23
|
-
inside = '0x' + '0' * (6 - inside.length)
|
23
|
+
inside = '0x' + '0' * (6 - inside.length) + inside
|
24
24
|
|
25
25
|
Symbol.css_colors.each_pair do |color, hex|
|
26
26
|
if hex == my_color
|
data/lib/sugarcube/uiimage.rb
CHANGED
@@ -190,4 +190,11 @@ class UIImage
|
|
190
190
|
resizableImageWithCapInsets(insets, resizingMode:UIImageResizingModeStretch)
|
191
191
|
end
|
192
192
|
|
193
|
+
##|
|
194
|
+
##| imageWithAlignmentRectInsets
|
195
|
+
##|
|
196
|
+
def alignment_rect(insets=UIEdgeInsetsZero)
|
197
|
+
imageWithAlignmentRectInsets(insets)
|
198
|
+
end
|
199
|
+
|
193
200
|
end
|
data/lib/sugarcube/version.rb
CHANGED
@@ -0,0 +1,68 @@
|
|
1
|
+
describe NSString do
|
2
|
+
|
3
|
+
describe 'resource()' do
|
4
|
+
describe '"info.plist".resource' do
|
5
|
+
before { @it = "info.plist".resource }
|
6
|
+
it 'should start with "/Users"' do
|
7
|
+
@it.hasPrefix("/Users").should == true
|
8
|
+
end
|
9
|
+
it 'should end with "SugarCube_spec.app/info.plist"' do
|
10
|
+
@it.hasSuffix("SugarCube_spec.app/info.plist").should == true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
describe '"PkgInfo".resource' do
|
14
|
+
before { @it = "PkgInfo".resource }
|
15
|
+
it 'should start with "/Users"' do
|
16
|
+
@it.hasPrefix("/Users").should == true
|
17
|
+
end
|
18
|
+
it 'should end with "SugarCube_spec.app/PkgInfo"' do
|
19
|
+
@it.hasSuffix("SugarCube_spec.app/PkgInfo").should == true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
describe 'resource_url()' do
|
26
|
+
=begin
|
27
|
+
# it fail. returns nil.
|
28
|
+
# Maybe info.plist is not permitted to get as NSURL
|
29
|
+
describe '"info.plist".resource_url' do
|
30
|
+
before { @it = "info.plist".resource_url.absoluteString }
|
31
|
+
it 'should start with "file://localhost/Users"' do
|
32
|
+
@it.hasPrefix("file://localhost/Users").should == true
|
33
|
+
end
|
34
|
+
it 'should end with "SugarCube_spec.app/info.plist"' do
|
35
|
+
@it.hasSuffix("SugarCube_spec.app/info.plist").should == true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
=end
|
39
|
+
|
40
|
+
describe '"PkgInfo".resource_url' do
|
41
|
+
before { @it = "PkgInfo".resource_url.absoluteString }
|
42
|
+
it 'should start with "file://localhost/Users"' do
|
43
|
+
@it.hasPrefix("file://localhost/Users").should == true
|
44
|
+
end
|
45
|
+
it 'should end with "SugarCube_spec.app/PkgInfo"' do
|
46
|
+
@it.hasSuffix("SugarCube_spec.app/PkgInfo").should == true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'info_plist' do
|
52
|
+
describe '"CFBundleVersion".info_plist' do
|
53
|
+
before { @it = "CFBundleVersion".info_plist }
|
54
|
+
it 'should be "1.0"' do
|
55
|
+
@it.should == "1.0"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '"CFBundleSupportedPlatforms".info_plist' do
|
60
|
+
before { @it = "CFBundleSupportedPlatforms".info_plist }
|
61
|
+
it 'should be ["iPhoneOS"]' do
|
62
|
+
@it.should == ["iPhoneOS"]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
data/sugarcube.gemspec
CHANGED
@@ -5,7 +5,7 @@ Gem::Specification.new do |gem|
|
|
5
5
|
gem.name = 'sugarcube'
|
6
6
|
gem.version = SugarCube::Version
|
7
7
|
|
8
|
-
gem.authors = ['Colin
|
8
|
+
gem.authors = ['Colin T.A. Gray', 'Thom Parkin', 'Katsuyoshi Ito', 'Fusionbox']
|
9
9
|
gem.email = ['colinta@gmail.com']
|
10
10
|
gem.summary = %{Extensions for Ruby to make Rubymotion development more enjoyable, and hopefully more rubyesque!}
|
11
11
|
gem.description = <<-DESC
|
metadata
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sugarcube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.
|
4
|
+
version: 0.13.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
- Colin
|
8
|
+
- Colin T.A. Gray
|
9
|
+
- Thom Parkin
|
10
|
+
- Katsuyoshi Ito
|
9
11
|
- Fusionbox
|
10
12
|
autorequire:
|
11
13
|
bindir: bin
|
12
14
|
cert_chain: []
|
13
|
-
date:
|
15
|
+
date: 2013-01-11 00:00:00.000000000 Z
|
14
16
|
dependencies: []
|
15
17
|
description: ! '== Description
|
16
18
|
|
@@ -101,6 +103,8 @@ files:
|
|
101
103
|
- lib/sugarcube/uuid.rb
|
102
104
|
- lib/sugarcube/version.rb
|
103
105
|
- spec/core_graphics_spec.rb
|
106
|
+
- spec/nsstring_files_spec.rb
|
107
|
+
- spec/symbol_uicolor_spec.rb
|
104
108
|
- sugarcube.gemspec
|
105
109
|
homepage: https://github.com/rubymotion/sugarcube
|
106
110
|
licenses: []
|
@@ -129,4 +133,6 @@ summary: Extensions for Ruby to make Rubymotion development more enjoyable, and
|
|
129
133
|
more rubyesque!
|
130
134
|
test_files:
|
131
135
|
- spec/core_graphics_spec.rb
|
136
|
+
- spec/nsstring_files_spec.rb
|
137
|
+
- spec/symbol_uicolor_spec.rb
|
132
138
|
has_rdoc:
|