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,36 @@
1
+ describe TestLayerLayout do
2
+ before do
3
+ @subject = TestLayerLayout.new
4
+ end
5
+
6
+ it 'should create a CALayer root' do
7
+ @subject.view.should.be.kind_of(CALayer)
8
+ end
9
+
10
+ it 'should add sublayers' do
11
+ @subject.view.sublayers.length.should == 3
12
+ end
13
+
14
+ describe 'should have styled sublayers' do
15
+ before do
16
+ @subject = TestLayerLayout.new
17
+ end
18
+
19
+ it 'should have a CALayer' do
20
+ @subject.view.sublayers[0].opacity.should == 0.5
21
+ @subject.view.sublayers[0].backgroundColor.should.not == nil
22
+ end
23
+
24
+ it 'should have a CAGradientLayer' do
25
+ @subject.view.sublayers[1].opacity.should == 0.5
26
+ @subject.view.sublayers[1].colors.should.not == nil
27
+ @subject.view.sublayers[1].colors.length.should == 2
28
+ end
29
+
30
+ it 'should have a CAShapeLayer' do
31
+ @subject.view.sublayers[2].opacity.should == 0.5
32
+ @subject.view.sublayers[2].path.should.not == nil
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,70 @@
1
+ describe "Layout extensions - iOS" do
2
+
3
+ before do
4
+ @subject = MK::UIViewLayout.new
5
+ @subject.instance_variable_set(:@context, "don't matter what i be, as long as i be.")
6
+ end
7
+
8
+ it 'should have `orientation?` method' do
9
+ tf = @subject.orientation?(:portrait)
10
+ (tf == true || tf == false).should.be.true
11
+ end
12
+
13
+ it 'should return true for `orientation?(:portrait)` when in portrait' do
14
+ tf = @subject.orientation?(:portrait)
15
+ should_be = (UIApplication.sharedApplication.statusBarOrientation == UIInterfaceOrientationPortrait)
16
+ tf.should == should_be
17
+ end
18
+
19
+ it 'should return true for `orientation?(:landscape_left)` when in landscape_left' do
20
+ tf = @subject.orientation?(:landscape_left)
21
+ should_be = (UIApplication.sharedApplication.statusBarOrientation == UIInterfaceOrientationLandscapeLeft)
22
+ tf.should == should_be
23
+ end
24
+
25
+ it 'should return true for `orientation?(:landscape_right)` when in landscape_right' do
26
+ tf = @subject.orientation?(:landscape_right)
27
+ should_be = (UIApplication.sharedApplication.statusBarOrientation == UIInterfaceOrientationLandscapeRight)
28
+ tf.should == should_be
29
+ end
30
+
31
+ it 'should return true for `orientation?(:landscape)` when in landscape' do
32
+ tf = @subject.orientation?(:landscape)
33
+ should_be = (UIApplication.sharedApplication.statusBarOrientation == UIInterfaceOrientationLandscapeLeft || UIApplication.sharedApplication.statusBarOrientation == UIInterfaceOrientationLandscapeRight)
34
+ tf.should == should_be
35
+ end
36
+
37
+ it 'should have `iphone?` method' do
38
+ tf = @subject.iphone?
39
+ (tf == true || tf == false).should.be.true
40
+ end
41
+
42
+ it 'should return `true` for `iphone?` when using an iphone' do
43
+ tf = @subject.iphone?
44
+ should_be = UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPhone
45
+ tf.should == should_be
46
+ end
47
+
48
+ it 'should have `ipad?` method' do
49
+ tf = @subject.ipad?
50
+ (tf == true || tf == false).should.be.true
51
+ end
52
+
53
+ it 'should return `true` for `ipad?` when using an ipad' do
54
+ tf = @subject.ipad?
55
+ should_be = UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
56
+ tf.should == should_be
57
+ end
58
+
59
+ it 'should have `retina?` method' do
60
+ tf = @subject.retina?
61
+ (tf == true || tf == false).should.be.true
62
+ end
63
+
64
+ it 'should return `true` for `return?` when using a retina device' do
65
+ tf = @subject.retina?
66
+ should_be = UIScreen.mainScreen.scale == 2
67
+ tf.should == should_be
68
+ end
69
+
70
+ end
@@ -0,0 +1,74 @@
1
+ describe MotionKit::Layout do
2
+ before do
3
+ @subject = TestLayout.new
4
+ end
5
+
6
+ it "should be an instance of MotionKit::Layout" do
7
+ @subject.should.be.kind_of(MotionKit::Layout)
8
+ end
9
+
10
+ it "should be an instance of MK::Layout" do
11
+ @subject.should.be.kind_of(MK::Layout)
12
+ end
13
+
14
+ it "should add a UIView subview with the name :basic_view" do
15
+ view = @subject.view.subviews.find { |view| view.motion_kit_id == :basic_view }
16
+ view.should.be.kind_of(UIView)
17
+ end
18
+
19
+ it "should add two subviews under :basic_view" do
20
+ @subject.view.subviews.first.subviews.length.should == 2
21
+ end
22
+
23
+ it "should add a UIButton as the first subview under :basic_view" do
24
+ @subject.view.subviews.first.subviews.first.should.be.kind_of UIButton
25
+ end
26
+
27
+ it "should add a UILabel as the second subview under :basic_view" do
28
+ @subject.view.subviews.first.subviews[1].should.be.kind_of UILabel
29
+ end
30
+
31
+ it "should allow getting the subviews by their id" do
32
+ @subject.get(:basic_view).should.be.kind_of UIView
33
+ @subject.get(:basic_view, in: @subject.view).should.be.kind_of UIView
34
+ @subject.get(:basic_view, in: @subject.view).should == @subject.get(:basic_view)
35
+
36
+ @subject.get(:basic_button).should.be.kind_of UIButton
37
+ @subject.get(:basic_button, in: @subject.view).should.be.kind_of UIView
38
+ @subject.get(:basic_button, in: @subject.view).should == @subject.get(:basic_button)
39
+
40
+ @subject.get(:basic_label).should.be.kind_of UILabel
41
+ @subject.get(:basic_label, in: @subject.view).should.be.kind_of UIView
42
+ @subject.get(:basic_label, in: @subject.view).should == @subject.get(:basic_label)
43
+ end
44
+
45
+ it "should allow getting the subviews by first, last and nth child" do
46
+ @subject.first(:repeated_label_3).should.be.kind_of UIView
47
+ @subject.first(:repeated_label_3, in: @subject.other_view).should.be.kind_of UIView
48
+ @subject.nth(:repeated_label_3, 1).should.be.kind_of UIButton
49
+ @subject.nth(:repeated_label_3, at: 1, in: @subject.other_view).should.be.kind_of UIButton
50
+ @subject.last(:repeated_label_3).should.be.kind_of UILabel
51
+ @subject.last(:repeated_label_3, in: @subject.other_view).should.be.kind_of UILabel
52
+ end
53
+
54
+ it "should allow getting all the subviews by name" do
55
+ views = @subject.all(:repeated_label_3)
56
+ views.length.should == 3
57
+ views[0].should.be.kind_of UIView
58
+ views[1].should.be.kind_of UIButton
59
+ views[2].should.be.kind_of UILabel
60
+
61
+ views = @subject.all(:repeated_label_3, in: @subject.other_view)
62
+ views.length.should == 3
63
+ views[0].should.be.kind_of UIView
64
+ views[1].should.be.kind_of UIButton
65
+ views[2].should.be.kind_of UILabel
66
+ end
67
+
68
+ it "should support missing methods" do
69
+ -> do
70
+ @subject.foo_bar_baz
71
+ end.should.raise(NoMethodError)
72
+ end
73
+
74
+ end
@@ -0,0 +1,27 @@
1
+ describe 'Blocks that are state specific' do
2
+
3
+ before do
4
+ @subject = TestLayoutState.new
5
+ end
6
+
7
+ it 'should run the initial blocks from layout' do
8
+ @subject.view.text.should == 'initial'
9
+ end
10
+
11
+ it 'should run the reapply blocks from layout' do
12
+ @subject.reapply!
13
+ @subject.view.text.should == 'reapply'
14
+ end
15
+
16
+ it 'should run the initial blocks from any method' do
17
+ any_view = @subject.any_view
18
+ any_view.text.should == 'initial'
19
+ end
20
+
21
+ it 'should run the reapply blocks from any method' do
22
+ any_view = @subject.any_view
23
+ @subject.reapply!(any_view)
24
+ any_view.text.should == 'reapply'
25
+ end
26
+
27
+ end
@@ -0,0 +1,102 @@
1
+ describe 'MotionKit utility methods' do
2
+
3
+ it 'should objc-ify a string' do
4
+ MotionKit.objective_c_method_name('this_is_my_string').should == 'thisIsMyString'
5
+ end
6
+
7
+ it 'should camel case a string' do
8
+ MotionKit.camel_case('this_is_my_string').should == 'ThisIsMyString'
9
+ end
10
+
11
+ it 'should return the UIView appearance class' do
12
+ MotionKit.appearance_class.should.be.kind_of(Class)
13
+ end
14
+
15
+ describe 'traversal methods' do
16
+ before do
17
+ view = UIView.new
18
+ view.tag = 1
19
+ subview1 = UIButton.new
20
+ subview1.tag = 2
21
+ subview2 = UILabel.new
22
+ subview2.tag = 3
23
+ subview3 = UILabel.new
24
+ subview3.tag = 4
25
+ subview4 = UIView.new
26
+ subview4.tag = 5
27
+ subview5 = UIButton.new
28
+ subview5.tag = 6
29
+ subview6 = UILabel.new
30
+ subview6.tag = 7
31
+
32
+ view.addSubview(subview1)
33
+ view.addSubview(subview2)
34
+ view.addSubview(subview3)
35
+ view.addSubview(subview4)
36
+
37
+ subview4.addSubview(subview5)
38
+ subview4.addSubview(subview6)
39
+
40
+ @subject = view
41
+ end
42
+
43
+ it 'should return the first UIButton that matches' do
44
+ found = MotionKit.find_first_view(@subject) { |view| view.is_a?(UIButton) }
45
+ found.should.be.kind_of(UIButton)
46
+ found.tag.should == 2
47
+ end
48
+
49
+ it 'should return the first UILabel that matches' do
50
+ found = MotionKit.find_first_view(@subject) { |view| view.is_a?(UILabel) }
51
+ found.should.be.kind_of(UILabel)
52
+ found.tag.should == 3
53
+ end
54
+
55
+ it 'should return nil for first UIImage' do
56
+ found = MotionKit.find_first_view(@subject) { |view| view.is_a?(UIImage) }
57
+ found.should == nil
58
+ end
59
+
60
+ it 'should return the last UIButton that matches' do
61
+ found = MotionKit.find_last_view(@subject) { |view| view.is_a?(UIButton) }
62
+ found.should.be.kind_of(UIButton)
63
+ found.tag.should == 6
64
+ end
65
+
66
+ it 'should return the last UILabel that matches' do
67
+ found = MotionKit.find_last_view(@subject) { |view| view.is_a?(UILabel) }
68
+ found.should.be.kind_of(UILabel)
69
+ found.tag.should == 7
70
+ end
71
+
72
+ it 'should return nil for last UIImage' do
73
+ found = MotionKit.find_last_view(@subject) { |view| view.is_a?(UIImage) }
74
+ found.should == nil
75
+ end
76
+
77
+ it 'should return all the UIButton that match' do
78
+ found = MotionKit.find_all_views(@subject) { |view| view.is_a?(UIButton) }
79
+ found.length.should == 2
80
+ found.map { |view| view.tag }.should == [2, 6]
81
+ end
82
+
83
+ it 'should return all the UILabel that match' do
84
+ found = MotionKit.find_all_views(@subject) { |view| view.is_a?(UILabel) }
85
+ found.length.should == 3
86
+ found.map { |view| view.tag }.should == [3, 4, 7]
87
+ end
88
+
89
+ it 'should return all the UIView that match' do
90
+ found = MotionKit.find_all_views(@subject) { |view| view.is_a?(UIView) }
91
+ found.length.should == 7
92
+ found.map { |view| view.tag }.should == [1, 2, 3, 4, 5, 6, 7]
93
+ end
94
+
95
+ it 'should return [] for all UIImages' do
96
+ found = MotionKit.find_all_views(@subject) { |view| view.is_a?(UIImage) }
97
+ found.should == []
98
+ end
99
+
100
+ end
101
+
102
+ end
@@ -0,0 +1,10 @@
1
+ describe 'Obj-C Selectors' do
2
+
3
+ it 'should work' do
4
+ -> do
5
+ layout = TestObjcSelectorsLayout.new
6
+ layout.view
7
+ end.should.not.raise
8
+ end
9
+
10
+ end
@@ -0,0 +1,67 @@
1
+ describe 'Orientation helpers' do
2
+
3
+ before do
4
+ @layout = MK::Layout.new
5
+ end
6
+
7
+ it 'should have orientation helpers' do
8
+ @layout.context({}) do
9
+ @layout.orientation?(UIInterfaceOrientationPortrait).should == true
10
+ @layout.orientation?(UIInterfaceOrientationLandscapeLeft).should == false
11
+ @layout.orientation?(UIInterfaceOrientationLandscapeRight).should == false
12
+ @layout.orientation?(UIInterfaceOrientationPortraitUpsideDown).should == false
13
+ end
14
+ end
15
+
16
+ it 'should have orientation (portrait?) helpers' do
17
+ @layout.context({}) do
18
+ @layout.portrait?.should == true
19
+ @layout.upright?.should == true
20
+ @layout.upside_down?.should == false
21
+ @layout.landscape?.should == false
22
+ @layout.landscape_left?.should == false
23
+ @layout.landscape_right?.should == false
24
+ end
25
+ end
26
+
27
+ it 'should have orientation (portrait do end) helpers' do
28
+ @layout.context({}) do
29
+ @check = false
30
+ @layout.portrait do
31
+ @check = true
32
+ end
33
+ @check.should == true
34
+
35
+ @check = false
36
+ @layout.upright do
37
+ @check = true
38
+ end
39
+ @check.should == true
40
+
41
+ @check = false
42
+ @layout.upside_down do
43
+ @check = true
44
+ end
45
+ @check.should == false
46
+
47
+ @check = false
48
+ @layout.landscape do
49
+ @check = true
50
+ end
51
+ @check.should == false
52
+
53
+ @check = false
54
+ @layout.landscape_left do
55
+ @check = true
56
+ end
57
+ @check.should == false
58
+
59
+ @check = false
60
+ @layout.landscape_right do
61
+ @check = true
62
+ end
63
+ @check.should == false
64
+ end
65
+ end
66
+
67
+ end
@@ -0,0 +1,19 @@
1
+ describe "layout parent methods" do
2
+ before do
3
+ @subject = TestParentLayout.new.view.subviews.first
4
+ end
5
+
6
+ it "should be a UIView" do
7
+ @subject.should.be.kind_of UIView
8
+ end
9
+
10
+ it "should set the first subview frame properly" do
11
+ @subject.frame.should == CGRectMake(0, 0, 100, 60)
12
+ end
13
+
14
+ it "should use parent to set its frame properly" do
15
+ @subject.subviews.first.frame.should == CGRectMake(10, 10, 50, 30)
16
+ @subject.subviews.first.subviews.first.frame.should == CGRectMake(25, 15, 40, 20)
17
+ end
18
+
19
+ end
@@ -0,0 +1,45 @@
1
+ describe MotionKit::Parent do
2
+
3
+ before do
4
+ uiview = UIView.new
5
+ uiview.frame = [[10, 20], [30, 40]]
6
+ @subject = MotionKit::Parent.new(uiview)
7
+ end
8
+
9
+ it "should return the x value" do
10
+ @subject.x.should == 10
11
+ end
12
+
13
+ it "should return the y value" do
14
+ @subject.y.should == 20
15
+ end
16
+
17
+ it "should return the width value" do
18
+ @subject.width.should == 30
19
+ end
20
+
21
+ it "should return the height value" do
22
+ @subject.height.should == 40
23
+ end
24
+
25
+ it "should return the center_x value" do
26
+ @subject.center_x.should == 15
27
+ end
28
+
29
+ it "should return the center_y value" do
30
+ @subject.center_y.should == 20
31
+ end
32
+
33
+ it "should return the center point" do
34
+ @subject.center.should == CGPointMake(15, 20)
35
+ end
36
+
37
+ it "should return the origin point" do
38
+ @subject.origin.should == CGPointMake(10, 20)
39
+ end
40
+
41
+ it "should return the size rect" do
42
+ @subject.size.should == CGSizeMake(30, 40)
43
+ end
44
+
45
+ end