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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDUyY2MzNDVkMGE0N2JhMGIyZmUyNWQ4MzU2MThiMmI5ZjU1MDZkNg==
4
+ NDg1MzVkMmY1NjhmMjAzNmRlZWU2NmY5MjQ0NDY3YTQ0N2NkOGQxOQ==
5
5
  data.tar.gz: !binary |-
6
- NDM3MWNhNTc4OTg2M2ZmYzEwMzU2MWQxMjA0MTM3OGIxOGNkOTcwMA==
6
+ YTE2ZDExNTMxNmUyMGIyOGNiZWRlZmEzNGI2MTI1Mjc3YjhmYjE0Nw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OTQ1N2ZiMDJkMmQ2YzhlNGRmMzlmY2RkOTdjZDIwNDI1NzUxZWQ5MjcxZTJj
10
- MTYxMmUyNmM1NzFhNDE3ZGI4MjQ1MGM3OTcyOGZhMDcxMDU3N2JlM2MxMjA1
11
- OGY0ZTIyMjE5NDA2NjE1YTIzMmIwMTRlMTRhMWU1ODk2MDFlYTY=
9
+ NTdiYmJmYjQ1OTIwYmI5ZWZiNzI0Y2Q1ZGQ2ZTE5MDFiZmQ1NjM3MjQ5MDJm
10
+ YTg2OGE1MGQ3ZmU1YjVmMzBiMTk2MTM2YzgzZjkzYzE0ZTU1MjM1Njg5MDZm
11
+ ZTk4M2QyN2I0NjlmYmUzNmQ5MmUxM2U0MmM1MzcxNTJhMjFlYmE=
12
12
  data.tar.gz: !binary |-
13
- Y2FkZDljMjllN2FhM2ZkNTE4OTNjYWQ5OWQ3N2U1YzA2Mzc4NTBlMDY5Nzgy
14
- ZTk5MGZiMzU3OWI2NTkxMDU0ZTM1ZDZjNDJmNDY1ZjdjZWY1NjU4MGM3YjM1
15
- ZGIzMGMxYjIyMmJiZTNhNDk0OWYzNGY4OWUyNjFiODFiOWU0Mzc=
13
+ YTBiNDk5ZDU4MWJlYWIxZTViOGZmM2NjNzI1ZWU3NGMwMGE1OWEyY2E2YTc4
14
+ YzljZDkxOGQxZDFkNDczYjVhNDk4ZDZlNmY1OTRkMWJmZGI2MGE2MTgwNGQ3
15
+ MWMyMzg5OGJjMjM3MzA0ZjQ4N2EwNzVhZDYzZTM5ZTg4MzBlZTg=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- plastic_cup (0.1.2)
4
+ plastic_cup (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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(:round_button, {
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(:green_button, {
31
- extends: :round_button,
30
+ PlasticCup::Base.add_style_sheet(:green_label, {
31
+ extends: :round_label,
32
32
  backgroundColor: UIColor.greenColor
33
33
  }
34
- @button = PlasticCup::Base.style(UIButton.new, :green_button)
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
 
@@ -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
- apply_properties(target, get_style_sheet_properties(style))
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
- apply_properties(target.send(key), value)
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
@@ -1,3 +1,3 @@
1
1
  module PlasticCup
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
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.2
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: 2014-05-13 00:00:00.000000000 Z
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.