teacup 1.2.3 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +39 -0
- data/lib/dummy.rb +6 -0
- data/lib/teacup/version.rb +1 -1
- data/lib/teacup/z_core_extensions/ui_view.rb +2 -2
- data/lib/teacup/z_core_extensions/z_handlers.rb +21 -0
- data/spec/gradient_spec.rb +32 -0
- metadata +5 -2
data/README.md
CHANGED
@@ -29,6 +29,45 @@ gems on a per-project basis, using a gemset. See the
|
|
29
29
|
[rvm]: https://rvm.io/
|
30
30
|
[Installation]: https://github.com/rubymotion/teacup/wiki/Installation
|
31
31
|
|
32
|
+
#### 10 second primer
|
33
|
+
|
34
|
+
1. Create a `UIViewController` subclass:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
class MyController < UIViewController
|
38
|
+
```
|
39
|
+
2. Assign a stylesheet name:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
class MyController < UIViewController
|
43
|
+
stylesheet :main_screen
|
44
|
+
```
|
45
|
+
3. Create a layout:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
class MyController < UIViewController
|
49
|
+
stylesheet :main_screen
|
50
|
+
|
51
|
+
layout do
|
52
|
+
subview(UIButton, :finished_button)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
```
|
56
|
+
4. Create the stylesheet
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
Teacup::Stylesheet.new :main_screen do
|
60
|
+
style :finished_button,
|
61
|
+
origin: [10, 10],
|
62
|
+
title: 'Hi!'
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
|
+
Teacup implements the `viewDidLoad` method and instantiates any views you
|
67
|
+
declare in the `layout` block. Make sure to call `super` if you implement
|
68
|
+
`viewDidLoad`, or you can use the "teacup-esque" `layoutDidLoad` method.
|
69
|
+
|
70
|
+
|
32
71
|
#### Showdown
|
33
72
|
|
34
73
|
Cocoa
|
data/lib/dummy.rb
CHANGED
data/lib/teacup/version.rb
CHANGED
@@ -205,7 +205,7 @@ class UIView
|
|
205
205
|
UIView.beginAnimations(nil, context: nil)
|
206
206
|
UIView.setAnimationDuration(style[:duration]) if style[:duration]
|
207
207
|
UIView.setAnimationCurve(style[:curve]) if style[:curve]
|
208
|
-
UIView.setAnimationDelay(
|
208
|
+
UIView.setAnimationDelay(style[:delay]) if style[:delay]
|
209
209
|
style(style)
|
210
210
|
UIView.commitAnimations
|
211
211
|
end
|
@@ -223,7 +223,7 @@ class UIView
|
|
223
223
|
# a warning message will be emitted.
|
224
224
|
#
|
225
225
|
# @param Hash the properties to set.
|
226
|
-
def style(properties
|
226
|
+
def style(properties)
|
227
227
|
if properties.key?(:constraints)
|
228
228
|
add_uniq_constraints(properties.delete(:constraints))
|
229
229
|
end
|
@@ -93,6 +93,27 @@ Teacup.handler UIView, :frame { |frame|
|
|
93
93
|
self.frame = frame
|
94
94
|
}
|
95
95
|
|
96
|
+
Teacup.handler UIView, :gradient { |gradient|
|
97
|
+
gradient_layer = self.instance_variable_get(:@gradient_layer) || begin
|
98
|
+
gradient_layer = CAGradientLayer.layer
|
99
|
+
gradient_layer.frame = self.bounds
|
100
|
+
self.layer.insertSublayer(gradient_layer, atIndex:0)
|
101
|
+
gradient_layer
|
102
|
+
end
|
103
|
+
|
104
|
+
gradient.each do |key, value|
|
105
|
+
case key.to_s
|
106
|
+
when 'colors'
|
107
|
+
colors = [value].flatten.collect { |color| color.is_a?(UIColor) ? color.CGColor : color }
|
108
|
+
gradient_layer.colors = colors
|
109
|
+
else
|
110
|
+
gradient_layer.send("#{key}=", value)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
self.instance_variable_set(:@gradient_layer, gradient_layer)
|
115
|
+
}
|
116
|
+
|
96
117
|
##|
|
97
118
|
##| UIButton
|
98
119
|
##|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
describe "Gradient" do
|
2
|
+
tests FirstController
|
3
|
+
|
4
|
+
before do
|
5
|
+
@root_view = window.subviews[0]
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should insert gradient layer when gradient style is set" do
|
9
|
+
@root_view.style(gradient: { colors: [UIColor.redColor, UIColor.yellowColor] })
|
10
|
+
@root_view.layer.sublayers.size.should == 2
|
11
|
+
@root_view.layer.sublayers.first.class.should == CAGradientLayer
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should not insert another gradient layer when gradient style is changed" do
|
15
|
+
@root_view.style(gradient: { colors: [UIColor.redColor, UIColor.yellowColor] })
|
16
|
+
@root_view.style(gradient: { colors: [UIColor.greenColor, UIColor.whiteColor] })
|
17
|
+
@root_view.layer.sublayers.size.should == 2
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should change gradient layer when gradient style is changed" do
|
21
|
+
@root_view.style(gradient: { colors: [UIColor.redColor, UIColor.yellowColor] })
|
22
|
+
before = @root_view.layer.sublayers.first.colors.first
|
23
|
+
@root_view.style(gradient: { colors: [UIColor.greenColor, UIColor.whiteColor] })
|
24
|
+
after = @root_view.layer.sublayers.first.colors.first
|
25
|
+
before.should != after
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should accept CGColors" do
|
29
|
+
@root_view.style(gradient: { colors: [UIColor.redColor.CGColor, UIColor.yellowColor.CGColor] })
|
30
|
+
@root_view.layer.sublayers.size.should == 2
|
31
|
+
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: teacup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -103,6 +103,7 @@ files:
|
|
103
103
|
- samples/Hai/styles/iphone.rb
|
104
104
|
- samples/README.md
|
105
105
|
- spec/custom_class_spec.rb
|
106
|
+
- spec/gradient_spec.rb
|
106
107
|
- spec/main_spec.rb
|
107
108
|
- spec/style_spec.rb
|
108
109
|
- spec/stylesheet_spec.rb
|
@@ -134,7 +135,9 @@ specification_version: 3
|
|
134
135
|
summary: A community-driven DSL for creating user interfaces on iOS.
|
135
136
|
test_files:
|
136
137
|
- spec/custom_class_spec.rb
|
138
|
+
- spec/gradient_spec.rb
|
137
139
|
- spec/main_spec.rb
|
138
140
|
- spec/style_spec.rb
|
139
141
|
- spec/stylesheet_spec.rb
|
140
142
|
- spec/view_spec.rb
|
143
|
+
has_rdoc:
|