motion-pixate-layout 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -0
- data/README.md +5 -2
- data/Rakefile +3 -1
- data/lib/motion-pixate-layout/fake_pixate/ui_view.rb +5 -0
- data/lib/motion-pixate-layout/layout.rb +5 -53
- data/lib/motion-pixate-layout/proxy.rb +61 -0
- data/lib/motion-pixate-layout/version.rb +1 -1
- data/lib/motion-pixate-layout/z_core_extensions/ui_view_controller.rb +21 -20
- metadata +5 -2
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
# MotionPixateLayout
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/terriblelabs/motion-pixate-layout.png?branch=master)](https://travis-ci.org/terriblelabs/motion-pixate-layout)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/terriblelabs/motion-pixate-layout.png)](https://codeclimate.com/github/terriblelabs/motion-pixate-layout)
|
5
|
+
|
3
6
|
This project adds a simple DSL to your Rubymotion UIViewControllers to create subviews to be styled with [Pixate](http://www.pixate.com/).
|
4
7
|
|
5
|
-
The idea is inspired by [Teacup](https://github.com/rubymotion/teacup), which has an awesome layout/subview DSL for
|
8
|
+
The idea is inspired by [Teacup](https://github.com/rubymotion/teacup), which has an awesome layout/subview DSL for laying out your controllers. While this DSL is great, Teacup brings in a lot of style/stylesheet features that are not useful to Pixate users. MotionPixateLayout also adds a convenient shorthand selector to quickly set the styleId and styleClass of subviews.
|
6
9
|
|
7
10
|
## A quick example
|
8
11
|
|
@@ -36,7 +39,7 @@ class MyViewController < UIViewController
|
|
36
39
|
# pixate_layout { ... }
|
37
40
|
|
38
41
|
def update_label_text
|
39
|
-
subviews['title-label'] = 'An updated title'
|
42
|
+
subviews['title-label'].text = 'An updated title'
|
40
43
|
end
|
41
44
|
end
|
42
45
|
````
|
data/Rakefile
CHANGED
@@ -10,5 +10,7 @@ Motion::Project::App.setup do |app|
|
|
10
10
|
app.name = 'testSuite'
|
11
11
|
app.identifier = 'com.terriblelabs.motionPixateLayout.testSuite'
|
12
12
|
|
13
|
-
|
13
|
+
if File.exist?('vendor/PXEngine.framework')
|
14
|
+
app.pixate.framework = 'vendor/PXEngine.framework'
|
15
|
+
end
|
14
16
|
end
|
@@ -1,60 +1,12 @@
|
|
1
1
|
module MotionPixateLayout
|
2
2
|
class Layout
|
3
3
|
attr_accessor :selector
|
4
|
+
attr_reader :after, :before, :blocks
|
4
5
|
|
5
|
-
def
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def each
|
10
|
-
blocks.each do |block|
|
11
|
-
yield block
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def after
|
16
|
-
@_after ||= []
|
17
|
-
end
|
18
|
-
|
19
|
-
def before
|
20
|
-
@_before ||= []
|
21
|
-
end
|
22
|
-
|
23
|
-
def blocks
|
24
|
-
@_blocks ||= []
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class Proxy
|
29
|
-
attr_reader :view
|
30
|
-
|
31
|
-
def initialize(view)
|
32
|
-
@view = view
|
33
|
-
end
|
34
|
-
|
35
|
-
def method_missing(method_name, *args)
|
36
|
-
if Kernel.constants.include?(method_name.to_sym)
|
37
|
-
view_class = Kernel.const_get(method_name.to_s)
|
38
|
-
raise "#{view_class.name} is not a known UIView subclass" unless view_class < UIView
|
39
|
-
return subview(view_class, *args)
|
40
|
-
else
|
41
|
-
raise "#{method_name} is not defined. Should be a subclass of UIView."
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def subview(subview_class, selector, attributes = {})
|
46
|
-
selector = MotionPixateLayout::Selector.new(selector)
|
47
|
-
|
48
|
-
subview_class.new.tap do |subview|
|
49
|
-
subview.styleId = selector.style_id
|
50
|
-
subview.styleClass = selector.style_classes.join(" ")
|
51
|
-
|
52
|
-
attributes.each do |key, value|
|
53
|
-
subview.send "#{key}=", value
|
54
|
-
end
|
55
|
-
|
56
|
-
view.addSubview subview
|
57
|
-
end
|
6
|
+
def initialize
|
7
|
+
@before = []
|
8
|
+
@after = []
|
9
|
+
@blocks = []
|
58
10
|
end
|
59
11
|
end
|
60
12
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module MotionPixateLayout
|
2
|
+
class Proxy
|
3
|
+
attr_reader :controller
|
4
|
+
|
5
|
+
def initialize(controller)
|
6
|
+
@controller = controller
|
7
|
+
end
|
8
|
+
|
9
|
+
def view
|
10
|
+
controller.view
|
11
|
+
end
|
12
|
+
|
13
|
+
def layout
|
14
|
+
controller.pixate_layout
|
15
|
+
end
|
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
|
+
def run
|
43
|
+
apply_selector
|
44
|
+
run_blocks controller, layout.before
|
45
|
+
run_blocks self, layout.blocks
|
46
|
+
run_blocks controller, layout.after
|
47
|
+
controller.view.updateStyles
|
48
|
+
end
|
49
|
+
|
50
|
+
def apply_selector
|
51
|
+
if layout.selector
|
52
|
+
view.styleId = layout.selector.style_id
|
53
|
+
view.styleClass = layout.selector.style_classes.join(' ')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def run_blocks(context, blocks)
|
58
|
+
blocks.each { |block| context.instance_eval &block }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -3,7 +3,7 @@ class UIViewController
|
|
3
3
|
def pixate_layout(selector='', &block)
|
4
4
|
if block_given?
|
5
5
|
pixate_layout.selector = MotionPixateLayout::Selector.new(selector)
|
6
|
-
pixate_layout << block
|
6
|
+
pixate_layout.blocks << block
|
7
7
|
else
|
8
8
|
@_pixate_layout ||= MotionPixateLayout::Layout.new
|
9
9
|
end
|
@@ -23,33 +23,34 @@ class UIViewController
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def viewDidLoad
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
MotionPixateLayout::Proxy.new(self).run
|
27
|
+
end
|
28
|
+
|
29
|
+
def subviews
|
30
|
+
@subviews_hash ||= SubviewHash.new(view)
|
31
|
+
end
|
30
32
|
|
31
|
-
|
33
|
+
class SubviewHash
|
34
|
+
attr_reader :view
|
32
35
|
|
33
|
-
|
34
|
-
|
36
|
+
def initialize(view)
|
37
|
+
@view = view
|
35
38
|
end
|
36
39
|
|
37
|
-
|
38
|
-
|
40
|
+
def [](key)
|
41
|
+
hash[key] ||= current_hash[key]
|
39
42
|
end
|
40
43
|
|
41
|
-
|
44
|
+
private
|
42
45
|
|
43
|
-
|
44
|
-
|
46
|
+
def hash
|
47
|
+
@hash ||= current_hash
|
45
48
|
end
|
46
|
-
end
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
].freeze
|
50
|
+
def current_hash
|
51
|
+
Hash[
|
52
|
+
view.subviews.select(&:styleId).map { |view| [view.styleId, view] }
|
53
|
+
]
|
54
|
+
end
|
54
55
|
end
|
55
56
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: motion-pixate
|
@@ -67,6 +67,7 @@ extensions: []
|
|
67
67
|
extra_rdoc_files: []
|
68
68
|
files:
|
69
69
|
- .gitignore
|
70
|
+
- .travis.yml
|
70
71
|
- Gemfile
|
71
72
|
- Gemfile.lock
|
72
73
|
- LICENSE.md
|
@@ -74,7 +75,9 @@ files:
|
|
74
75
|
- Rakefile
|
75
76
|
- app/app_delegate.rb
|
76
77
|
- lib/motion-pixate-layout.rb
|
78
|
+
- lib/motion-pixate-layout/fake_pixate/ui_view.rb
|
77
79
|
- lib/motion-pixate-layout/layout.rb
|
80
|
+
- lib/motion-pixate-layout/proxy.rb
|
78
81
|
- lib/motion-pixate-layout/selector.rb
|
79
82
|
- lib/motion-pixate-layout/version.rb
|
80
83
|
- lib/motion-pixate-layout/z_core_extensions/ui_view_controller.rb
|