sugarcube 0.19.5 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +28 -3
- data/Rakefile +1 -0
- data/lib/sugarcube/version.rb +1 -1
- data/lib/sugarcube-anonymous/anonymous.rb +56 -0
- data/lib/sugarcube-anonymous.rb +23 -0
- data/spec/anonymous_spec.rb +61 -0
- metadata +5 -1
data/README.md
CHANGED
@@ -72,6 +72,31 @@ Examples
|
|
72
72
|
[1, 3].nsindexpath # NSIndexPath.indexPathWithIndex(1).indexPathByAddingIndex(3)
|
73
73
|
[160, 210, 242].uicolor # => UIColor.colorWithRed(0.6274, green:0.8235, blue:0.9490, alpha:1.0)
|
74
74
|
[160, 210, 242].uicolor(0.5) # => UIColor.colorWithRed(0.6274, green:0.8235, blue:0.9490, alpha:0.5)
|
75
|
+
```
|
76
|
+
|
77
|
+
Hash => Object
|
78
|
+
--------
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
require 'sugarcube-attributedstring'
|
82
|
+
```
|
83
|
+
|
84
|
+
Convert `Hash`es into an "anonymous object". Existing keys will be able to be
|
85
|
+
accessed using method names. Uses the `SugarCube::Anonymous` class to
|
86
|
+
accomplish this, though the usual interface is via `Hash#to_object`.
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
h = { foo: 'FOO', 'bar' => 'BAR' }.to_object
|
90
|
+
|
91
|
+
# You can use methods instead of keys.
|
92
|
+
h.foo # => h[:foo]
|
93
|
+
h.bar # => h['bar']
|
94
|
+
h.foo = 'Foo' # => h[:foo] = 'Foo'
|
95
|
+
h.bar = 'Bar' # => h['bar'] = 'Bar'
|
96
|
+
|
97
|
+
# only existing keys are accessed this way
|
98
|
+
h.baz # => NoMethodError
|
99
|
+
h.baz = 'baz' # => NoMethodError
|
75
100
|
```
|
76
101
|
|
77
102
|
Fixnum
|
@@ -1084,14 +1109,14 @@ text_view.off :change, :end, :begin
|
|
1084
1109
|
UILabel
|
1085
1110
|
----------
|
1086
1111
|
|
1087
|
-
Added simple `fit_to_size` function to the label, which will start at the supplied font size
|
1112
|
+
Added simple `fit_to_size` function to the label, which will start at the supplied font size
|
1088
1113
|
and then squeeze down until all the text fits. This way you can assure any dynamic text will completely display
|
1089
|
-
in a given label frame.
|
1114
|
+
in a given label frame.
|
1090
1115
|
|
1091
1116
|
The font size changes instead of the frame size.
|
1092
1117
|
```ruby
|
1093
1118
|
#this will try to make the containing text fit at font size 40, but squeeze as needed.
|
1094
|
-
@label.fit_to_size(40)
|
1119
|
+
@label.fit_to_size(40)
|
1095
1120
|
puts @label.font.pointSize # => Will be 40 or less depending on the font type and label frame.
|
1096
1121
|
```
|
1097
1122
|
|
data/Rakefile
CHANGED
data/lib/sugarcube/version.rb
CHANGED
@@ -0,0 +1,56 @@
|
|
1
|
+
module SugarCube
|
2
|
+
# A subclass of Hash that allows its keys to be accessed and assigned by
|
3
|
+
# method name. Useful to quickly mock objects. To that end, a
|
4
|
+
# `NoMethodError` is raised anytime the key doesn't exist (getter or setter)
|
5
|
+
#
|
6
|
+
# You can convert an existing Hash or NSDictionary into a Anonymous using the
|
7
|
+
# constructor `SugarCube::Anonymous[hash]`, or you can call `to_object` on a
|
8
|
+
# dictionary or hash.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# obj = {
|
12
|
+
# 'first_name': 'Katsuyoshi', # strings
|
13
|
+
# company: 'Ito Soft Design', # and symbols are supported
|
14
|
+
# }.to_object
|
15
|
+
#
|
16
|
+
# obj.first_name
|
17
|
+
# # => 'Katsuyoshi'
|
18
|
+
# obj.company
|
19
|
+
# # => 'Ito Soft Design'
|
20
|
+
# obj.bla # => raises NoMethodError
|
21
|
+
# obj.bla = 'bla' # => raises NoMethodError
|
22
|
+
class Anonymous < Hash
|
23
|
+
|
24
|
+
def method_missing(symbol, *args)
|
25
|
+
if args.size == 0
|
26
|
+
key = symbol
|
27
|
+
key = symbol.to_s unless self.include? key
|
28
|
+
if self.include?(key)
|
29
|
+
return self[key]
|
30
|
+
end
|
31
|
+
elsif args.size == 1 && /(.*)=$/ =~ symbol.to_s
|
32
|
+
key = $1.to_sym
|
33
|
+
key = key.to_s unless self.include? key
|
34
|
+
if self.include?(key)
|
35
|
+
return self[key] = args.first
|
36
|
+
end
|
37
|
+
end
|
38
|
+
return super
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_object
|
42
|
+
self
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
class NSDictionary
|
51
|
+
|
52
|
+
def to_object
|
53
|
+
SugarCube::Anonymous[self]
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
unless defined?(Motion::Project::Config)
|
2
|
+
raise "The sugarcube gem must be required within a RubyMotion project Rakefile."
|
3
|
+
end
|
4
|
+
|
5
|
+
|
6
|
+
Motion::Project::App.setup do |app|
|
7
|
+
# scans app.files until it finds app/ (the default)
|
8
|
+
# if found, it inserts just before those files, otherwise it will insert to
|
9
|
+
# the end of the list
|
10
|
+
insert_point = 0
|
11
|
+
app.files.each_index do |index|
|
12
|
+
file = app.files[index]
|
13
|
+
if file =~ /^(?:\.\/)?app\//
|
14
|
+
# found app/, so stop looking
|
15
|
+
break
|
16
|
+
end
|
17
|
+
insert_point = index + 1
|
18
|
+
end
|
19
|
+
|
20
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'sugarcube-anonymous/**/*.rb')).reverse.each do |file|
|
21
|
+
app.files.insert(insert_point, file)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
describe "SugarCube::Anonymous" do
|
2
|
+
|
3
|
+
before do
|
4
|
+
@h = SugarCube::Anonymous[{ foo: 'FOO', "bar" => 'BAR' }]
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "NSDictionary#to_object" do
|
8
|
+
|
9
|
+
it 'should return an instance of SugarCube::Anonymous' do
|
10
|
+
SugarCube::Anonymous.should === { foo: 'FOO', "bar" => 'BAR' }.to_object
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "constructor" do
|
16
|
+
|
17
|
+
it 'should give an instance of SugarCube::Anonymous' do
|
18
|
+
SugarCube::Anonymous.should === @h
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "getter" do
|
24
|
+
|
25
|
+
it 'should have an #foo method, and return "FOO"' do
|
26
|
+
@h.foo.should == 'FOO'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should have an #bar method, and return "BAR"' do
|
30
|
+
@h.bar.should == 'BAR'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should raise NoMethodError on non-existing keys' do
|
34
|
+
should.raise(NoMethodError) {
|
35
|
+
@h.hoge
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "setter" do
|
42
|
+
|
43
|
+
it 'should have an #foo= method, and return "Foo"' do
|
44
|
+
@h.foo = 'Foo'
|
45
|
+
@h.foo.should == 'Foo'
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should have a #bar= method, and return "Bar"' do
|
49
|
+
@h.bar = 'Bar'
|
50
|
+
@h.bar.should == 'Bar'
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should raise NoMethodError on non-existing keys' do
|
54
|
+
should.raise(NoMethodError) {
|
55
|
+
@h.hoge.should == 'Hoge'
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
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.
|
4
|
+
version: 0.20.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -52,6 +52,8 @@ files:
|
|
52
52
|
- app/uicontrol_controller.rb
|
53
53
|
- lib/sugarcube-568.rb
|
54
54
|
- lib/sugarcube-568/uiimage.rb
|
55
|
+
- lib/sugarcube-anonymous.rb
|
56
|
+
- lib/sugarcube-anonymous/anonymous.rb
|
55
57
|
- lib/sugarcube-attributedstring.rb
|
56
58
|
- lib/sugarcube-attributedstring/nsattributedstring.rb
|
57
59
|
- lib/sugarcube-gestures.rb
|
@@ -128,6 +130,7 @@ files:
|
|
128
130
|
- spec/568_spec.rb
|
129
131
|
- spec/activesupport_spec.rb
|
130
132
|
- spec/animation_chain_spec.rb
|
133
|
+
- spec/anonymous_spec.rb
|
131
134
|
- spec/calayer_spec.rb
|
132
135
|
- spec/core_graphics_spec.rb
|
133
136
|
- spec/core_location_spec.rb
|
@@ -190,6 +193,7 @@ test_files:
|
|
190
193
|
- spec/568_spec.rb
|
191
194
|
- spec/activesupport_spec.rb
|
192
195
|
- spec/animation_chain_spec.rb
|
196
|
+
- spec/anonymous_spec.rb
|
193
197
|
- spec/calayer_spec.rb
|
194
198
|
- spec/core_graphics_spec.rb
|
195
199
|
- spec/core_location_spec.rb
|