motion-kit 0.11.1 → 0.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a28612bd72f42867be9f7a5dc6e8d03f9c89ef2
4
- data.tar.gz: 0aba2379868df670e26807df6d48ccbfbe6a6aa1
3
+ metadata.gz: 178a4a8d53c639db16f7d73765521a9ee5b220b5
4
+ data.tar.gz: bd48860c5baff3f5ee0543c28426b6c2d63e09f5
5
5
  SHA512:
6
- metadata.gz: ab2048fbca5054345ec6323b25c9e3a689261f4592f579346bbb638359063e37b3d81c63ac15db092dc3da012ace33753c54e1abb2284d5846ef19e9bc4266c1
7
- data.tar.gz: 6f4ddbb452f81897d06f80302167ea9141924755637c054e9bcd34555df0e9c1a4667554d439cf8d7f27136c69d357dfa4d1eb60f82b7921af6a1626900e182b
6
+ metadata.gz: b8b0dd1b76e3875e5aa86dddf9d2e56862b3f5954e7ef33413ad430750a0b3a0565e56355597c9428ac5d322d17c593c48d009a157a6adff10ec1c01567a3706
7
+ data.tar.gz: 368ac319ec7994a9a7623ea6c4149c61372f9f087041cc77b6f4b2830f1d1a1d176b467e59fe7bef026c393fddc51ad064b53b18865a4ef6b907b670f991ba0e
data/README.md CHANGED
@@ -422,9 +422,17 @@ module MotionKit
422
422
  end
423
423
  ```
424
424
 
425
- For your own custom classes, or built-in classes that don't already have a
426
- `Layout` class defined, you can provide a Layout class by calling the `targets`
427
- method in your class body.
425
+ ### Adding your own helper methods
426
+
427
+ For your own custom classes, or when you want to write
428
+ helper methods for a built-in class, you will need to write a class that
429
+ "`targets`" that class. This will be a subclass of `MK::UIViewLayout`; it looks
430
+ and *feels* like a `MK::Layout` subclass, but these classes are used to extend
431
+ the MotionKit DSL, and should not be instantiated or used to build layouts.
432
+
433
+ Again, to be clear: you should be subclassing `MK::Layout` when you build your
434
+ controller layouts, and you should write a subclass of `MK::UIViewLayout` *only*
435
+ when you are adding extensions to the MotionKit DSL.
428
436
 
429
437
  ```ruby
430
438
  # Be sure to extend an existing Layout class, otherwise you'll lose a lot of
@@ -59,6 +59,8 @@ module MotionKit
59
59
  # <=, and >=
60
60
  #
61
61
  # @example
62
+ # x.is(10)
63
+ # x.is(10).priority(:required)
62
64
  # x.is == 10
63
65
  # (x.is == 10).priority :required
64
66
  # width.is >= 100
@@ -83,7 +85,7 @@ module MotionKit
83
85
 
84
86
  def >=(compare)
85
87
  if @compare_flag
86
- if @relationship && Constraint.relationship_lookup(@relationship) != NSLayoutRelationEqual
88
+ if @relationship && Constraint.relationship_lookup(@relationship) != NSLayoutRelationGreaterThanOrEqual
87
89
  raise InvalidRelationshipError.new("You cannot use `.is >=` on a constraint that is already defined as #{@relationship}")
88
90
  end
89
91
 
@@ -97,7 +99,7 @@ module MotionKit
97
99
 
98
100
  def <=(compare)
99
101
  if @compare_flag
100
- if @relationship && Constraint.relationship_lookup(@relationship) != NSLayoutRelationEqual
102
+ if @relationship && Constraint.relationship_lookup(@relationship) != NSLayoutRelationLessThanOrEqual
101
103
  raise InvalidRelationshipError.new("You cannot use `.is <=` on a constraint that is already defined as #{@relationship}")
102
104
  end
103
105
 
@@ -249,12 +251,15 @@ module MotionKit
249
251
  @resolved ||= begin
250
252
  item = Constraint.view_lookup(layout, view, self.target)
251
253
  rel_item = Constraint.view_lookup(layout, view, self.relative_to)
254
+ relationship = Constraint.relationship_lookup(self.relationship)
255
+ attribute1 = Constraint.attribute_lookup(self.attribute)
256
+ attribute2 = Constraint.attribute_lookup(self.attribute2)
252
257
 
253
258
  nsconstraint = NSLayoutConstraint.constraintWithItem(item,
254
- attribute: Constraint.attribute_lookup(self.attribute),
255
- relatedBy: Constraint.relationship_lookup(self.relationship),
259
+ attribute: attribute1,
260
+ relatedBy: relationship,
256
261
  toItem: rel_item,
257
- attribute: Constraint.attribute_lookup(self.attribute2),
262
+ attribute: attribute2,
258
263
  multiplier: self.multiplier,
259
264
  constant: self.constant
260
265
  )
@@ -552,13 +557,15 @@ module MotionKit
552
557
  @resolved ||= begin
553
558
  item = Constraint.view_lookup(layout, view, self.target)
554
559
  rel_item = Constraint.view_lookup(layout, view, self.relative_to)
560
+ relationship = Constraint.relationship_lookup(self.relationship)
555
561
 
556
- [[:width, 0], [:height, 1]].map do |attribute, index|
562
+ [[:width, 0], [:height, 1]].map do |attr_name, index|
563
+ attribute = Constraint.attribute_lookup(attr_name)
557
564
  nsconstraint = NSLayoutConstraint.constraintWithItem(item,
558
- attribute: Constraint.attribute_lookup(attribute),
559
- relatedBy: Constraint.relationship_lookup(self.relationship),
565
+ attribute: attribute,
566
+ relatedBy: relationship,
560
567
  toItem: rel_item,
561
- attribute: Constraint.attribute_lookup(attribute),
568
+ attribute: attribute,
562
569
  multiplier: self.multiplier[index],
563
570
  constant: self.constant[index]
564
571
  )
@@ -732,17 +739,20 @@ module MotionKit
732
739
  @resolved ||= begin
733
740
  item = Constraint.view_lookup(layout, view, self.target)
734
741
  rel_item = Constraint.view_lookup(layout, view, self.relative_to)
742
+ relationship = Constraint.relationship_lookup(self.relationship)
735
743
 
736
744
  [0, 1].map do |index|
737
745
  attribute = Constraint.attribute_lookup(self.attribute[index])
746
+ mul = self.multiplier[index]
747
+ const = self.constant[index]
738
748
 
739
749
  nsconstraint = NSLayoutConstraint.constraintWithItem(item,
740
750
  attribute: attribute,
741
- relatedBy: Constraint.relationship_lookup(self.relationship),
751
+ relatedBy: relationship,
742
752
  toItem: rel_item,
743
753
  attribute: attribute,
744
- multiplier: self.multiplier[index],
745
- constant: self.constant[index]
754
+ multiplier: mul,
755
+ constant: const
746
756
  )
747
757
 
748
758
  if self.priority
@@ -22,7 +22,7 @@ module MotionKit
22
22
  ConstraintPlaceholder.new(:nth, name, value)
23
23
  end
24
24
 
25
- def x(value=nil, rel=:equal)
25
+ def x(value=nil, rel=nil)
26
26
  target_constraint(:left, rel, value)
27
27
  end
28
28
  alias left x
@@ -37,7 +37,7 @@ module MotionKit
37
37
  end
38
38
  alias max_left max_x
39
39
 
40
- def leading(value=nil, rel=:equal)
40
+ def leading(value=nil, rel=nil)
41
41
  target_constraint(:leading, rel, value)
42
42
  end
43
43
 
@@ -49,7 +49,7 @@ module MotionKit
49
49
  leading(value, :lte)
50
50
  end
51
51
 
52
- def center_x(value=nil, rel=:equal)
52
+ def center_x(value=nil, rel=nil)
53
53
  target_constraint(:center_x, rel, value)
54
54
  end
55
55
 
@@ -61,7 +61,7 @@ module MotionKit
61
61
  center_x(value, :lte)
62
62
  end
63
63
 
64
- def right(value=nil, rel=:equal)
64
+ def right(value=nil, rel=nil)
65
65
  target_constraint(:right, rel, value)
66
66
  end
67
67
 
@@ -73,7 +73,7 @@ module MotionKit
73
73
  right(value, :lte)
74
74
  end
75
75
 
76
- def trailing(value=nil, rel=:equal)
76
+ def trailing(value=nil, rel=nil)
77
77
  target_constraint(:trailing, rel, value)
78
78
  end
79
79
 
@@ -85,7 +85,7 @@ module MotionKit
85
85
  trailing(value, :lte)
86
86
  end
87
87
 
88
- def y(value=nil, rel=:equal)
88
+ def y(value=nil, rel=nil)
89
89
  target_constraint(:top, rel, value)
90
90
  end
91
91
  alias top y
@@ -100,7 +100,7 @@ module MotionKit
100
100
  end
101
101
  alias max_top max_y
102
102
 
103
- def center_y(value=nil, rel=:equal)
103
+ def center_y(value=nil, rel=nil)
104
104
  target_constraint(:center_y, rel, value)
105
105
  end
106
106
 
@@ -112,7 +112,7 @@ module MotionKit
112
112
  center_y(value, :lte)
113
113
  end
114
114
 
115
- def bottom(value=nil, rel=:equal)
115
+ def bottom(value=nil, rel=nil)
116
116
  target_constraint(:bottom, rel, value)
117
117
  end
118
118
 
@@ -124,7 +124,7 @@ module MotionKit
124
124
  bottom(value, :lte)
125
125
  end
126
126
 
127
- def baseline(value=nil, rel=:equal)
127
+ def baseline(value=nil, rel=nil)
128
128
  target_constraint(:baseline, rel, value)
129
129
  end
130
130
 
@@ -136,7 +136,7 @@ module MotionKit
136
136
  baseline(value, :lte)
137
137
  end
138
138
 
139
- def width(value=nil, rel=:equal)
139
+ def width(value=nil, rel=nil)
140
140
  target_constraint(:width, rel, value)
141
141
  end
142
142
  alias w width
@@ -149,7 +149,7 @@ module MotionKit
149
149
  width(value, :lte)
150
150
  end
151
151
 
152
- def height(value=nil, rel=:equal)
152
+ def height(value=nil, rel=nil)
153
153
  target_constraint(:height, :equal, value)
154
154
  end
155
155
  alias h height
@@ -162,7 +162,7 @@ module MotionKit
162
162
  target_constraint(:height, :lte, value)
163
163
  end
164
164
 
165
- def size(value=nil, rel=:equal)
165
+ def size(value=nil, rel=nil)
166
166
  target_constraint(:size, rel, value, SizeConstraint)
167
167
  end
168
168
 
@@ -174,7 +174,7 @@ module MotionKit
174
174
  size(value, :lte)
175
175
  end
176
176
 
177
- def center(value=nil, rel=:equal)
177
+ def center(value=nil, rel=nil)
178
178
  target_constraint([:center_x, :center_y], rel, value, PointConstraint)
179
179
  end
180
180
 
@@ -186,7 +186,7 @@ module MotionKit
186
186
  center(value, :lte)
187
187
  end
188
188
 
189
- def top_left(value=nil, rel=:equal)
189
+ def top_left(value=nil, rel=nil)
190
190
  target_constraint([:left, :top], rel, value, PointConstraint)
191
191
  end
192
192
  alias origin top_left
@@ -201,7 +201,7 @@ module MotionKit
201
201
  end
202
202
  alias max_origin max_top_left
203
203
 
204
- def top_right(value=nil, rel=:equal)
204
+ def top_right(value=nil, rel=nil)
205
205
  target_constraint([:right, :top], rel, value, PointConstraint)
206
206
  end
207
207
 
@@ -213,7 +213,7 @@ module MotionKit
213
213
  top_right(value, :lte)
214
214
  end
215
215
 
216
- def bottom_left(value=nil, rel=:equal)
216
+ def bottom_left(value=nil, rel=nil)
217
217
  target_constraint([:left, :bottom], rel, value, PointConstraint)
218
218
  end
219
219
 
@@ -225,7 +225,7 @@ module MotionKit
225
225
  bottom_left(value, :lte)
226
226
  end
227
227
 
228
- def bottom_right(value=nil, rel=:equal)
228
+ def bottom_right(value=nil, rel=nil)
229
229
  target_constraint([:right, :bottom], rel, value, PointConstraint)
230
230
  end
231
231
 
@@ -179,23 +179,40 @@ module MotionKit
179
179
  def objc_version(method_name, args)
180
180
  if method_name.count(':') > 1
181
181
  objc_method_name = method_name
182
- objc_method_args = [args[0]].concat args[1].values
183
182
  elsif args.length == 2 && args[1].is_a?(Hash) && !args[1].empty?
184
183
  objc_method_name = "#{method_name}:#{args[1].keys.join(':')}:"
184
+ else
185
+ return nil, nil
186
+ end
187
+
188
+ if args[1].is_a?(Hash)
185
189
  objc_method_args = [args[0]].concat args[1].values
186
190
  else
187
- objc_method_name = nil
188
- objc_method_args = nil
191
+ objc_method_args = args
189
192
  end
193
+
190
194
  return objc_method_name, objc_method_args
191
195
  end
192
196
 
193
- def ruby_version(method_name)
197
+ def ruby_version(method_name, args)
194
198
  if method_name.count(':') > 1
195
- method_name.split(':').first
199
+ parts = method_name.split(':')
200
+ ruby_method_name = parts.first
201
+ if args[1].is_a?(Hash)
202
+ ruby_method_args = args
203
+ else
204
+ keys = parts[1..-1].map(&:to_sym)
205
+ ruby_method_args = [args[0]] << Hash[keys.zip args[1..-1]]
206
+ end
207
+ elsif method_name.count(':') == 1
208
+ ruby_method_name = method_name.split(':').first
209
+ ruby_method_args = args
196
210
  else
197
- method_name
211
+ ruby_method_name = method_name
212
+ ruby_method_args = args
198
213
  end
214
+
215
+ return ruby_method_name, ruby_method_args
199
216
  end
200
217
 
201
218
  # Tries to call the setter (`foo 'value'` => `view.setFoo('value')`), or
@@ -218,7 +235,7 @@ module MotionKit
218
235
  end
219
236
 
220
237
  objc_method_name, objc_method_args = objc_version(method_name, args)
221
- ruby_method_name = ruby_version(method_name)
238
+ ruby_method_name, ruby_method_args = ruby_version(method_name, args)
222
239
 
223
240
  @layout_delegate ||= Layout.layout_for(target.class)
224
241
  if @layout_delegate
@@ -226,7 +243,7 @@ module MotionKit
226
243
  if objc_method_name && @layout_delegate.respond_to?(objc_method_name)
227
244
  return @layout_delegate.send(objc_method_name, *objc_method_args, &block)
228
245
  elsif @layout_delegate.respond_to?(ruby_method_name)
229
- return @layout_delegate.send(ruby_method_name, *args, &block)
246
+ return @layout_delegate.send(ruby_method_name, *ruby_method_args, &block)
230
247
  end
231
248
  end
232
249
 
@@ -239,13 +256,13 @@ module MotionKit
239
256
 
240
257
  def apply_with_context(method_name, *args, &block)
241
258
  objc_method_name, objc_method_args = objc_version(method_name, args)
242
- ruby_method_name = ruby_version(method_name)
259
+ ruby_method_name, ruby_method_args = ruby_version(method_name, args)
243
260
 
244
261
  if objc_method_name && target.respond_to?(objc_method_name)
245
262
  new_context = target.send(objc_method_name, *objc_method_args)
246
263
  self.context(new_context, &block)
247
264
  elsif target.respond_to?(ruby_method_name)
248
- new_context = target.send(ruby_method_name, *args)
265
+ new_context = target.send(ruby_method_name, *ruby_method_args)
249
266
  self.context(new_context, &block)
250
267
  elsif ruby_method_name.include?('_')
251
268
  objc_name = MotionKit.objective_c_method_name(ruby_method_name)
@@ -257,7 +274,7 @@ module MotionKit
257
274
 
258
275
  def apply_with_target(method_name, *args, &block)
259
276
  objc_method_name, objc_method_args = objc_version(method_name, args)
260
- ruby_method_name = ruby_version(method_name)
277
+ ruby_method_name, ruby_method_args = ruby_version(method_name, args)
261
278
 
262
279
  setter = MotionKit.setter(ruby_method_name)
263
280
  assign = "#{ruby_method_name}="
@@ -272,13 +289,13 @@ module MotionKit
272
289
  if objc_method_name && target.respond_to?(objc_method_name)
273
290
  target.send(objc_method_name, *objc_method_args, &block)
274
291
  elsif args.empty? && target.respond_to?(ruby_method_name)
275
- target.send(ruby_method_name, *args, &block)
292
+ target.send(ruby_method_name, *ruby_method_args, &block)
276
293
  elsif target.respond_to?(setter)
277
294
  target.send(setter, *args, &block)
278
295
  elsif target.respond_to?(assign)
279
296
  target.send(assign, *args, &block)
280
297
  elsif target.respond_to?(ruby_method_name)
281
- target.send(ruby_method_name, *args, &block)
298
+ target.send(ruby_method_name, *ruby_method_args, &block)
282
299
  # UIAppearance classes are a whole OTHER thing; they never return 'true'
283
300
  elsif target.is_a?(MotionKit.appearance_class)
284
301
  target.send(setter, *args, &block)
@@ -1,3 +1,3 @@
1
1
  module MotionKit
2
- VERSION = '0.11.1'
2
+ VERSION = '0.11.2'
3
3
  end
@@ -4,6 +4,7 @@ describe CALayer do
4
4
  end
5
5
 
6
6
  it 'should style a CALayer' do
7
+ 1.should == 1
7
8
  end
8
9
 
9
10
  end
@@ -3,12 +3,14 @@ describe 'Constraints - Center helpers' do
3
3
  before do
4
4
  @layout = MK::Layout.new
5
5
  @constraint = nil
6
- @view = nil
6
+ @view = UIView.new
7
+ @parent_view = UIView.new
8
+ @parent_view.addSubview(@view)
7
9
  @another_view = nil
8
10
  end
9
11
 
10
12
  it 'should support `center [10, 10]`' do
11
- @view = @layout.context(UIView.new) do
13
+ @layout.context(@view) do
12
14
  @layout.constraints do
13
15
  @constraint = @layout.center([10, 10])
14
16
  end
@@ -26,21 +28,21 @@ describe 'Constraints - Center helpers' do
26
28
  resolved[0].firstItem.should == @view
27
29
  resolved[0].firstAttribute.should == NSLayoutAttributeCenterX
28
30
  resolved[0].relation.should == NSLayoutRelationEqual
29
- resolved[0].secondItem.should == nil
30
- resolved[0].secondAttribute.should == NSLayoutAttributeNotAnAttribute
31
+ resolved[0].secondItem.should == @parent_view
32
+ resolved[0].secondAttribute.should == NSLayoutAttributeCenterX
31
33
  resolved[0].multiplier.should == 1
32
34
  resolved[0].constant.should == 10
33
35
 
34
36
  resolved[1].firstItem.should == @view
35
37
  resolved[1].firstAttribute.should == NSLayoutAttributeCenterY
36
38
  resolved[1].relation.should == NSLayoutRelationEqual
37
- resolved[1].secondItem.should == nil
38
- resolved[1].secondAttribute.should == NSLayoutAttributeNotAnAttribute
39
+ resolved[1].secondItem.should == @parent_view
40
+ resolved[1].secondAttribute.should == NSLayoutAttributeCenterY
39
41
  resolved[1].multiplier.should == 1
40
42
  resolved[1].constant.should == 10
41
43
  end
42
44
  it 'should support `min_center [10, 10]`' do
43
- @view = @layout.context(UIView.new) do
45
+ @layout.context(@view) do
44
46
  @layout.constraints do
45
47
  @constraint = @layout.min_center([10, 10])
46
48
  end
@@ -54,7 +56,7 @@ describe 'Constraints - Center helpers' do
54
56
  @constraint.attribute2.should == [:center_x, :center_y]
55
57
  end
56
58
  it 'should support `max_center [10, 10]`' do
57
- @view = @layout.context(UIView.new) do
59
+ @layout.context(@view) do
58
60
  @layout.constraints do
59
61
  @constraint = @layout.max_center([10, 10])
60
62
  end
@@ -68,7 +70,7 @@ describe 'Constraints - Center helpers' do
68
70
  @constraint.attribute2.should == [:center_x, :center_y]
69
71
  end
70
72
  it 'should support `center x: 10, y: 10`' do
71
- @view = @layout.context(UIView.new) do
73
+ @layout.context(@view) do
72
74
  @layout.constraints do
73
75
  @constraint = @layout.center(x: 10, y: 10)
74
76
  end
@@ -82,7 +84,7 @@ describe 'Constraints - Center helpers' do
82
84
  @constraint.attribute2.should == [:center_x, :center_y]
83
85
  end
84
86
  it 'should support `min_center x: 10, y: 10`' do
85
- @view = @layout.context(UIView.new) do
87
+ @layout.context(@view) do
86
88
  @layout.constraints do
87
89
  @constraint = @layout.min_center(x: 10, y: 10)
88
90
  end
@@ -96,7 +98,7 @@ describe 'Constraints - Center helpers' do
96
98
  @constraint.attribute2.should == [:center_x, :center_y]
97
99
  end
98
100
  it 'should support `max_center x: 10, y: 10`' do
99
- @view = @layout.context(UIView.new) do
101
+ @layout.context(@view) do
100
102
  @layout.constraints do
101
103
  @constraint = @layout.max_center(x: 10, y: 10)
102
104
  end
@@ -110,7 +112,7 @@ describe 'Constraints - Center helpers' do
110
112
  @constraint.attribute2.should == [:center_x, :center_y]
111
113
  end
112
114
  it 'should support `center.equals(:another_view[, :center])`' do
113
- @top = @view = @layout.context(UIView.new) do
115
+ @top = @layout.context(@view) do
114
116
  @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
115
117
  @layout.constraints do
116
118
  @constraint = @layout.center.equals(:another_view)
@@ -125,7 +127,7 @@ describe 'Constraints - Center helpers' do
125
127
  @constraint.attribute2.should == [:center_x, :center_y]
126
128
  end
127
129
  it 'should support `center.equals(:another_view).plus(10).plus([5, 10])`' do
128
- @view = @layout.context(UIView.new) do
130
+ @layout.context(@view) do
129
131
  @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
130
132
  @layout.constraints do
131
133
  @constraint = @layout.center.equals(:another_view).plus(10).plus([5, 10])
@@ -140,7 +142,7 @@ describe 'Constraints - Center helpers' do
140
142
  @constraint.attribute2.should == [:center_x, :center_y]
141
143
  end
142
144
  it 'should support `min_center.equals(:another_view[, :center])`' do
143
- @view = @layout.context(UIView.new) do
145
+ @layout.context(@view) do
144
146
  @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
145
147
  @layout.constraints do
146
148
  @constraint = @layout.min_center.equals(:another_view)
@@ -173,7 +175,7 @@ describe 'Constraints - Center helpers' do
173
175
  resolved[1].constant.should == 0
174
176
  end
175
177
  it 'should support `max_center.equals(:another_view[, :center])`' do
176
- @view = @layout.context(UIView.new) do
178
+ @layout.context(@view) do
177
179
  @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
178
180
  @layout.constraints do
179
181
  @constraint = @layout.max_center.equals(:another_view)
@@ -188,7 +190,7 @@ describe 'Constraints - Center helpers' do
188
190
  @constraint.attribute2.should == [:center_x, :center_y]
189
191
  end
190
192
  it 'should support `center.equals(:another_view).plus(10)`' do
191
- @view = @layout.context(UIView.new) do
193
+ @layout.context(@view) do
192
194
  @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
193
195
  @layout.constraints do
194
196
  @constraint = @layout.center.equals(:another_view).plus(10)
@@ -203,7 +205,7 @@ describe 'Constraints - Center helpers' do
203
205
  @constraint.attribute2.should == [:center_x, :center_y]
204
206
  end
205
207
  it 'should support `min_center.equals(:another_view).plus(10)`' do
206
- @view = @layout.context(UIView.new) do
208
+ @layout.context(@view) do
207
209
  @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
208
210
  @layout.constraints do
209
211
  @constraint = @layout.min_center.equals(:another_view).plus(10)
@@ -218,7 +220,7 @@ describe 'Constraints - Center helpers' do
218
220
  @constraint.attribute2.should == [:center_x, :center_y]
219
221
  end
220
222
  it 'should support `max_center.equals(:another_view).plus(10)`' do
221
- @view = @layout.context(UIView.new) do
223
+ @layout.context(@view) do
222
224
  @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
223
225
  @layout.constraints do
224
226
  @constraint = @layout.max_center.equals(:another_view).plus(10)
@@ -233,7 +235,7 @@ describe 'Constraints - Center helpers' do
233
235
  @constraint.attribute2.should == [:center_x, :center_y]
234
236
  end
235
237
  it 'should support `center.equals(:another_view).plus([10, 10])`' do
236
- @view = @layout.context(UIView.new) do
238
+ @layout.context(@view) do
237
239
  @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
238
240
  @layout.constraints do
239
241
  @constraint = @layout.center.equals(:another_view).plus([10, 10])
@@ -248,7 +250,7 @@ describe 'Constraints - Center helpers' do
248
250
  @constraint.attribute2.should == [:center_x, :center_y]
249
251
  end
250
252
  it 'should support `min_center.equals(:another_view).plus([10, 10])`' do
251
- @view = @layout.context(UIView.new) do
253
+ @layout.context(@view) do
252
254
  @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
253
255
  @layout.constraints do
254
256
  @constraint = @layout.min_center.equals(:another_view).plus([10, 10])
@@ -263,7 +265,7 @@ describe 'Constraints - Center helpers' do
263
265
  @constraint.attribute2.should == [:center_x, :center_y]
264
266
  end
265
267
  it 'should support `max_center.equals(:another_view).plus(x: 10, y: 10)`' do
266
- @view = @layout.context(UIView.new) do
268
+ @layout.context(@view) do
267
269
  @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
268
270
  @layout.constraints do
269
271
  @constraint = @layout.max_center.equals(:another_view).plus(x: 10, y: 10)
@@ -278,7 +280,7 @@ describe 'Constraints - Center helpers' do
278
280
  @constraint.attribute2.should == [:center_x, :center_y]
279
281
  end
280
282
  it 'should support `center.equals(:another_view).times(2).plus(10)`' do
281
- @view = @layout.context(UIView.new) do
283
+ @layout.context(@view) do
282
284
  @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
283
285
  @layout.constraints do
284
286
  @constraint = @layout.center.equals(:another_view).times(2).plus(10)
@@ -293,7 +295,7 @@ describe 'Constraints - Center helpers' do
293
295
  @constraint.attribute2.should == [:center_x, :center_y]
294
296
  end
295
297
  it 'should support `min_center.equals(:another_view).times(2).plus(10)`' do
296
- @view = @layout.context(UIView.new) do
298
+ @layout.context(@view) do
297
299
  @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
298
300
  @layout.constraints do
299
301
  @constraint = @layout.min_center.equals(:another_view).times(2).plus(10)
@@ -308,7 +310,7 @@ describe 'Constraints - Center helpers' do
308
310
  @constraint.attribute2.should == [:center_x, :center_y]
309
311
  end
310
312
  it 'should support `max_center.equals(:another_view).times(2).plus(10)`' do
311
- @view = @layout.context(UIView.new) do
313
+ @layout.context(@view) do
312
314
  @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
313
315
  @layout.constraints do
314
316
  @constraint = @layout.max_center.equals(:another_view).times(2).plus(10)
@@ -341,7 +343,7 @@ describe 'Constraints - Center helpers' do
341
343
  resolved[1].constant.should == 10
342
344
  end
343
345
  it 'should support `center.equals(:another_view).times([2, 2]).plus(10)`' do
344
- @view = @layout.context(UIView.new) do
346
+ @layout.context(@view) do
345
347
  @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
346
348
  @layout.constraints do
347
349
  @constraint = @layout.center.equals(:another_view).times([2, 2]).plus(10)
@@ -356,7 +358,7 @@ describe 'Constraints - Center helpers' do
356
358
  @constraint.attribute2.should == [:center_x, :center_y]
357
359
  end
358
360
  it 'should support `min_center.equals(:another_view).times([2, 2]).plus(10)`' do
359
- @view = @layout.context(UIView.new) do
361
+ @layout.context(@view) do
360
362
  @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
361
363
  @layout.constraints do
362
364
  @constraint = @layout.min_center.equals(:another_view).times([2, 2]).plus(10)
@@ -371,7 +373,7 @@ describe 'Constraints - Center helpers' do
371
373
  @constraint.attribute2.should == [:center_x, :center_y]
372
374
  end
373
375
  it 'should support `max_center.equals(:another_view).times(x: 2, y: 2).plus(10)`' do
374
- @view = @layout.context(UIView.new) do
376
+ @layout.context(@view) do
375
377
  @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
376
378
  @layout.constraints do
377
379
  @constraint = @layout.max_center.equals(:another_view).times(x: 2, y: 2).plus(10)
@@ -386,7 +388,7 @@ describe 'Constraints - Center helpers' do
386
388
  @constraint.attribute2.should == [:center_x, :center_y]
387
389
  end
388
390
  it 'should support `center.equals(:another_view).times(2).times([3, 4])`' do
389
- @view = @layout.context(UIView.new) do
391
+ @layout.context(@view) do
390
392
  @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
391
393
  @layout.constraints do
392
394
  @constraint = @layout.center.equals(:another_view).times(2).times([3, 4])
@@ -401,7 +403,7 @@ describe 'Constraints - Center helpers' do
401
403
  @constraint.attribute2.should == [:center_x, :center_y]
402
404
  end
403
405
  it 'should support `center.equals(:another_view).divided_by(2)`' do
404
- @view = @layout.context(UIView.new) do
406
+ @layout.context(@view) do
405
407
  @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
406
408
  @layout.constraints do
407
409
  @constraint = @layout.center.equals(:another_view).divided_by(2)