teacup 1.2.5 → 1.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/teacup/constraint.rb +4 -4
- data/lib/teacup/merge_defaults.rb +0 -4
- data/lib/teacup/stylesheet_extensions/constraints.rb +2 -2
- data/lib/teacup/stylesheet_extensions/geometry.rb +17 -7
- data/lib/teacup/version.rb +1 -1
- data/lib/teacup/z_core_extensions/ui_view.rb +1 -1
- data/spec/stylesheet_spec.rb +34 -16
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/lib/teacup/constraint.rb
CHANGED
@@ -88,22 +88,22 @@ module Teacup
|
|
88
88
|
[
|
89
89
|
Teacup::Constraint.new(:self, :left).equals(relative_to, :left),
|
90
90
|
]
|
91
|
-
when :top_left
|
91
|
+
when :top_left, :topleft
|
92
92
|
[
|
93
93
|
Teacup::Constraint.new(:self, :left).equals(relative_to, :left),
|
94
94
|
Teacup::Constraint.new(:self, :top).equals(relative_to, :top),
|
95
95
|
]
|
96
|
-
when :top_right
|
96
|
+
when :top_right, :topright
|
97
97
|
[
|
98
98
|
Teacup::Constraint.new(:self, :right).equals(relative_to, :right),
|
99
99
|
Teacup::Constraint.new(:self, :top).equals(relative_to, :top),
|
100
100
|
]
|
101
|
-
when :bottom_right
|
101
|
+
when :bottom_right, :bottomright
|
102
102
|
[
|
103
103
|
Teacup::Constraint.new(:self, :right).equals(relative_to, :right),
|
104
104
|
Teacup::Constraint.new(:self, :bottom).equals(relative_to, :bottom),
|
105
105
|
]
|
106
|
-
when :bottom_left
|
106
|
+
when :bottom_left, :bottomleft
|
107
107
|
[
|
108
108
|
Teacup::Constraint.new(:self, :left).equals(relative_to, :left),
|
109
109
|
Teacup::Constraint.new(:self, :bottom).equals(relative_to, :bottom),
|
@@ -26,10 +26,6 @@ module Teacup
|
|
26
26
|
|
27
27
|
right.each do |key, value|
|
28
28
|
if not target.has_key? key
|
29
|
-
if value.is_a?(Hash)
|
30
|
-
# make a copy of the Hash
|
31
|
-
value = Teacup::merge_defaults!({}, value)
|
32
|
-
end
|
33
29
|
target[key] = value
|
34
30
|
elsif value.is_a?(Hash) and left[key].is_a?(Hash)
|
35
31
|
target[key] = Teacup::merge_defaults(left[key], value, (left==target ? left[key] : {}))
|
@@ -25,7 +25,7 @@ module Teacup
|
|
25
25
|
Teacup::Constraint.new(:self, :right).equals(:superview, :right).plus(x)
|
26
26
|
end
|
27
27
|
|
28
|
-
def constrain_center_x(x)
|
28
|
+
def constrain_center_x(x=0)
|
29
29
|
Teacup::Constraint.new(:self, :center_x).equals(:superview, :center_x).plus(x)
|
30
30
|
end
|
31
31
|
|
@@ -37,7 +37,7 @@ module Teacup
|
|
37
37
|
Teacup::Constraint.new(:self, :bottom).equals(:superview, :bottom).plus(y)
|
38
38
|
end
|
39
39
|
|
40
|
-
def constrain_center_y(y)
|
40
|
+
def constrain_center_y(y=0)
|
41
41
|
Teacup::Constraint.new(:self, :center_y).equals(:superview, :center_y).plus(y)
|
42
42
|
end
|
43
43
|
|
@@ -28,9 +28,15 @@ module Teacup
|
|
28
28
|
class Stylesheet
|
29
29
|
def iPhone ; 1 << 1 ; end
|
30
30
|
def iPhoneRetina ; 1 << 2 ; end
|
31
|
-
def
|
32
|
-
def
|
33
|
-
def
|
31
|
+
def iPhone4 ; 1 << 3 ; end
|
32
|
+
def iPhone35 ; 1 << 4 ; end
|
33
|
+
def iPad ; 1 << 5 ; end
|
34
|
+
def iPadRetina ; 1 << 6 ; end
|
35
|
+
|
36
|
+
def iPhone5
|
37
|
+
NSLog('TEACUP WARNING: iPhone5 method is deprecated in lieu of size-based method names (iPhone4, iPhone35)')
|
38
|
+
1 << 3
|
39
|
+
end
|
34
40
|
|
35
41
|
# returns the device size in points, regardless of status bar
|
36
42
|
def screen_size
|
@@ -50,11 +56,15 @@ module Teacup
|
|
50
56
|
@@this_device = 0
|
51
57
|
if UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPhone
|
52
58
|
@@this_device |= iPhone
|
53
|
-
|
59
|
+
|
60
|
+
if UIScreen.mainScreen.respond_to?(:scale) && UIScreen.mainScreen.scale == 2
|
54
61
|
@@this_device |= iPhoneRetina
|
55
|
-
|
56
|
-
|
57
|
-
|
62
|
+
end
|
63
|
+
|
64
|
+
if UIScreen.mainScreen.bounds.size.height == 568
|
65
|
+
@@this_device |= iPhone4
|
66
|
+
else
|
67
|
+
@@this_device |= iPhone35
|
58
68
|
end
|
59
69
|
else
|
60
70
|
@@this_device |= iPad
|
data/lib/teacup/version.rb
CHANGED
data/spec/stylesheet_spec.rb
CHANGED
@@ -51,7 +51,7 @@ describe "Teacup::Stylesheet" do
|
|
51
51
|
title: "Example!",
|
52
52
|
frame: [[0, 0], [100, 100]],
|
53
53
|
layer: {
|
54
|
-
|
54
|
+
borderWidth: 10,
|
55
55
|
opacity: 0.5
|
56
56
|
}
|
57
57
|
|
@@ -59,7 +59,7 @@ describe "Teacup::Stylesheet" do
|
|
59
59
|
backgroundColor: :blue,
|
60
60
|
frame: [[100, 100], [200, 200]],
|
61
61
|
layer: {
|
62
|
-
|
62
|
+
borderWidth: 20
|
63
63
|
}
|
64
64
|
end
|
65
65
|
end
|
@@ -73,8 +73,8 @@ describe "Teacup::Stylesheet" do
|
|
73
73
|
@stylesheet.query(:example_button)[:frame].should == [[100, 100], [200, 200]]
|
74
74
|
end
|
75
75
|
|
76
|
-
it 'should
|
77
|
-
@stylesheet.query(:example_button)[:layer][:
|
76
|
+
it 'should merge hashes' do
|
77
|
+
@stylesheet.query(:example_button)[:layer][:borderWidth].should == 20
|
78
78
|
@stylesheet.query(:example_button)[:layer][:opacity].should == 0.5
|
79
79
|
end
|
80
80
|
end
|
@@ -122,12 +122,19 @@ describe "Teacup::Stylesheet" do
|
|
122
122
|
import :importedbyname
|
123
123
|
|
124
124
|
style :label,
|
125
|
-
backgroundColor: :blue
|
125
|
+
backgroundColor: :blue,
|
126
|
+
layer: {
|
127
|
+
borderWidth: 2,
|
128
|
+
}
|
126
129
|
end
|
127
130
|
|
128
131
|
Teacup::Stylesheet.new(:importedbyname) do
|
129
132
|
style :label,
|
130
|
-
title: "Imported by name"
|
133
|
+
title: "Imported by name",
|
134
|
+
layer: {
|
135
|
+
borderWidth: 1,
|
136
|
+
borderColor: :red,
|
137
|
+
}
|
131
138
|
end
|
132
139
|
|
133
140
|
@name_importer = Teacup::Stylesheet.new do
|
@@ -167,6 +174,11 @@ describe "Teacup::Stylesheet" do
|
|
167
174
|
@oo_name_importer.query(:label)[:backgroundColor].should == :blue
|
168
175
|
end
|
169
176
|
|
177
|
+
it 'should merge properties' do
|
178
|
+
@oo_name_importer.query(:label)[:layer][:borderWidth].should == 2
|
179
|
+
@oo_name_importer.query(:label)[:layer][:borderColor].should == :red
|
180
|
+
end
|
181
|
+
|
170
182
|
it 'should work with a value' do
|
171
183
|
imported_anonymously = Teacup::Stylesheet.new do
|
172
184
|
style :label,
|
@@ -214,7 +226,7 @@ describe "Teacup::Stylesheet" do
|
|
214
226
|
import :most_generic
|
215
227
|
|
216
228
|
style :label,
|
217
|
-
|
229
|
+
borderWidth: 10,
|
218
230
|
title: "Stylesheet"
|
219
231
|
end
|
220
232
|
|
@@ -227,9 +239,15 @@ describe "Teacup::Stylesheet" do
|
|
227
239
|
end
|
228
240
|
end
|
229
241
|
|
242
|
+
after do
|
243
|
+
Teacup::Stylesheet.stylesheets.delete(:most_generic)
|
244
|
+
Teacup::Stylesheet.stylesheets.delete(:stylesheet)
|
245
|
+
Teacup::Stylesheet.stylesheets.delete(:most_specific)
|
246
|
+
end
|
247
|
+
|
230
248
|
it 'should union different properties for the same rule' do
|
231
249
|
@stylesheet.query(:label)[:backgroundColor].should == :blue
|
232
|
-
@stylesheet.query(:label)[:
|
250
|
+
@stylesheet.query(:label)[:borderWidth] == 10
|
233
251
|
end
|
234
252
|
|
235
253
|
it 'should give the importer precedence' do
|
@@ -239,7 +257,7 @@ describe "Teacup::Stylesheet" do
|
|
239
257
|
it 'should follow chains of imports' do
|
240
258
|
@most_specific.query(:label)[:title].should == "Most specific"
|
241
259
|
@most_specific.query(:label)[:font].should == "IMPACT"
|
242
|
-
@most_specific.query(:label)[:
|
260
|
+
@most_specific.query(:label)[:borderWidth].should == 10
|
243
261
|
@most_specific.query(:label)[:backgroundColor].should == :blue
|
244
262
|
end
|
245
263
|
|
@@ -295,13 +313,13 @@ describe "Teacup::Stylesheet" do
|
|
295
313
|
backgroundColor: :blue
|
296
314
|
|
297
315
|
style :my_textfield, extends: [:textfield, :input],
|
298
|
-
|
316
|
+
borderWidth: 10
|
299
317
|
end
|
300
318
|
|
301
319
|
stylesheet.query(:my_textfield)[:text].should == "Extended"
|
302
320
|
stylesheet.query(:my_textfield)[:backgroundColor].should == :blue
|
303
321
|
stylesheet.query(:my_textfield)[:origin].should == [0, 0]
|
304
|
-
stylesheet.query(:my_textfield)[:
|
322
|
+
stylesheet.query(:my_textfield)[:borderWidth].should == 10
|
305
323
|
end
|
306
324
|
|
307
325
|
it 'should give precedence to imported rules over extended rules' do
|
@@ -311,7 +329,7 @@ describe "Teacup::Stylesheet" do
|
|
311
329
|
backgroundColor: :blue
|
312
330
|
|
313
331
|
style :my_textfield, extends: :textfield,
|
314
|
-
|
332
|
+
borderWidth: 10
|
315
333
|
|
316
334
|
import Teacup::Stylesheet.new{
|
317
335
|
style :my_textfield,
|
@@ -321,7 +339,7 @@ describe "Teacup::Stylesheet" do
|
|
321
339
|
|
322
340
|
stylesheet.query(:my_textfield)[:text].should == "Imported"
|
323
341
|
stylesheet.query(:my_textfield)[:backgroundColor].should == :blue
|
324
|
-
stylesheet.query(:my_textfield)[:
|
342
|
+
stylesheet.query(:my_textfield)[:borderWidth].should == 10
|
325
343
|
end
|
326
344
|
|
327
345
|
it 'should import rules using a deep merge strategy' do
|
@@ -329,19 +347,19 @@ describe "Teacup::Stylesheet" do
|
|
329
347
|
import Teacup::Stylesheet.new{
|
330
348
|
style :my_textfield,
|
331
349
|
layer: {
|
332
|
-
|
350
|
+
borderWidth: 1,
|
333
351
|
opacity: 0.5
|
334
352
|
}
|
335
353
|
}
|
336
354
|
|
337
355
|
style :my_textfield,
|
338
356
|
layer: {
|
339
|
-
|
357
|
+
borderWidth: 10
|
340
358
|
}
|
341
359
|
end
|
342
360
|
|
343
361
|
stylesheet.query(:my_textfield)[:layer][:opacity].should == 0.5
|
344
|
-
stylesheet.query(:my_textfield)[:layer][:
|
362
|
+
stylesheet.query(:my_textfield)[:layer][:borderWidth].should == 10
|
345
363
|
end
|
346
364
|
|
347
365
|
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.7
|
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-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|