plastic_cup 0.0.2 → 0.1.0

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
- NDNlZGZkMThkNzQwMmE0ZjU3OTU0M2RkNWI0NTljNGYzZDlkZGZiZg==
4
+ OGI3ODk4MmZmMmM2MzYzYTk5ZmJlOGJiYmQ4YmVlZDU4YjM4YTFmYg==
5
5
  data.tar.gz: !binary |-
6
- NTNmMmI5M2QwZWM2NGY1YmZhNTU5YTNkZTFlMGY2OTJjZjlkMWVlZg==
6
+ NThhNDRiNWY5NzVmMTczZmZiOTZjMDVlMjNmZDc4YzhjMDQwYmFhZA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NmM3ZDhkNmQzNjczOWI4ZjcwZDdmMjM3Njg3MTUxNjBiN2IxMWU4ODA1Mzk0
10
- YTgxMjk5M2MyNTlkMGNkM2YzNjZkOGQ0Y2VkY2Y1OGY3NmRjODA5MjZmYmVl
11
- OGFkNjQ2YzY0YjVlZmE2ZWIwNTY5Zjc3ZWY1YzRjMWJkNWJjOWY=
9
+ YjVmN2ZjYjVlNDcyYzU0MGJhMmQ3NGY2YzAwYzA5N2RkMTliNjY3ZDNiOGJj
10
+ ZjVlOWYzNzQxNjhlOTUwODQ4MmE2ZDIyN2JjMWMwMzg5MTBiMTE1M2QzMTI1
11
+ YmFjODlmMmRmMjgyYjdiOGRjODQ0ZjU5OWE4OTg3NDQzNTYyMWQ=
12
12
  data.tar.gz: !binary |-
13
- NmI5NTgxNWVhMTMwODNhNWNlMGJjYjlhZjQ1MDdmZDkyM2I3YTVlMmVjZWZm
14
- ZTgzMzFiNGZlM2RkZDY1N2Y5MzYyM2Y2M2VmMzEwOWNiZWFkYWJlMTY4NThi
15
- NTcyY2RmZjEwNzVhZDE0MTU0ZjExODZlMjUzYTBhYzdiN2E3NDA=
13
+ MDcwYWQ4NzczZTIxZmVmZWJhM2U0ZjdlZDhhODRiZjllMmJlODE2ZWJmZTkx
14
+ NmMzNDg2MWMxZWNjOGY5MTlkMzM0MDdiNjZiOGRlZDU2YzZhMzdiMGY0NTY3
15
+ N2Q2Y2FhMGE1MTBkNzNmYmYwNjQzMGJlMjFjYjYxNTk3MWQ4MmU=
data/Gemfile CHANGED
@@ -2,6 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  group :test, :development do
4
4
  gem 'rake'
5
+ gem 'motion-stump'
5
6
  end
6
7
 
7
8
  gemspec
data/Gemfile.lock CHANGED
@@ -1,16 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- plastic_cup (0.0.2)
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
@@ -8,6 +8,7 @@ else
8
8
  end
9
9
  require 'bundler'
10
10
  Bundler.require
11
+ require 'motion-stump'
11
12
 
12
13
  Motion::Project::App.setup do |app|
13
14
  # Use `rake config' to see complete project settings.
@@ -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
- styles[to_key(name)] = Stylesheet.new(properties)
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
- style_hash = styles[to_key(style)]
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
@@ -1,3 +1,3 @@
1
1
  module PlasticCup
2
- VERSION = '0.0.2'
2
+ VERSION = '0.1.0'
3
3
  end
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.2
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-08-21 00:00:00.000000000 Z
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.