plastic_cup 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile.lock +1 -1
- data/README.md +5 -5
- data/lib/plastic_cup/base.rb +13 -5
- data/lib/plastic_cup/version.rb +1 -1
- data/spec/base_spec.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDg1MzVkMmY1NjhmMjAzNmRlZWU2NmY5MjQ0NDY3YTQ0N2NkOGQxOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTE2ZDExNTMxNmUyMGIyOGNiZWRlZmEzNGI2MTI1Mjc3YjhmYjE0Nw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTdiYmJmYjQ1OTIwYmI5ZWZiNzI0Y2Q1ZGQ2ZTE5MDFiZmQ1NjM3MjQ5MDJm
|
10
|
+
YTg2OGE1MGQ3ZmU1YjVmMzBiMTk2MTM2YzgzZjkzYzE0ZTU1MjM1Njg5MDZm
|
11
|
+
ZTk4M2QyN2I0NjlmYmUzNmQ5MmUxM2U0MmM1MzcxNTJhMjFlYmE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTBiNDk5ZDU4MWJlYWIxZTViOGZmM2NjNzI1ZWU3NGMwMGE1OWEyY2E2YTc4
|
14
|
+
YzljZDkxOGQxZDFkNDczYjVhNDk4ZDZlNmY1OTRkMWJmZGI2MGE2MTgwNGQ3
|
15
|
+
MWMyMzg5OGJjMjM3MzA0ZjQ4N2EwNzVhZDYzZTM5ZTg4MzBlZTg=
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -22,16 +22,16 @@ PlasticCup::Base.add_style_sheet(:red_button, {
|
|
22
22
|
|
23
23
|
Style with extend Stylesheet
|
24
24
|
```ruby
|
25
|
-
PlasticCup::Base.add_style_sheet(:
|
25
|
+
PlasticCup::Base.add_style_sheet(:round_label, {
|
26
26
|
layer: {
|
27
27
|
cornerRadius: 8
|
28
28
|
}
|
29
29
|
})
|
30
|
-
PlasticCup::Base.add_style_sheet(:
|
31
|
-
extends: :
|
30
|
+
PlasticCup::Base.add_style_sheet(:green_label, {
|
31
|
+
extends: :round_label,
|
32
32
|
backgroundColor: UIColor.greenColor
|
33
33
|
}
|
34
|
-
@
|
34
|
+
@label = PlasticCup::Base.style(UILabel.new, :green_label)
|
35
35
|
```
|
36
36
|
|
37
37
|
Support different iOS versions
|
@@ -43,7 +43,7 @@ PlasticCup::Base.add_style_sheet(:bg_view, {
|
|
43
43
|
PlasticCup::Base.add_style_sheet(:bg_view, {
|
44
44
|
frame: CGRectMake(0, 20, 320, 200)
|
45
45
|
}, :ios7)
|
46
|
-
# supported symbols: :all, :ios4, :ios5, :ios6, :ios7
|
46
|
+
# supported symbols: :all, :ios4, :ios5, :ios6, :ios7, :ios8
|
47
47
|
# default is :all
|
48
48
|
```
|
49
49
|
|
data/lib/plastic_cup/base.rb
CHANGED
@@ -2,15 +2,19 @@ module PlasticCup
|
|
2
2
|
|
3
3
|
class Base
|
4
4
|
|
5
|
-
OSVersions = %w(all ios4 ios5 ios6 ios7)
|
5
|
+
OSVersions = %w(all ios4 ios5 ios6 ios7 ios8)
|
6
6
|
|
7
7
|
def self.style(target, style, other_style=nil)
|
8
8
|
if style.is_a?(Hash)
|
9
9
|
apply_properties(target, style)
|
10
|
-
elsif other_style.is_a?(Hash)
|
11
|
-
apply_properties(target, get_style_sheet_properties(style).merge(other_style))
|
12
10
|
else
|
13
|
-
|
11
|
+
extends = style.is_a?(Array) ? style : [style]
|
12
|
+
final_style = {}
|
13
|
+
extends.each do |ext|
|
14
|
+
final_style.merge!(get_style_sheet_properties(ext))
|
15
|
+
end
|
16
|
+
final_style.merge!(other_style) if other_style.is_a?(Hash)
|
17
|
+
apply_properties(target, final_style)
|
14
18
|
end
|
15
19
|
target
|
16
20
|
end
|
@@ -106,7 +110,11 @@ module PlasticCup
|
|
106
110
|
# you can send methods to subviews (e.g. UIButton#titleLabel) and CALayers
|
107
111
|
# (e.g. UIView#layer) by assigning a hash to a style name.
|
108
112
|
if value.is_a?(Hash)
|
109
|
-
|
113
|
+
if target.respondsToSelector(key) || target.respond_to?(key)
|
114
|
+
apply_properties(target.send(key), value)
|
115
|
+
else
|
116
|
+
NSLog "WARNING: undefined method '#{key}' for #{target.inspect}"
|
117
|
+
end
|
110
118
|
else
|
111
119
|
if key =~ /^set[A-Z]/
|
112
120
|
assign = nil
|
data/lib/plastic_cup/version.rb
CHANGED
data/spec/base_spec.rb
CHANGED
@@ -91,6 +91,17 @@ describe 'PlasticCup::Base' do
|
|
91
91
|
field.text.should == 'My Style Text'
|
92
92
|
field.placeholder.should == 'My placeholder'
|
93
93
|
end
|
94
|
+
|
95
|
+
it 'should support multiple additional styles' do
|
96
|
+
PlasticCup::Base.add_style_sheet(:father, {backgroundColor: UIColor.blueColor, numberOfLines: 18})
|
97
|
+
PlasticCup::Base.add_style_sheet(:mother, {backgroundColor: UIColor.redColor, textColor: UIColor.greenColor})
|
98
|
+
label = PlasticCup::Base.style(UILabel.new, [:father, :mother], text: 'My label', textColor: UIColor.grayColor)
|
99
|
+
|
100
|
+
label.backgroundColor.should == UIColor.redColor
|
101
|
+
label.numberOfLines.should == 18
|
102
|
+
label.textColor.should == UIColor.grayColor
|
103
|
+
label.text.should == 'My label'
|
104
|
+
end
|
94
105
|
end
|
95
106
|
|
96
107
|
describe '#add_style_sheet and #get_style_sheet' 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.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- April Tsang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-15 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.
|