plastic_cup 0.0.2 → 0.1.0
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.
- checksums.yaml +8 -8
- data/Gemfile +1 -0
- data/Gemfile.lock +3 -1
- data/README.md +13 -0
- data/Rakefile +1 -0
- data/lib/plastic_cup/base.rb +14 -3
- data/lib/plastic_cup/version.rb +1 -1
- data/spec/base_spec.rb +33 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OGI3ODk4MmZmMmM2MzYzYTk5ZmJlOGJiYmQ4YmVlZDU4YjM4YTFmYg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NThhNDRiNWY5NzVmMTczZmZiOTZjMDVlMjNmZDc4YzhjMDQwYmFhZA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjVmN2ZjYjVlNDcyYzU0MGJhMmQ3NGY2YzAwYzA5N2RkMTliNjY3ZDNiOGJj
|
10
|
+
ZjVlOWYzNzQxNjhlOTUwODQ4MmE2ZDIyN2JjMWMwMzg5MTBiMTE1M2QzMTI1
|
11
|
+
YmFjODlmMmRmMjgyYjdiOGRjODQ0ZjU5OWE4OTg3NDQzNTYyMWQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MDcwYWQ4NzczZTIxZmVmZWJhM2U0ZjdlZDhhODRiZjllMmJlODE2ZWJmZTkx
|
14
|
+
NmMzNDg2MWMxZWNjOGY5MTlkMzM0MDdiNjZiOGRlZDU2YzZhMzdiMGY0NTY3
|
15
|
+
N2Q2Y2FhMGE1MTBkNzNmYmYwNjQzMGJlMjFjYjYxNTk3MWQ4MmU=
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
plastic_cup (0.0
|
4
|
+
plastic_cup (0.1.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
+
motion-stump (0.3.0)
|
9
10
|
rake (10.1.0)
|
10
11
|
|
11
12
|
PLATFORMS
|
12
13
|
ruby
|
13
14
|
|
14
15
|
DEPENDENCIES
|
16
|
+
motion-stump
|
15
17
|
plastic_cup!
|
16
18
|
rake
|
data/README.md
CHANGED
@@ -33,6 +33,19 @@ PlasticCup::Base.add_style_sheet(:green_button, {
|
|
33
33
|
@button = PlasticCup::Base.style(UIButton.new, :green_button)
|
34
34
|
```
|
35
35
|
|
36
|
+
Support different iOS versions
|
37
|
+
```ruby
|
38
|
+
PlasticCup::Base.add_style_sheet(:bg_view, {
|
39
|
+
frame: CGRectMake(0, 0, 320, 200)
|
40
|
+
}, :all)
|
41
|
+
|
42
|
+
PlasticCup::Base.add_style_sheet(:bg_view, {
|
43
|
+
frame: CGRectMake(0, 20, 320, 200)
|
44
|
+
}, :ios7)
|
45
|
+
# supported symbols: :all, :ios4, :ios5, :ios6, :ios7
|
46
|
+
# default is :all
|
47
|
+
```
|
48
|
+
|
36
49
|
If you define stylesheet outside methods, some values (e.g. UIFont) need to be in Proc form:
|
37
50
|
```ruby
|
38
51
|
PlasticCup::Base.add_style_sheet(:login_title, {
|
data/Rakefile
CHANGED
data/lib/plastic_cup/base.rb
CHANGED
@@ -2,6 +2,8 @@ module PlasticCup
|
|
2
2
|
|
3
3
|
class Base
|
4
4
|
|
5
|
+
OSVersions = %w(all ios4 ios5 ios6 ios7)
|
6
|
+
|
5
7
|
def self.style(target, style)
|
6
8
|
if style.is_a?(Hash)
|
7
9
|
apply_properties(target, style)
|
@@ -20,12 +22,21 @@ module PlasticCup
|
|
20
22
|
target
|
21
23
|
end
|
22
24
|
|
23
|
-
def self.add_style_sheet(name, properties)
|
24
|
-
|
25
|
+
def self.add_style_sheet(name, properties, os_version=:all)
|
26
|
+
if OSVersions.include?(os_version.to_s)
|
27
|
+
styles[to_key(name)] ||= {}
|
28
|
+
styles[to_key(name)][os_version.to_sym] = Stylesheet.new(properties)
|
29
|
+
else
|
30
|
+
raise ArgumentError.new "OS version only accept #{OSVersions}"
|
31
|
+
end
|
25
32
|
end
|
26
33
|
|
27
34
|
def self.get_style_sheet(style)
|
28
|
-
|
35
|
+
version_string = UIDevice.currentDevice.systemVersion.split('.').first
|
36
|
+
if styles[to_key(style)].is_a?(Hash)
|
37
|
+
style_hash = styles[to_key(style)]["ios#{version_string}".to_sym]
|
38
|
+
style_hash ||= styles[to_key(style)][:all]
|
39
|
+
end
|
29
40
|
NSLog "WARNING: Style #{style} undefined." if style_hash.nil?
|
30
41
|
style_hash
|
31
42
|
end
|
data/lib/plastic_cup/version.rb
CHANGED
data/spec/base_spec.rb
CHANGED
@@ -87,6 +87,39 @@ describe 'PlasticCup::Base' do
|
|
87
87
|
style_sheet.properties.should == {text: 'My Text', textAlignment: 1}
|
88
88
|
style_sheet.extends.should == [:mother, :father]
|
89
89
|
end
|
90
|
+
|
91
|
+
describe 'os version' do
|
92
|
+
after do
|
93
|
+
UIDevice.currentDevice.reset(:systemVersion)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should add style sheet with specific os version' do
|
97
|
+
PlasticCup::Base.add_style_sheet(:my_style, {text: 'iOS 7 text'}, :ios7)
|
98
|
+
PlasticCup::Base.add_style_sheet(:my_style, {text: 'iOS 6 text'}, :ios6)
|
99
|
+
PlasticCup::Base.add_style_sheet(:my_style, {text: 'other iOS text'})
|
100
|
+
|
101
|
+
UIDevice.currentDevice.stub!(:systemVersion, return: '6.1')
|
102
|
+
style_sheet = PlasticCup::Base.get_style_sheet(:my_style)
|
103
|
+
style_sheet.properties.should == {text: 'iOS 6 text'}
|
104
|
+
|
105
|
+
UIDevice.currentDevice.stub!(:systemVersion, return: '7.0')
|
106
|
+
style_sheet = PlasticCup::Base.get_style_sheet(:my_style)
|
107
|
+
style_sheet.properties.should == {text: 'iOS 7 text'}
|
108
|
+
|
109
|
+
UIDevice.currentDevice.stub!(:systemVersion, return: '5.0')
|
110
|
+
style_sheet = PlasticCup::Base.get_style_sheet(:my_style)
|
111
|
+
style_sheet.properties.should == {text: 'other iOS text'}
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'add style sheet should raise error if os version not supported' do
|
116
|
+
lambda {
|
117
|
+
PlasticCup::Base.add_style_sheet(:my_style, {text: ''}, :ios1)
|
118
|
+
}.
|
119
|
+
should.raise(ArgumentError).
|
120
|
+
message.should.match(/OS version only accept /)
|
121
|
+
end
|
122
|
+
end
|
90
123
|
end
|
91
124
|
|
92
125
|
describe '#handler' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plastic_cup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- April Tsang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ! 'Plastic Cup is a simplified version of Teacup, aiming at memory leak
|
14
14
|
prevention.
|