teacup 1.3.2 → 1.3.3
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 +5 -1
- data/lib/teacup/version.rb +1 -1
- data/lib/teacup/z_core_extensions/ui_view_getters.rb +17 -8
- data/lib/teacup/z_core_extensions/z_handlers.rb +17 -1
- data/samples/AutoLayout/Rakefile +1 -1
- data/samples/AutoLayout/{styles → app/styles}/root.rb +0 -0
- data/samples/AutoLayout/{styles → lib}/dummy.rb +0 -0
- data/samples/AutoLayout/{styles → lib}/handlers.rb +0 -0
- data/samples/AutoLayout/{styles → lib/styles}/base.rb +0 -0
- data/samples/Hai/Gemfile.lock +1 -3
- data/samples/Hai/Rakefile +0 -1
- data/samples/Hai/{styles → app/styles}/iphone.rb +0 -0
- data/spec/ui_view_getters_spec.rb +68 -0
- metadata +9 -8
- data/samples/AutoLayout/styles/settings.rb +0 -13
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -20,6 +20,10 @@ to create interfaces programmatically.
|
|
20
20
|
```bash
|
21
21
|
> gem install teacup
|
22
22
|
```
|
23
|
+
and in your Rakefile
|
24
|
+
```ruby
|
25
|
+
require 'teacup'
|
26
|
+
```
|
23
27
|
|
24
28
|
**Better Install**
|
25
29
|
|
@@ -55,7 +59,7 @@ gems on a per-project basis, using a gemset. See the
|
|
55
59
|
end
|
56
60
|
end
|
57
61
|
```
|
58
|
-
4. Create the stylesheet
|
62
|
+
4. Create the stylesheet (Usually in app/styles/)
|
59
63
|
|
60
64
|
```ruby
|
61
65
|
Teacup::Stylesheet.new :main_screen do
|
data/lib/teacup/version.rb
CHANGED
@@ -18,21 +18,30 @@ class UIView
|
|
18
18
|
view = subviews.find { |subview| found_subview = subview.viewWithStylename(name_or_class) }
|
19
19
|
return found_subview if view
|
20
20
|
|
21
|
-
nil # couldn't find it
|
21
|
+
return nil # couldn't find it
|
22
22
|
end
|
23
23
|
|
24
24
|
# get all subviews by stylename or class
|
25
25
|
# my_view.viewsWithStylename :button => [#<UIButton..>, #<UIButton...>]
|
26
26
|
# my_view.viewsWithStylename UIButton => [#<UIButton..>, #<UIButton...>]
|
27
27
|
def viewsWithStylename name_or_class
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
retval = []
|
29
|
+
retval << self if self._teacup_check_stylename(name_or_class)
|
30
|
+
|
31
|
+
search_views = [].concat(self.subviews)
|
32
|
+
# ewww, a traditional for loop! the search_views array is modified in place,
|
33
|
+
# and `each` and other methods don't like that.
|
34
|
+
index = 0
|
35
|
+
while index < search_views.length
|
36
|
+
view = search_views[index]
|
37
|
+
if view._teacup_check_stylename(name_or_class)
|
38
|
+
retval << view
|
39
|
+
end
|
40
|
+
search_views.concat(view.subviews)
|
41
|
+
index += 1
|
34
42
|
end
|
35
|
-
|
43
|
+
|
44
|
+
return retval
|
36
45
|
end
|
37
46
|
|
38
47
|
def _teacup_check_stylename(name_or_class)
|
@@ -49,12 +49,28 @@ Teacup.handler UIView, :height { |target, h|
|
|
49
49
|
target.frame = f
|
50
50
|
}
|
51
51
|
|
52
|
+
Teacup.handler UIView, :size { |target, size|
|
53
|
+
f = target.frame
|
54
|
+
size_x = Teacup::calculate(target, :width, size[0])
|
55
|
+
size_y = Teacup::calculate(target, :height, size[1])
|
56
|
+
f.size = [size_x, size_y]
|
57
|
+
target.frame = f
|
58
|
+
}
|
59
|
+
|
52
60
|
Teacup.handler UIView, :origin { |target, origin|
|
53
61
|
f = target.frame
|
54
|
-
|
62
|
+
origin_x = Teacup::calculate(target, :width, origin[0])
|
63
|
+
origin_y = Teacup::calculate(target, :height, origin[1])
|
64
|
+
f.origin = [origin_x, origin_y]
|
55
65
|
target.frame = f
|
56
66
|
}
|
57
67
|
|
68
|
+
Teacup.handler UIView, :center { |target, center|
|
69
|
+
center_x = Teacup::calculate(target, :width, center[0])
|
70
|
+
center_y = Teacup::calculate(target, :height, center[1])
|
71
|
+
target.center = [center_x, center_y]
|
72
|
+
}
|
73
|
+
|
58
74
|
Teacup.handler UIView, :size { |target, size|
|
59
75
|
# odd... if I changed these to .is_a?, weird errors happen. Use ===
|
60
76
|
if Symbol === size && size == :full
|
data/samples/AutoLayout/Rakefile
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/samples/Hai/Gemfile.lock
CHANGED
data/samples/Hai/Rakefile
CHANGED
File without changes
|
@@ -0,0 +1,68 @@
|
|
1
|
+
describe "UIView getters" do
|
2
|
+
|
3
|
+
before do
|
4
|
+
stylesheet1 = Teacup::Stylesheet.new do
|
5
|
+
style :parent_style
|
6
|
+
end
|
7
|
+
stylesheet2 = Teacup::Stylesheet.new do
|
8
|
+
import stylesheet1
|
9
|
+
style :extended_style, extends: :parent_style
|
10
|
+
end
|
11
|
+
|
12
|
+
@view = UIView.new.tap do |view|
|
13
|
+
@some_view = view.subview(UIView, :some_view)
|
14
|
+
@extended_style = view.subview(UIView, :extended_style)
|
15
|
+
container = view.subview(UIView)
|
16
|
+
@label1 = container.subview(UILabel)
|
17
|
+
@label2 = container.subview(UILabel)
|
18
|
+
@label3 = container.subview(UILabel)
|
19
|
+
@stylename1 = view.subview(UIView, :stylename)
|
20
|
+
@stylename2 = view.subview(UIView, :stylename)
|
21
|
+
@stylename3 = view.subview(UIView, :stylename)
|
22
|
+
container = view.subview(UIView)
|
23
|
+
@button = container.subview(UIButton)
|
24
|
+
end
|
25
|
+
@view.stylesheet = stylesheet2
|
26
|
+
@view.stylename = :self_style
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "viewWithStylename" do
|
30
|
+
it "should return based on stylename" do
|
31
|
+
@view.viewWithStylename(:some_view).should == @some_view
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return self based on stylename" do
|
35
|
+
@view.viewWithStylename(:self_style).should == @view
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return based on class" do
|
39
|
+
@view.viewWithStylename(UIButton).should == @button
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should return based on extended stylename" do
|
43
|
+
@view.viewWithStylename(:extended_style).should == @extended_style
|
44
|
+
@view.viewWithStylename(:parent_style).should == @extended_style
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should nil when there is no match" do
|
48
|
+
@view.viewWithStylename(:this_is_not_a_stylename).should == nil
|
49
|
+
@view.viewWithStylename(UITableView).should == nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "viewsWithStylename" do
|
54
|
+
it "should return based on stylename" do
|
55
|
+
@view.viewsWithStylename(:stylename).should == [@stylename1, @stylename2, @stylename3]
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should return based on class" do
|
59
|
+
@view.viewsWithStylename(UILabel).should == [@label1, @label2, @label3]
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should [] when there is no match" do
|
63
|
+
@view.viewsWithStylename(:this_is_not_a_stylename).should == []
|
64
|
+
@view.viewsWithStylename(UITableView).should == []
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: teacup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.3
|
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-04-
|
12
|
+
date: 2013-04-15 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! 'Teacup is a community-driven DSL for making CSS-like styling, and
|
15
15
|
layouts for
|
@@ -72,19 +72,18 @@ files:
|
|
72
72
|
- samples/AutoLayout/Rakefile
|
73
73
|
- samples/AutoLayout/app/app_delegate.rb
|
74
74
|
- samples/AutoLayout/app/root_controller.rb
|
75
|
-
- samples/AutoLayout/styles/
|
76
|
-
- samples/AutoLayout/
|
77
|
-
- samples/AutoLayout/
|
78
|
-
- samples/AutoLayout/styles/
|
79
|
-
- samples/AutoLayout/styles/settings.rb
|
75
|
+
- samples/AutoLayout/app/styles/root.rb
|
76
|
+
- samples/AutoLayout/lib/dummy.rb
|
77
|
+
- samples/AutoLayout/lib/handlers.rb
|
78
|
+
- samples/AutoLayout/lib/styles/base.rb
|
80
79
|
- samples/Hai/.gitignore
|
81
80
|
- samples/Hai/Gemfile
|
82
81
|
- samples/Hai/Gemfile.lock
|
83
82
|
- samples/Hai/Rakefile
|
84
83
|
- samples/Hai/app/app_delegate.rb
|
85
84
|
- samples/Hai/app/hai_controller.rb
|
85
|
+
- samples/Hai/app/styles/iphone.rb
|
86
86
|
- samples/Hai/spec/main_spec.rb
|
87
|
-
- samples/Hai/styles/iphone.rb
|
88
87
|
- samples/OnePage/Gemfile
|
89
88
|
- samples/OnePage/Rakefile
|
90
89
|
- samples/OnePage/app/app_delegate.rb
|
@@ -99,6 +98,7 @@ files:
|
|
99
98
|
- spec/present_modal_spec.rb
|
100
99
|
- spec/style_spec.rb
|
101
100
|
- spec/stylesheet_spec.rb
|
101
|
+
- spec/ui_view_getters_spec.rb
|
102
102
|
- spec/uiswitch_spec.rb
|
103
103
|
- spec/view_spec.rb
|
104
104
|
- teacup.gemspec
|
@@ -135,5 +135,6 @@ test_files:
|
|
135
135
|
- spec/present_modal_spec.rb
|
136
136
|
- spec/style_spec.rb
|
137
137
|
- spec/stylesheet_spec.rb
|
138
|
+
- spec/ui_view_getters_spec.rb
|
138
139
|
- spec/uiswitch_spec.rb
|
139
140
|
- spec/view_spec.rb
|