motion-pixate-layout 0.0.4 → 0.0.5
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.
- data/Gemfile.lock +1 -1
- data/README.md +4 -0
- data/lib/motion-pixate-layout/proxy.rb +55 -28
- data/lib/motion-pixate-layout/version.rb +1 -1
- data/motion-pixate-layout.gemspec +2 -2
- data/spec/lib/layout_spec.rb +16 -1
- metadata +4 -2
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -14,6 +14,9 @@ class MyViewController < UIViewController
|
|
14
14
|
pixate_layout '#my-view.fancy' do
|
15
15
|
UILabel '#title-label.small.green', text: 'My Title'
|
16
16
|
UIButton '#ok-button.call-to-action'
|
17
|
+
UIView '#parent' do
|
18
|
+
UILabel '#child'
|
19
|
+
end
|
17
20
|
end
|
18
21
|
end
|
19
22
|
````
|
@@ -29,6 +32,7 @@ This code hooks into UIViewController's `viewDidLoad` mode and:
|
|
29
32
|
1. Adds a UIButton with these attributes as a subview of the controller's view:
|
30
33
|
* styleId: 'ok-button'
|
31
34
|
* styleClass: 'call-to-action'
|
35
|
+
1. Adds a UIView with styleId of 'parent' to the controllers view with a child subview with styleId 'child'
|
32
36
|
|
33
37
|
## Accessing subviews
|
34
38
|
|
@@ -14,40 +14,21 @@ module MotionPixateLayout
|
|
14
14
|
controller.pixate_layout
|
15
15
|
end
|
16
16
|
|
17
|
-
def method_missing(method_name, *args)
|
18
|
-
if Kernel.constants.include?(method_name.to_sym)
|
19
|
-
view_class = Kernel.const_get(method_name.to_s)
|
20
|
-
raise "#{view_class.name} is not a known UIView subclass" unless view_class <= UIView
|
21
|
-
return subview(view_class, *args)
|
22
|
-
else
|
23
|
-
raise "#{method_name} is not defined. Should be a subclass of UIView."
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def subview(subview_class, selector, attributes = {})
|
28
|
-
selector = MotionPixateLayout::Selector.new(selector)
|
29
|
-
|
30
|
-
subview_class.new.tap do |subview|
|
31
|
-
subview.styleId = selector.style_id
|
32
|
-
subview.styleClass = selector.style_classes.join(" ")
|
33
|
-
|
34
|
-
attributes.each do |key, value|
|
35
|
-
subview.send "#{key}=", value
|
36
|
-
end
|
37
|
-
|
38
|
-
view.addSubview subview
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
17
|
def run
|
43
18
|
apply_selector
|
44
19
|
apply_attributes
|
45
20
|
run_blocks controller, layout.before
|
46
|
-
run_blocks
|
21
|
+
view_proxy.run_blocks
|
47
22
|
run_blocks controller, layout.after
|
48
23
|
controller.view.updateStyles
|
49
24
|
end
|
50
25
|
|
26
|
+
def view_proxy
|
27
|
+
@view_proxy ||= ViewProxy.new(self.view).tap do |proxy|
|
28
|
+
proxy.blocks = layout.blocks
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
51
32
|
def apply_selector
|
52
33
|
if layout.selector
|
53
34
|
view.styleId = layout.selector.style_id
|
@@ -55,15 +36,61 @@ module MotionPixateLayout
|
|
55
36
|
end
|
56
37
|
end
|
57
38
|
|
39
|
+
def run_blocks(context, blocks)
|
40
|
+
blocks.each { |block| context.instance_eval &block }
|
41
|
+
end
|
42
|
+
|
58
43
|
def apply_attributes
|
59
44
|
layout.view_attributes ||= []
|
60
45
|
layout.view_attributes.each do |key, value|
|
61
46
|
view.public_send "#{key}=", value
|
62
47
|
end
|
63
48
|
end
|
49
|
+
end
|
64
50
|
|
65
|
-
|
66
|
-
|
51
|
+
class ViewProxy
|
52
|
+
attr_accessor :blocks
|
53
|
+
attr_reader :view
|
54
|
+
|
55
|
+
def initialize(view)
|
56
|
+
@view = view
|
57
|
+
self.blocks = []
|
67
58
|
end
|
59
|
+
|
60
|
+
def subview(subview_class, selector, attributes = {}, &block)
|
61
|
+
selector = MotionPixateLayout::Selector.new(selector)
|
62
|
+
|
63
|
+
subview_class.new.tap do |subview|
|
64
|
+
subview.styleId = selector.style_id
|
65
|
+
subview.styleClass = selector.style_classes.join(" ")
|
66
|
+
|
67
|
+
attributes.each do |key, value|
|
68
|
+
subview.send "#{key}=", value
|
69
|
+
end
|
70
|
+
|
71
|
+
view.addSubview subview
|
72
|
+
if block_given?
|
73
|
+
ViewProxy.new(subview).tap do |proxy|
|
74
|
+
proxy.blocks << block
|
75
|
+
proxy.run_blocks
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def method_missing(method_name, *args, &block)
|
82
|
+
if Kernel.constants.include?(method_name.to_sym)
|
83
|
+
view_class = Kernel.const_get(method_name.to_s)
|
84
|
+
raise "#{view_class.name} is not a known UIView subclass" unless view_class <= UIView
|
85
|
+
return subview(view_class, *args, &block)
|
86
|
+
else
|
87
|
+
raise "#{method_name} is not defined. Should be a subclass of UIView."
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def run_blocks
|
92
|
+
blocks.each { |block| self.instance_eval &block }
|
93
|
+
end
|
94
|
+
|
68
95
|
end
|
69
96
|
end
|
@@ -2,8 +2,8 @@
|
|
2
2
|
require File.expand_path('../lib/motion-pixate-layout/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ["Joe Lind"]
|
6
|
-
gem.email = ["joe@terriblelabs.com"]
|
5
|
+
gem.authors = ["Joe Lind", "Nick Pachulski"]
|
6
|
+
gem.email = ["joe@terriblelabs.com", "hello@nickpachulski.com"]
|
7
7
|
gem.description = "A RubyMotion DSL to add subviews that are styled with Pixate"
|
8
8
|
gem.summary = "A RubyMotion DSL to add subviews that are styled with Pixate"
|
9
9
|
gem.homepage = 'http://github.com/terriblelabs/motion-pixate-layout'
|
data/spec/lib/layout_spec.rb
CHANGED
@@ -10,7 +10,11 @@ describe "MotionPixateLayout::Layout" do
|
|
10
10
|
|
11
11
|
pixate_layout '#view-id.view-class.view-class-2', accessibilityLabel: 'main view' do
|
12
12
|
UILabel '#style-id.class1.class2', text: 'Test Label'
|
13
|
-
UIView '#subview'
|
13
|
+
UIView '#subview' do
|
14
|
+
UILabel '#grandchild' do
|
15
|
+
UIButton '#great_grandchild'
|
16
|
+
end
|
17
|
+
end
|
14
18
|
end
|
15
19
|
|
16
20
|
after_pixate_layout do
|
@@ -20,6 +24,17 @@ describe "MotionPixateLayout::Layout" do
|
|
20
24
|
|
21
25
|
tests TestViewController
|
22
26
|
|
27
|
+
it 'recursively adds subviews supplied in blocks' do
|
28
|
+
|
29
|
+
controller.subviews['subview'].subviews.size.should == 1
|
30
|
+
controller.subviews['subview'].subviews.first.tap do |grandchild|
|
31
|
+
grandchild.styleId.should == 'grandchild'
|
32
|
+
grandchild.should.be.kind_of UILabel
|
33
|
+
grandchild.subviews.size.should == 1
|
34
|
+
grandchild.subviews.first.styleId.should == 'great_grandchild'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
23
38
|
it "is added to UIViewController" do
|
24
39
|
UIViewController.should.respond_to :pixate_layout
|
25
40
|
end
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-pixate-layout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Joe Lind
|
9
|
+
- Nick Pachulski
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
13
|
+
date: 2013-06-11 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: motion-pixate
|
@@ -62,6 +63,7 @@ dependencies:
|
|
62
63
|
description: A RubyMotion DSL to add subviews that are styled with Pixate
|
63
64
|
email:
|
64
65
|
- joe@terriblelabs.com
|
66
|
+
- hello@nickpachulski.com
|
65
67
|
executables: []
|
66
68
|
extensions: []
|
67
69
|
extra_rdoc_files: []
|