motion-kit 0.10.0 → 0.10.1

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: 525e32728b35f92e5b149c067887539f4e1fd493
4
- data.tar.gz: e5170c04a01756a4626c943448ab80e169884b19
3
+ metadata.gz: c38cc123b569dc34b2b5b8b829d7520d549f1c84
4
+ data.tar.gz: 36d097e9d6ad953a6f245ce2550e223a30a6db88
5
5
  SHA512:
6
- metadata.gz: 2088f89d374db7d138d4a878ecc88fb59f819485e6aae7cf6a2c01037796cbf4225b0b00db55df2e255c82ec434670016c3babbb5521e73498bafd2c1d2a2d84
7
- data.tar.gz: a7f7d63d194d14835d6d357f64cfb9ad33217f8d060a9d9fc401ea07e1b29c31a8d069e497bea7cbab3d257c772721a3e31e221c0358da8949283fc366647a34
6
+ metadata.gz: 6f88abc1b00777b63b6272626aed88526f93b459b0e9ab6daf0c815921ec403b23d954e6e70b19517b584b713fe3160de649f215fd9da302eba780dfc5c663c7
7
+ data.tar.gz: 93e2b1fd29e5b046ccd64b4fa67569a64b6c5ffd491f0017320be5970609c61f39eb7e1047fbc5cd03164c258a80e483ddc60052212cb2edd5656a996621df0f
data/README.md CHANGED
@@ -270,6 +270,46 @@ end
270
270
  ```
271
271
 
272
272
 
273
+ ### Setting a custom root view
274
+
275
+ If you need to use a custom root view, you can use the `root` method from within
276
+ the `layout` method. When you create or assign the root view this way, you must
277
+ assign subviews and styles *inside* a block that you pass to `root`.
278
+
279
+ ```ruby
280
+ def layout
281
+ root(SomeOtherViewclass) do
282
+ add UILabel
283
+ end
284
+ end
285
+ ```
286
+
287
+ You can also pass in a root view to your layout, like this:
288
+
289
+ ```ruby
290
+ def loadView
291
+ @layout = MyLayout.new(root: self.view).build
292
+ end
293
+ ```
294
+
295
+ Make sure to call `.build`; otherwise, the layout will be returned but the view not built.
296
+
297
+ In this case, if you want to style the root view, just refer to it in your layout:
298
+
299
+ ```ruby
300
+ def layout
301
+ root :my_root_view do
302
+ # ...
303
+ end
304
+ end
305
+
306
+ def my_root_view_style
307
+ background_color UIColor.grayColor
308
+ end
309
+ ```
310
+
311
+ This is especially useful with collection views, table views, and table cells.
312
+
273
313
  ### How do styles get applied?
274
314
 
275
315
  If you've used RMQ's Stylers, you'll recognize a very similar pattern here. In
@@ -638,7 +678,7 @@ class MainController < UIViewController
638
678
 
639
679
  def loadView
640
680
  @layout = MainLayout.new
641
- self.view = @layout
681
+ self.view = @layout.view
642
682
  end
643
683
 
644
684
  # for the constraints to work reliably they should be added in this method:
@@ -765,44 +805,6 @@ annoying subtletees of the NSCell/NSControl dichotomy.
765
805
  gem install sweet-kit
766
806
 
767
807
 
768
- ### Setting a custom root view
769
-
770
- If you need to use a custom root view, you can use the `root` method from within
771
- the `layout` method. When you create or assign the root view this way, you must
772
- assign subviews and styles *inside* a block that you pass to `root`.
773
-
774
- ```ruby
775
- def layout
776
- root(SomeOtherViewclass) do
777
- add UILabel
778
- end
779
- end
780
- ```
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.
805
-
806
808
  # Contributing
807
809
 
808
810
  We welcome your contributions! Please be sure to run the specs before you do,
@@ -24,10 +24,7 @@ module MotionKit
24
24
  @layout_delegate = nil
25
25
  @layout_state = :initial
26
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
27
+ @preset_root = args[:root]
31
28
  end
32
29
 
33
30
  def set_layout(layout)
@@ -11,7 +11,13 @@ module MotionKit
11
11
  return nil if klass.nil? && self == BaseLayout
12
12
  return @targets || superclass.targets if klass.nil?
13
13
  @targets = klass
14
+
15
+ if BaseLayout.target_klasses.key?(klass) && BaseLayout.target_klasses[klass] != self
16
+ NSLog('WARNING! The class “%@” was registered with the layout class “%@”',
17
+ klass, BaseLayout.target_klasses[klass])
18
+ end
14
19
  BaseLayout.target_klasses[klass] = self
20
+
15
21
  nil
16
22
  end
17
23
 
@@ -56,6 +56,18 @@ module MotionKit
56
56
  @view ||= build_view
57
57
  end
58
58
 
59
+ # Builds the layout and then returns self for chaining.
60
+ def build
61
+ view
62
+ self
63
+ end
64
+
65
+ # Checks if the layout has been built yet or not.
66
+ def built?
67
+ !@view.nil?
68
+ end
69
+ alias build? built? # just in case
70
+
59
71
  # Assign a view to act as the 'root' view for this layout. This method can
60
72
  # only be called once, and must be called before `add` is called for the
61
73
  # first time (otherwise `add` will create a default root view). This method
@@ -78,13 +90,13 @@ module MotionKit
78
90
  element_id = element
79
91
  # See note below about why we don't need to `apply(:default_root)`
80
92
  element = preset_root || default_root
81
- elsif @preset_root
93
+ elsif @preset_root && @preset_root != element
82
94
  # You're trying to make two roots, one at initialization
83
95
  # and one in your layout itself.
84
96
  raise ContextConflictError.new("Already created the root view")
85
97
  end
86
98
 
87
- @view = initialize_view(element)
99
+ @view = initialize_element(element)
88
100
  if block
89
101
  if @context
90
102
  raise ContextConflictError.new("Already in a context")
@@ -104,7 +116,7 @@ module MotionKit
104
116
 
105
117
  # instantiates a view, possibly running a 'layout block' to add child views.
106
118
  def create(element, element_id=nil, &block)
107
- element = initialize_view(element)
119
+ element = initialize_element(element)
108
120
 
109
121
  if element_id
110
122
  # We set the optional id and call the '_style' method, if it's been
@@ -168,7 +180,7 @@ module MotionKit
168
180
  # make sure we have a target - raises NoContextError if none exists
169
181
  self.target
170
182
 
171
- element = initialize_view(element)
183
+ element = initialize_element(element)
172
184
  unless @context
173
185
  create_default_root_context
174
186
  end
@@ -264,7 +276,7 @@ module MotionKit
264
276
  # view-related methods, but actually this method *only* gets called
265
277
  # from within the `layout` method, and so should already be inside the
266
278
  # correct Layout subclass.
267
- @context = root(default_root)
279
+ @context = root(preset_root || default_root)
268
280
  else
269
281
  raise NoContextError.new("No top level view specified (missing outer 'create' method?)")
270
282
  end
@@ -322,7 +334,7 @@ module MotionKit
322
334
  #
323
335
  # Accepts a view instance, a class (which is instantiated with 'new') or a
324
336
  # `ViewLayout`, which returns the root view.
325
- def initialize_view(elem)
337
+ def initialize_element(elem)
326
338
  if elem.is_a?(Class) && elem < TreeLayout
327
339
  elem = elem.new_child(@layout, nil, self).view
328
340
  elsif elem.is_a?(Class)
@@ -1,3 +1,3 @@
1
1
  module MotionKit
2
- VERSION = '0.10.0'
2
+ VERSION = '0.10.1'
3
3
  end
@@ -33,4 +33,25 @@ describe MotionKit::Layout do
33
33
  @subject.view.subviews.first.subviews.first.backgroundColor.should == UIColor.blackColor
34
34
  end
35
35
 
36
+ it "shouldn't build if `build` or `view` aren't called" do
37
+ @subject.built?.should == false
38
+ end
39
+
40
+ it "should build when `build` is called" do
41
+ @subject.build
42
+ @subject.built?.should == true
43
+ end
44
+
45
+ it "should build when `view` is called" do
46
+ @subject.view
47
+ @subject.built?.should == true
48
+ end
49
+
50
+ it "should allow bare styles in layout when root is specified in initializer" do
51
+ @subject = TestNoRootLayout.new(root: @view).build
52
+ @subject.view.should == @view
53
+ @subject.view.backgroundColor.should == UIColor.redColor
54
+ @subject.view.subviews.first.should.be.kind_of?(UILabel)
55
+ end
56
+
36
57
  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.10.0
4
+ version: 0.10.1
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-20 00:00:00.000000000 Z
12
+ date: 2014-05-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dbt