motion-kit 0.9.6 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca8bcc4c3162610c0090bb119ed03e2c1ebf5484
4
- data.tar.gz: 002fd919664672e8b07fc6a56ac8103e4d61b75b
3
+ metadata.gz: 525e32728b35f92e5b149c067887539f4e1fd493
4
+ data.tar.gz: e5170c04a01756a4626c943448ab80e169884b19
5
5
  SHA512:
6
- metadata.gz: 125fd67fafeeccbed6778c15281a9bdd4f1e4cb48d28f57edd18dec56089345cec1069a3a7b2c407e194efe8241d9c6285179fff28354078467810027e1239b5
7
- data.tar.gz: 85d2bf979800eee4f63d2114fc0cda48a2a2918ee0b2a8f9f2a38828e97f482b571ef6e4702930ddc2d17ddecdd0f22368a35a79c99e817fd6f3c829a1764bb2
6
+ metadata.gz: 2088f89d374db7d138d4a878ecc88fb59f819485e6aae7cf6a2c01037796cbf4225b0b00db55df2e255c82ec434670016c3babbb5521e73498bafd2c1d2a2d84
7
+ data.tar.gz: a7f7d63d194d14835d6d357f64cfb9ad33217f8d060a9d9fc401ea07e1b29c31a8d069e497bea7cbab3d257c772721a3e31e221c0358da8949283fc366647a34
data/README.md CHANGED
@@ -11,12 +11,11 @@
11
11
  - [Frame geometry][readmore-frames]
12
12
  - [CoreAnimation][readmore-coreanimation]
13
13
  - [NSMenu/NSMenuItem][readmore-nsmenu]
14
- - [Joybox][readmore-joybox] *TODO*
15
- - [SpriteKit][readmore-spritekit] *TODO*
16
- 4. Non-polluting
17
- 5. ProMotion/RMQ/SugarCube-compatible (kind of goes hand-in-hand with non-polluting)
18
- 6. Styles and layouts are "just code" (not hash-based like in Teacup)
19
- 7. Written by [the authors][authors] of [ProMotion][] and [Teacup][]
14
+ 4. Easily extendable to support custom, mini-DSLs
15
+ 5. Non-polluting
16
+ 6. ProMotion/RMQ/SugarCube-compatible (kind of goes hand-in-hand with being non-polluting)
17
+ 7. Styles and layouts are "just code" (not hash-based like in Teacup)
18
+ 8. Written by [the authors][authors] of [ProMotion][] and [Teacup][]
20
19
 
21
20
  [authors]: CONTRIBUTORS.md
22
21
  [Colin]: https://github.com/colinta
@@ -24,14 +23,14 @@
24
23
  [ProMotion]: https://github.com/clearsightstudio/ProMotion
25
24
  [RMQ]: https://github.com/infinitered/rmq
26
25
  [Teacup]: https://github.com/rubymotion/teacup
26
+ [SweetKit]: https://github.com/rubymotion/sweet-kit
27
27
 
28
+ [READMORE]: https://github.com/rubymotion/motion-kit/blob/master/READMORE.md
28
29
  [readmore-uikit]: https://github.com/rubymotion/motion-kit/blob/master/READMORE.md#uikit
29
30
  [readmore-applicationkit]: https://github.com/rubymotion/motion-kit/blob/master/READMORE.md#applicationkit
30
- [readmore-joybox]: https://github.com/rubymotion/motion-kit/blob/master/READMORE.md#joybox
31
- [readmore-spritekit]: https://github.com/rubymotion/motion-kit/blob/master/READMORE.md#spritekit
32
31
  [readmore-coreanimation]: https://github.com/rubymotion/motion-kit/blob/master/READMORE.md#coreanimation
33
- [readmore-frames]: https://github.com/rubymotion/motion-kit/blob/master/READMORE.md#frames
34
- [readmore-autolayout]: https://github.com/rubymotion/motion-kit/blob/master/READMORE.md#autolayout
32
+ [readmore-frames]: https://github.com/rubymotion/motion-kit/blob/master/READMORE.md#frames
33
+ [readmore-autolayout]: https://github.com/rubymotion/motion-kit/blob/master/READMORE.md#autolayout
35
34
  [readmore-nsmenu]: https://github.com/rubymotion/motion-kit/blob/master/READMORE.md#nsmenu
36
35
 
37
36
 
@@ -370,6 +369,16 @@ class CustomLayout < MK::UIViewLayout
370
369
  end
371
370
  ```
372
371
 
372
+ ### Even more information...
373
+
374
+ ...is in the [READMORE][] document. I re-explain some of these topics, go into
375
+ some more detail, that kinda thing. Basically an overflow document for topics I
376
+ don't want to stuff into the README.
377
+
378
+
379
+ ## MotionKit extensions
380
+
381
+ These are all built-in, unless otherwise specified.
373
382
 
374
383
  ### Frames
375
384
 
@@ -641,10 +650,21 @@ class MainController < UIViewController
641
650
  end
642
651
  ```
643
652
 
653
+ ### MotionKit::Events
654
+
655
+ gem install motion-kit-events
656
+
657
+ Adds `on :event` and `trigger :event` methods to `MK::Layout` objects. These
658
+ can be used to send events from the Layout to your controller, further
659
+ simplifying the controller code (and usually making it more testable). See the
660
+ [MotionKit::Events documentation][motion-kit-events] for more information.
661
+
662
+ [motion-kit-events]: https://github.com/rubymotion/motion-kit-events
663
+
644
664
 
645
- ### Some handy tricks and Features
665
+ ## Some handy tricks and Features
646
666
 
647
- #### Orientation specific styles
667
+ ### Orientation specific styles
648
668
 
649
669
  These are available on iOS.
650
670
 
@@ -659,7 +679,7 @@ add UIView, :container do
659
679
  end
660
680
  ```
661
681
 
662
- #### Update views via 'initial', 'reapply', and 'deferred'
682
+ ### Update views via 'initial', 'reapply', and 'deferred'
663
683
 
664
684
  If you call 'layout.reapply!', your style methods will be called again (but
665
685
  NOT the `layout` method). You very well might want to control what methods get
@@ -698,7 +718,7 @@ end
698
718
  ```
699
719
 
700
720
 
701
- #### Apply styles via module
721
+ ### Apply styles via module
702
722
 
703
723
  ```ruby
704
724
  module AppStyles
@@ -727,8 +747,25 @@ class LoginLayout < MotionKit::Layout
727
747
  end
728
748
  ```
729
749
 
750
+ ### Using SweetKit
751
+
752
+ The [SweetKit][] gem combines MotionKit and SugarCube. The helpers it provides
753
+ allow for even more expressiveness, for instance:
754
+
755
+ ```ruby
756
+ add UITextField do
757
+ return_key_type :email
758
+ text_alignment :right
759
+ end
760
+ ```
761
+
762
+ The OS X helpers are really nice, because it tries to hide most of the
763
+ annoying subtletees of the NSCell/NSControl dichotomy.
764
+
765
+ gem install sweet-kit
766
+
730
767
 
731
- #### Setting a custom root view
768
+ ### Setting a custom root view
732
769
 
733
770
  If you need to use a custom root view, you can use the `root` method from within
734
771
  the `layout` method. When you create or assign the root view this way, you must
@@ -742,6 +779,29 @@ def layout
742
779
  end
743
780
  ```
744
781
 
782
+ You can also pass in a root view to your layout, like this:
783
+
784
+ ```ruby
785
+ def loadView
786
+ @layout = MyLayout.new(root: self.view)
787
+ end
788
+ ```
789
+
790
+ In this case, if you want to style the root view, just refer to it in your layout:
791
+
792
+ ```ruby
793
+ def layout
794
+ root :my_root_view do
795
+ # ...
796
+ end
797
+ end
798
+
799
+ def my_root_view_style
800
+ background_color UIColor.grayColor
801
+ end
802
+ ```
803
+
804
+ This is especially useful with collection views, table views, and table cells.
745
805
 
746
806
  # Contributing
747
807
 
@@ -5,14 +5,24 @@
5
5
  module MotionKit
6
6
  class BaseLayout
7
7
 
8
+ delegate_method_fix :adjust
8
9
  delegate_method_fix :frame
9
10
  delegate_method_fix :left
10
11
  delegate_method_fix :right
11
12
  delegate_method_fix :up
12
13
  delegate_method_fix :down
13
14
  delegate_method_fix :origin
15
+ delegate_method_fix :thinner
16
+ delegate_method_fix :wider
17
+ delegate_method_fix :shorter
18
+ delegate_method_fix :taller
14
19
  delegate_method_fix :size
15
20
  delegate_method_fix :center
21
+ delegate_method_fix :shadow
22
+ delegate_method_fix :tree
23
+ delegate_method_fix :root
24
+ delegate_method_fix :restore
25
+ delegate_method_fix :blink
16
26
 
17
27
  end
18
28
  end
@@ -2,6 +2,7 @@
2
2
  module MotionKit
3
3
  class NSWindowLayout
4
4
 
5
+ overrides :frame
5
6
  def frame(value, autosave_name=nil)
6
7
  retval = target.setFrame(value, display: true)
7
8
  if autosave_name
@@ -16,13 +16,18 @@ module MotionKit
16
16
 
17
17
  attr :parent
18
18
 
19
- def initialize
19
+ def initialize(args={})
20
20
  # @layout is the object we look in for style methods
21
21
  @layout = self
22
22
  # the Layout object that implements custom style methods. Leave this as nil
23
23
  # in the initializer.
24
24
  @layout_delegate = nil
25
25
  @layout_state = :initial
26
+ # You can set a root view by using .new(root: some_view)
27
+ if args[:root]
28
+ @preset_root = args[:root]
29
+ view # Prebuild the view
30
+ end
26
31
  end
27
32
 
28
33
  def set_layout(layout)
@@ -48,7 +48,7 @@ module MotionKit
48
48
 
49
49
  end
50
50
 
51
- # The parent view. This method builds the layout and returns the root view.
51
+ # The main view. This method builds the layout and returns the root view.
52
52
  def view
53
53
  if @layout != self
54
54
  return @layout.view
@@ -77,7 +77,11 @@ module MotionKit
77
77
  if element.is_a?(Symbol)
78
78
  element_id = element
79
79
  # See note below about why we don't need to `apply(:default_root)`
80
- element = default_root
80
+ element = preset_root || default_root
81
+ elsif @preset_root
82
+ # You're trying to make two roots, one at initialization
83
+ # and one in your layout itself.
84
+ raise ContextConflictError.new("Already created the root view")
81
85
  end
82
86
 
83
87
  @view = initialize_view(element)
@@ -268,6 +272,12 @@ module MotionKit
268
272
 
269
273
  protected
270
274
 
275
+ def preset_root
276
+ # Set in the initializer
277
+ # TreeLayout.new(root: some_view)
278
+ @preset_root
279
+ end
280
+
271
281
  # This method builds the layout and returns the root view.
272
282
  def build_view
273
283
  # Only in the 'layout' method will we allow default container to be
@@ -1,3 +1,3 @@
1
1
  module MotionKit
2
- VERSION = '0.9.6'
2
+ VERSION = '0.10.0'
3
3
  end
@@ -0,0 +1,36 @@
1
+ describe MotionKit::Layout do
2
+ before do
3
+ @view = UIView.new
4
+ @subject = TestCustomRootLayout.new(root: @view)
5
+ end
6
+
7
+ it "should set the root view to the @view instance" do
8
+ @subject.view.should == @view
9
+ end
10
+
11
+ it "should still create subviews" do
12
+ @subject.view.subviews.first.should.be.kind_of UIButton
13
+ @subject.view.subviews.first.subviews.first.should.be.kind_of UILabel
14
+ end
15
+
16
+ it "should call style method" do
17
+ @subject.view.backgroundColor.should == UIColor.blueColor
18
+ end
19
+
20
+ it "should raise exception if you try to specify a root inside the layout too" do
21
+ -> do
22
+ subject = TestCustomDuplicateRootLayout.new(root: @view)
23
+ subject.view
24
+ end.should.raise(MotionKit::ContextConflictError)
25
+ end
26
+
27
+ it "should allow multiple nested layouts" do
28
+ @subject = TestMultipleNestedLayout.new
29
+ @subject.view.backgroundColor.should == UIColor.purpleColor
30
+ @subject.view.subviews.first.should.be.kind_of TestNestedView
31
+ @subject.view.subviews.first.backgroundColor.should == UIColor.yellowColor
32
+ @subject.view.subviews.first.subviews.first.should.be.kind_of UIButton
33
+ @subject.view.subviews.first.subviews.first.backgroundColor.should == UIColor.blackColor
34
+ end
35
+
36
+ end
@@ -0,0 +1,36 @@
1
+ describe MotionKit::Layout do
2
+ before do
3
+ @view = NSView.new
4
+ @subject = TestCustomRootLayout.new(root: @view)
5
+ end
6
+
7
+ it "should set the root view to the @view instance" do
8
+ @subject.view.should == @view
9
+ end
10
+
11
+ it "should still create subviews" do
12
+ @subject.view.subviews.first.should.be.kind_of NSButton
13
+ @subject.view.subviews.first.subviews.first.should.be.kind_of NSTextField
14
+ end
15
+
16
+ it "should call style method" do
17
+ @subject.view.backgroundColor.should == NSColor.blueColor
18
+ end
19
+
20
+ it "should raise exception if you try to specify a root inside the layout too" do
21
+ -> do
22
+ subject = TestCustomDuplicateRootLayout.new(root: @view)
23
+ subject.view
24
+ end.should.raise(MotionKit::ContextConflictError)
25
+ end
26
+
27
+ it "should allow multiple nested layouts" do
28
+ @subject = TestMultipleNestedLayout.new
29
+ @subject.view.backgroundColor.should == NSColor.purpleColor
30
+ @subject.view.subviews.first.should.be.kind_of TestNestedView
31
+ @subject.view.subviews.first.backgroundColor.should == NSColor.yellowColor
32
+ @subject.view.subviews.first.subviews.first.should.be.kind_of NSButton
33
+ @subject.view.subviews.first.subviews.first.backgroundColor.should == NSColor.blackColor
34
+ end
35
+
36
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin T.A. Gray
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-18 00:00:00.000000000 Z
12
+ date: 2014-05-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dbt
@@ -95,6 +95,7 @@ files:
95
95
  - spec/ios/constraints_helpers/view_lookup_constraints_spec.rb
96
96
  - spec/ios/create_layout_spec.rb
97
97
  - spec/ios/custom_layout_spec.rb
98
+ - spec/ios/custom_root_layout_spec.rb
98
99
  - spec/ios/deferred_spec.rb
99
100
  - spec/ios/device_helpers_spec.rb
100
101
  - spec/ios/frame_helper_spec.rb
@@ -121,6 +122,7 @@ files:
121
122
  - spec/osx/constraints_helpers/size_constraints_spec.rb
122
123
  - spec/osx/create_menu_spec.rb
123
124
  - spec/osx/create_via_extensions_spec.rb
125
+ - spec/osx/custom_root_layout_spec.rb
124
126
  - spec/osx/deferred_spec.rb
125
127
  - spec/osx/frame_helper_spec.rb
126
128
  - spec/osx/menu_extensions_spec.rb
@@ -169,6 +171,7 @@ test_files:
169
171
  - spec/ios/constraints_helpers/view_lookup_constraints_spec.rb
170
172
  - spec/ios/create_layout_spec.rb
171
173
  - spec/ios/custom_layout_spec.rb
174
+ - spec/ios/custom_root_layout_spec.rb
172
175
  - spec/ios/deferred_spec.rb
173
176
  - spec/ios/device_helpers_spec.rb
174
177
  - spec/ios/frame_helper_spec.rb
@@ -195,6 +198,7 @@ test_files:
195
198
  - spec/osx/constraints_helpers/size_constraints_spec.rb
196
199
  - spec/osx/create_menu_spec.rb
197
200
  - spec/osx/create_via_extensions_spec.rb
201
+ - spec/osx/custom_root_layout_spec.rb
198
202
  - spec/osx/deferred_spec.rb
199
203
  - spec/osx/frame_helper_spec.rb
200
204
  - spec/osx/menu_extensions_spec.rb