motion-kit 0.0.1 → 0.9.0

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.
Files changed (94) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +839 -0
  3. data/lib/motion-kit-cocoa/cocoa_util.rb +59 -0
  4. data/lib/motion-kit-cocoa/constraints/constraint.rb +765 -0
  5. data/lib/motion-kit-cocoa/constraints/constraint_placeholder.rb +22 -0
  6. data/lib/motion-kit-cocoa/constraints/constraints_layout.rb +536 -0
  7. data/lib/motion-kit-cocoa/constraints/constraints_target.rb +52 -0
  8. data/lib/motion-kit-cocoa/layouts/cagradientlayer_layout.rb +13 -0
  9. data/lib/motion-kit-cocoa/layouts/calayer_layout.rb +27 -0
  10. data/lib/motion-kit-cocoa/layouts/sugarcube_compat.rb +38 -0
  11. data/lib/motion-kit-ios/dummy.rb +93 -0
  12. data/lib/motion-kit-ios/ios_util.rb +20 -0
  13. data/lib/motion-kit-ios/layouts/constraints_layout.rb +22 -0
  14. data/lib/motion-kit-ios/layouts/layout_device.rb +32 -0
  15. data/lib/motion-kit-ios/layouts/layout_orientation.rb +47 -0
  16. data/lib/motion-kit-ios/layouts/uibutton_layout.rb +52 -0
  17. data/lib/motion-kit-ios/layouts/uiview_layout.rb +45 -0
  18. data/lib/motion-kit-ios/layouts/uiview_layout_autoresizing.rb +75 -0
  19. data/lib/motion-kit-ios/layouts/uiview_layout_constraints.rb +36 -0
  20. data/lib/motion-kit-ios/layouts/uiview_layout_frame.rb +307 -0
  21. data/lib/motion-kit-ios/layouts/uiview_layout_gradient.rb +20 -0
  22. data/lib/motion-kit-osx/dummy.rb +89 -0
  23. data/lib/motion-kit-osx/layouts/constraints_layout.rb +42 -0
  24. data/lib/motion-kit-osx/layouts/nsmenu_extensions.rb +186 -0
  25. data/lib/motion-kit-osx/layouts/nsmenu_layout.rb +109 -0
  26. data/lib/motion-kit-osx/layouts/nsmenuitem_extensions.rb +45 -0
  27. data/lib/motion-kit-osx/layouts/nstablecolumn_layout.rb +12 -0
  28. data/lib/motion-kit-osx/layouts/nstableview_layout.rb +20 -0
  29. data/lib/motion-kit-osx/layouts/nsview_layout.rb +47 -0
  30. data/lib/motion-kit-osx/layouts/nsview_layout_autoresizing.rb +75 -0
  31. data/lib/motion-kit-osx/layouts/nsview_layout_constraints.rb +34 -0
  32. data/lib/motion-kit-osx/layouts/nsview_layout_frame.rb +375 -0
  33. data/lib/motion-kit-osx/layouts/nswindow_frame.rb +14 -0
  34. data/lib/motion-kit-osx/layouts/nswindow_layout.rb +77 -0
  35. data/lib/motion-kit-osx/osx_util.rb +16 -0
  36. data/lib/motion-kit.rb +33 -0
  37. data/lib/motion-kit/calculate.rb +263 -0
  38. data/lib/motion-kit/layouts/base_layout.rb +299 -0
  39. data/lib/motion-kit/layouts/base_layout_class_methods.rb +43 -0
  40. data/lib/motion-kit/layouts/parent.rb +68 -0
  41. data/lib/motion-kit/layouts/view_layout.rb +327 -0
  42. data/lib/motion-kit/motion-kit.rb +18 -0
  43. data/lib/motion-kit/object.rb +16 -0
  44. data/lib/motion-kit/util.rb +20 -0
  45. data/lib/motion-kit/version.rb +1 -1
  46. data/spec/ios/apply_styles_spec.rb +21 -0
  47. data/spec/ios/autoresizing_helper_spec.rb +224 -0
  48. data/spec/ios/calculate_spec.rb +322 -0
  49. data/spec/ios/calculator_spec.rb +31 -0
  50. data/spec/ios/constraints_helpers/attribute_lookup_spec.rb +27 -0
  51. data/spec/ios/constraints_helpers/axis_lookup_spec.rb +13 -0
  52. data/spec/ios/constraints_helpers/center_constraints_spec.rb +419 -0
  53. data/spec/ios/constraints_helpers/constraint_placeholder_spec.rb +72 -0
  54. data/spec/ios/constraints_helpers/priority_lookup_spec.rb +19 -0
  55. data/spec/ios/constraints_helpers/relationship_lookup_spec.rb +27 -0
  56. data/spec/ios/constraints_helpers/relative_corners_spec.rb +274 -0
  57. data/spec/ios/constraints_helpers/relative_location_spec.rb +111 -0
  58. data/spec/ios/constraints_helpers/simple_constraints_spec.rb +2763 -0
  59. data/spec/ios/constraints_helpers/size_constraints_spec.rb +422 -0
  60. data/spec/ios/constraints_helpers/view_lookup_constraints_spec.rb +93 -0
  61. data/spec/ios/create_layout_spec.rb +40 -0
  62. data/spec/ios/custom_layout_spec.rb +13 -0
  63. data/spec/ios/deferred_spec.rb +89 -0
  64. data/spec/ios/device_helpers_spec.rb +51 -0
  65. data/spec/ios/frame_helper_spec.rb +1150 -0
  66. data/spec/ios/layer_layout_spec.rb +36 -0
  67. data/spec/ios/layout_extensions_spec.rb +70 -0
  68. data/spec/ios/layout_spec.rb +74 -0
  69. data/spec/ios/layout_state_spec.rb +27 -0
  70. data/spec/ios/motionkit_util_spec.rb +102 -0
  71. data/spec/ios/objc_selectors_spec.rb +10 -0
  72. data/spec/ios/orientation_helper_specs.rb +67 -0
  73. data/spec/ios/parent_layout_spec.rb +19 -0
  74. data/spec/ios/parent_spec.rb +45 -0
  75. data/spec/ios/remove_layout_spec.rb +25 -0
  76. data/spec/ios/root_layout_spec.rb +53 -0
  77. data/spec/ios/setters_spec.rb +63 -0
  78. data/spec/ios/uibutton_layout_spec.rb +24 -0
  79. data/spec/ios/uitextfield_spec.rb +14 -0
  80. data/spec/ios/view_attr_spec.rb +25 -0
  81. data/spec/osx/autoresizing_helper_spec.rb +224 -0
  82. data/spec/osx/constraints_helper_spec.rb +0 -0
  83. data/spec/osx/constraints_helpers/orientation_lookup_spec.rb +13 -0
  84. data/spec/osx/constraints_helpers/simple_constraints_spec.rb +2095 -0
  85. data/spec/osx/constraints_helpers/size_constraints_spec.rb +362 -0
  86. data/spec/osx/create_menu_spec.rb +14 -0
  87. data/spec/osx/create_via_extensions_spec.rb +63 -0
  88. data/spec/osx/deferred_spec.rb +85 -0
  89. data/spec/osx/frame_helper_spec.rb +1881 -0
  90. data/spec/osx/menu_extensions_spec.rb +376 -0
  91. data/spec/osx/menu_layout_spec.rb +157 -0
  92. data/spec/osx/menu_spec.rb +70 -0
  93. data/spec/osx/root_menu_spec.rb +15 -0
  94. metadata +166 -14
@@ -0,0 +1,25 @@
1
+ describe MotionKit::Layout do
2
+ before do
3
+ @subject = TestRemoveLayout.new
4
+ end
5
+
6
+ it 'should remove the #label view' do
7
+ @subject.get(:label).should.be.kind_of(UILabel)
8
+ @subject.remove_label
9
+ @subject.get(:label).should.be.nil
10
+ end
11
+
12
+ it 'should remove the #image view' do
13
+ @subject.get(:image).should.be.kind_of(UIImageView)
14
+ @subject.remove_image
15
+ @subject.get(:image).should.be.nil
16
+ end
17
+
18
+ it 'should remove the #view view' do
19
+ @subject.get(:view).should.be.kind_of(UIView)
20
+ @subject.remove_view
21
+ @subject.get(:view).should.be.nil
22
+ @subject.get(:image).should.be.nil
23
+ end
24
+
25
+ end
@@ -0,0 +1,53 @@
1
+ describe 'Assigning explicit root view' do
2
+ before { @subject = TestRootLayout.new }
3
+
4
+ it "should allow setting the root view" do
5
+ @subject.view.should.be.kind_of UIScrollView
6
+ end
7
+
8
+ it "should still create subviews" do
9
+ @subject.view.subviews.first.should.be.kind_of UIButton
10
+ @subject.view.subviews.first.subviews.first.should.be.kind_of UILabel
11
+ end
12
+
13
+ it "should call style method" do
14
+ @subject.view
15
+ @subject.scroll_view_styled.should == true
16
+ end
17
+
18
+ it "should call style method on simple root layout" do
19
+ subject = TestSimpleRootLayout.new
20
+
21
+ subject.view
22
+ subject.label_styled.should == true
23
+ end
24
+
25
+ it "should raise exception if you try to specify two roots" do
26
+ -> do
27
+ subject = TestDuplicateRootLayout.new
28
+ subject.view
29
+ end.should.raise(MotionKit::ContextConflictError)
30
+ end
31
+
32
+ it "should raise exception if you don't add views inside the root" do
33
+ -> do
34
+ subject = TestNoRootContextLayout.new
35
+ subject.view
36
+ end.should.raise(MotionKit::NoContextError)
37
+ end
38
+
39
+ it 'should raise an exception when there is no context' do
40
+ -> do
41
+ subject = TestNoContextLayout.new
42
+ subject.foo
43
+ end.should.raise(MotionKit::NoContextError)
44
+ end
45
+
46
+ it 'should raise an exception when creating a root view outside of `layout`' do
47
+ -> do
48
+ subject = TestInvalidRootContextLayout.new
49
+ subject.foo
50
+ end.should.raise(MotionKit::InvalidRootError)
51
+ end
52
+
53
+ end
@@ -0,0 +1,63 @@
1
+ describe "Layout setters" do
2
+
3
+ describe "Pure ruby object" do
4
+
5
+ before do
6
+ @subject = TestSetters.new(TestSettersFixture.new)
7
+ end
8
+
9
+ it 'should set foo (setFoo)' do
10
+ @subject.run_foo
11
+ @subject.target.foo.should == 'foo'
12
+ end
13
+
14
+ it 'should set bar (bar=)' do
15
+ @subject.run_bar
16
+ @subject.target.bar.should == 'bar'
17
+ end
18
+
19
+ it 'should set setter (setter(val))' do
20
+ @subject.run_setter
21
+ @subject.target.setter.should == 'setter'
22
+ end
23
+
24
+ it 'should assign quux (baz.quux, attr_accessor) with baz as context' do
25
+ @subject.run_baz
26
+ @subject.target.baz.quux.should == 'quux'
27
+ end
28
+
29
+ it 'should assign quux (bazBaz.quux, attr_accessor) with baz_baz as context' do
30
+ @subject.run_baz_baz
31
+ @subject.target.bazBaz.quux.should == 'quux'
32
+ end
33
+
34
+ end
35
+
36
+ describe "Objective-C object" do
37
+
38
+ before do
39
+ @subject = TestSetters.new(TestSettersLabel.new)
40
+ end
41
+
42
+ it 'should set text (setText)' do
43
+ @subject.run_text
44
+ @subject.target.text.should == 'text'
45
+ end
46
+
47
+ it 'should set bar (bar=)' do
48
+ @subject.run_bar
49
+ @subject.target.bar.should == 'bar'
50
+ end
51
+
52
+ it 'should set background_color (setBackgroundColor)' do
53
+ @subject.run_background_color
54
+ @subject.target.backgroundColor.should == UIColor.whiteColor
55
+ end
56
+
57
+ it 'should assign cornerRadius (layer.corner_radius) with layer as context' do
58
+ @subject.run_layer(5)
59
+ @subject.target.layer.cornerRadius.should == 5
60
+ end
61
+ end
62
+
63
+ end
@@ -0,0 +1,24 @@
1
+ describe 'UIButton Layout and objc-style selectors' do
2
+
3
+ before do
4
+ @layout = TestButtonLayout.new
5
+ @layout.view
6
+ end
7
+
8
+ it 'should set the title' do
9
+ @layout.get(:button).currentTitle.should == TestButtonLayout::TITLE
10
+ end
11
+
12
+ it 'should set the highlighted title' do
13
+ @layout.get(:button).titleForState(UIControlStateHighlighted).should == TestButtonLayout::HIGHLIGHTED_TITLE
14
+ end
15
+
16
+ it 'should set the image' do
17
+ @layout.get(:button).currentImage.should == TestButtonLayout::IMAGE
18
+ end
19
+
20
+ it 'should set the highlighted image' do
21
+ @layout.get(:button).imageForState(UIControlStateHighlighted).should == TestButtonLayout::HIGHLIGHTED_IMAGE
22
+ end
23
+
24
+ end
@@ -0,0 +1,14 @@
1
+ describe 'UITextField Layout and objc-style selectors' do
2
+
3
+ before do
4
+ @layout = TestTextFieldLayout.new
5
+ @layout.view
6
+ end
7
+
8
+ it 'should set autocorrectionType' do
9
+ @layout.get(:field).autocorrectionType.should == UITextAutocorrectionTypeNo
10
+ @layout.get(:field).spellCheckingType.should == UITextSpellCheckingTypeNo
11
+ @layout.get(:field).autocapitalizationType.should == UITextAutocapitalizationTypeNone
12
+ end
13
+
14
+ end
@@ -0,0 +1,25 @@
1
+ describe 'View attr' do
2
+
3
+ before do
4
+ @layout = TestViewAttrLayout.new
5
+ end
6
+
7
+ it 'should get :button' do
8
+ @layout.view
9
+ button = @layout.button
10
+ button.should.be.kind_of(UIButton)
11
+ end
12
+
13
+ it 'should return the same :button' do
14
+ @layout.view
15
+ button = @layout.button
16
+ button.should == @layout.button
17
+ end
18
+
19
+ it 'should call layout if the view doesnt exist' do
20
+ label = @layout.label
21
+ label.should.be.kind_of(UILabel)
22
+ label.should == @layout.label
23
+ end
24
+
25
+ end
@@ -0,0 +1,224 @@
1
+ describe 'Autoresize helpers' do
2
+
3
+ before do
4
+ @layout = MK::Layout.new
5
+ @view = NSView.alloc.initWithFrame([[0, 0], [10, 10]])
6
+ end
7
+
8
+ it 'should support :flexible_left' do
9
+ mask = nil
10
+ @layout.context(@view) do
11
+ mask = @layout.autoresizing_mask :flexible_left
12
+ end
13
+ mask.should == NSViewMinXMargin
14
+ end
15
+
16
+ it 'should support :flexible_width' do
17
+ mask = nil
18
+ @layout.context(@view) do
19
+ mask = @layout.autoresizing_mask :flexible_width
20
+ end
21
+ mask.should == NSViewWidthSizable
22
+ end
23
+
24
+ it 'should support :flexible_right' do
25
+ mask = nil
26
+ @layout.context(@view) do
27
+ mask = @layout.autoresizing_mask :flexible_right
28
+ end
29
+ mask.should == NSViewMaxXMargin
30
+ end
31
+
32
+ it 'should support :flexible_top' do
33
+ mask = nil
34
+ @layout.context(@view) do
35
+ mask = @layout.autoresizing_mask :flexible_top
36
+ end
37
+ mask.should == NSViewMaxYMargin
38
+ end
39
+
40
+ it 'should support :flexible_height' do
41
+ mask = nil
42
+ @layout.context(@view) do
43
+ mask = @layout.autoresizing_mask :flexible_height
44
+ end
45
+ mask.should == NSViewHeightSizable
46
+ end
47
+
48
+ it 'should support :flexible_bottom' do
49
+ mask = nil
50
+ @layout.context(@view) do
51
+ mask = @layout.autoresizing_mask :flexible_bottom
52
+ end
53
+ mask.should == NSViewMinYMargin
54
+ end
55
+
56
+ it 'should support :rigid_left' do
57
+ mask = nil
58
+ @layout.context(@view) do
59
+ mask = @layout.autoresizing_mask :flexible_right, :flexible_left, :rigid_left
60
+ end
61
+ mask.should == NSViewMaxXMargin
62
+ end
63
+
64
+ it 'should support :rigid_width' do
65
+ mask = nil
66
+ @layout.context(@view) do
67
+ mask = @layout.autoresizing_mask :flexible_height, :flexible_width, :rigid_width
68
+ end
69
+ mask.should == NSViewHeightSizable
70
+ end
71
+
72
+ it 'should support :rigid_right' do
73
+ mask = nil
74
+ @layout.context(@view) do
75
+ mask = @layout.autoresizing_mask :flexible_left, :flexible_right, :rigid_right
76
+ end
77
+ mask.should == NSViewMinXMargin
78
+ end
79
+
80
+ it 'should support :rigid_top' do
81
+ mask = nil
82
+ @layout.context(@view) do
83
+ mask = @layout.autoresizing_mask :flexible_bottom, :flexible_top, :rigid_top
84
+ end
85
+ mask.should == NSViewMinYMargin
86
+ end
87
+
88
+ it 'should support :rigid_height' do
89
+ mask = nil
90
+ @layout.context(@view) do
91
+ mask = @layout.autoresizing_mask :flexible_width, :flexible_height, :rigid_height
92
+ end
93
+ mask.should == NSViewWidthSizable
94
+ end
95
+
96
+ it 'should support :rigid_bottom' do
97
+ mask = nil
98
+ @layout.context(@view) do
99
+ mask = @layout.autoresizing_mask :flexible_top, :flexible_bottom, :rigid_bottom
100
+ end
101
+ mask.should == NSViewMaxYMargin
102
+ end
103
+
104
+ it 'should support :fill' do
105
+ mask = nil
106
+ @layout.context(@view) do
107
+ mask = @layout.autoresizing_mask :fill
108
+ end
109
+ mask.should == NSViewWidthSizable | NSViewHeightSizable
110
+ end
111
+
112
+ it 'should support :fill_top' do
113
+ mask = nil
114
+ @layout.context(@view) do
115
+ mask = @layout.autoresizing_mask :fill_top
116
+ end
117
+ mask.should == NSViewWidthSizable | NSViewMinYMargin
118
+ end
119
+
120
+ it 'should support :fill_bottom' do
121
+ mask = nil
122
+ @layout.context(@view) do
123
+ mask = @layout.autoresizing_mask :fill_bottom
124
+ end
125
+ mask.should == NSViewWidthSizable | NSViewMaxYMargin
126
+ end
127
+
128
+ it 'should support :fill_left' do
129
+ mask = nil
130
+ @layout.context(@view) do
131
+ mask = @layout.autoresizing_mask :fill_left
132
+ end
133
+ mask.should == NSViewHeightSizable | NSViewMaxXMargin
134
+ end
135
+
136
+ it 'should support :fill_right' do
137
+ mask = nil
138
+ @layout.context(@view) do
139
+ mask = @layout.autoresizing_mask :fill_right
140
+ end
141
+ mask.should == NSViewHeightSizable | NSViewMinXMargin
142
+ end
143
+
144
+ it 'should support :pin_to_top_left' do
145
+ mask = nil
146
+ @layout.context(@view) do
147
+ mask = @layout.autoresizing_mask :pin_to_top_left
148
+ end
149
+ mask.should == NSViewMaxXMargin | NSViewMinYMargin
150
+ end
151
+
152
+ it 'should support :pin_to_top' do
153
+ mask = nil
154
+ @layout.context(@view) do
155
+ mask = @layout.autoresizing_mask :pin_to_top
156
+ end
157
+ mask.should == NSViewMinXMargin | NSViewMaxXMargin | NSViewMinYMargin
158
+ end
159
+
160
+ it 'should support :pin_to_top_right' do
161
+ mask = nil
162
+ @layout.context(@view) do
163
+ mask = @layout.autoresizing_mask :pin_to_top_right
164
+ end
165
+ mask.should == NSViewMinXMargin | NSViewMinYMargin
166
+ end
167
+
168
+ it 'should support :pin_to_left' do
169
+ mask = nil
170
+ @layout.context(@view) do
171
+ mask = @layout.autoresizing_mask :pin_to_left
172
+ end
173
+ mask.should == NSViewMaxYMargin | NSViewMinYMargin | NSViewMaxXMargin
174
+ end
175
+
176
+ it 'should support :pin_to_center' do
177
+ mask = nil
178
+ @layout.context(@view) do
179
+ mask = @layout.autoresizing_mask :pin_to_center
180
+ end
181
+ mask.should == NSViewMaxYMargin | NSViewMinYMargin | NSViewMinXMargin | NSViewMaxXMargin
182
+ end
183
+
184
+ it 'should support :pin_to_middle' do
185
+ mask = nil
186
+ @layout.context(@view) do
187
+ mask = @layout.autoresizing_mask :pin_to_middle
188
+ end
189
+ mask.should == NSViewMaxYMargin | NSViewMinYMargin | NSViewMinXMargin | NSViewMaxXMargin
190
+ end
191
+
192
+ it 'should support :pin_to_right' do
193
+ mask = nil
194
+ @layout.context(@view) do
195
+ mask = @layout.autoresizing_mask :pin_to_right
196
+ end
197
+ mask.should == NSViewMaxYMargin | NSViewMinYMargin | NSViewMinXMargin
198
+ end
199
+
200
+ it 'should support :pin_to_bottom_left' do
201
+ mask = nil
202
+ @layout.context(@view) do
203
+ mask = @layout.autoresizing_mask :pin_to_bottom_left
204
+ end
205
+ mask.should == NSViewMaxXMargin | NSViewMaxYMargin
206
+ end
207
+
208
+ it 'should support :pin_to_bottom' do
209
+ mask = nil
210
+ @layout.context(@view) do
211
+ mask = @layout.autoresizing_mask :pin_to_bottom
212
+ end
213
+ mask.should == NSViewMinXMargin | NSViewMaxXMargin | NSViewMaxYMargin
214
+ end
215
+
216
+ it 'should support :pin_to_bottom_right' do
217
+ mask = nil
218
+ @layout.context(@view) do
219
+ mask = @layout.autoresizing_mask :pin_to_bottom_right
220
+ end
221
+ mask.should == NSViewMinXMargin | NSViewMaxYMargin
222
+ end
223
+
224
+ end
File without changes
@@ -0,0 +1,13 @@
1
+ describe 'Constraints - orientation lookup' do
2
+
3
+ it 'should return NSLayoutConstraintOrientationHorizontal' do
4
+ MotionKit::Constraint.orientation_lookup(:horizontal).should == NSLayoutConstraintOrientationHorizontal
5
+ MotionKit::Constraint.orientation_lookup(NSLayoutConstraintOrientationHorizontal).should == NSLayoutConstraintOrientationHorizontal
6
+ end
7
+
8
+ it 'should return NSLayoutConstraintOrientationVertical' do
9
+ MotionKit::Constraint.orientation_lookup(:vertical).should == NSLayoutConstraintOrientationVertical
10
+ MotionKit::Constraint.orientation_lookup(NSLayoutConstraintOrientationVertical).should == NSLayoutConstraintOrientationVertical
11
+ end
12
+
13
+ end