simple-view 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/.gitignore +5 -0
- data/.rvmrc +2 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +14 -0
- data/LICENSE +22 -0
- data/README.md +148 -0
- data/Rakefile +16 -0
- data/app/app_delegate.rb +9 -0
- data/app/simple_view_controller.rb +27 -0
- data/lib/simple-view.rb +16 -0
- data/lib/simple_view/builders/helpers/has_background_color.rb +10 -0
- data/lib/simple_view/builders/helpers/has_color.rb +9 -0
- data/lib/simple_view/builders/helpers/has_font.rb +9 -0
- data/lib/simple_view/builders/helpers/has_text_color.rb +11 -0
- data/lib/simple_view/builders/helpers/has_tint_color.rb +10 -0
- data/lib/simple_view/builders/ui_activity_indicator_view_builder.rb +12 -0
- data/lib/simple_view/builders/ui_button_builder.rb +32 -0
- data/lib/simple_view/builders/ui_control_builder.rb +9 -0
- data/lib/simple_view/builders/ui_image_view_builder.rb +38 -0
- data/lib/simple_view/builders/ui_label_builder.rb +18 -0
- data/lib/simple_view/builders/ui_progress_view_builder.rb +28 -0
- data/lib/simple_view/builders/ui_search_bar_builder.rb +31 -0
- data/lib/simple_view/builders/ui_segmented_control_builder.rb +28 -0
- data/lib/simple_view/builders/ui_slider_builder.rb +52 -0
- data/lib/simple_view/builders/ui_switch_builder.rb +10 -0
- data/lib/simple_view/builders/ui_tab_bar_builder.rb +20 -0
- data/lib/simple_view/builders/ui_table_view_builder.rb +15 -0
- data/lib/simple_view/builders/ui_table_view_cell_builder.rb +19 -0
- data/lib/simple_view/builders/ui_text_field_builder.rb +8 -0
- data/lib/simple_view/builders/ui_text_view_builder.rb +8 -0
- data/lib/simple_view/builders/ui_toolbar_builder.rb +11 -0
- data/lib/simple_view/builders/ui_view_builder.rb +58 -0
- data/lib/simple_view/extensions/string.rb +52 -0
- data/lib/simple_view/extensions/ui_color.rb +9 -0
- data/lib/simple_view/extensions/ui_font.rb +9 -0
- data/lib/simple_view/extensions/ui_image.rb +9 -0
- data/lib/simple_view/extensions/ui_view.rb +101 -0
- data/lib/simple_view/layout.rb +8 -0
- data/lib/simple_view/styles.rb +14 -0
- data/lib/simple_view/version.rb +3 -0
- data/lib/simple_view/view_proxy.rb +69 -0
- data/resources/test.jpg +0 -0
- data/simple_view.gemspec +16 -0
- data/spec/builders/ui_activity_indicator_view_builder_spec.rb +12 -0
- data/spec/builders/ui_button_builder_spec.rb +12 -0
- data/spec/builders/ui_control_builder_spec.rb +5 -0
- data/spec/builders/ui_image_view_builder_spec.rb +31 -0
- data/spec/builders/ui_progress_view_builder_spec.rb +12 -0
- data/spec/builders/ui_segmented_control_builder_spec.rb +13 -0
- data/spec/builders/ui_table_view_builder_spec.rb +12 -0
- data/spec/builders/ui_table_view_cell_builder_spec.rb +17 -0
- data/spec/builders/ui_view_builder_spec.rb +35 -0
- data/spec/extensions/string_spec.rb +38 -0
- data/spec/extensions/ui_color_spec.rb +8 -0
- data/spec/extensions/ui_font_spec.rb +8 -0
- data/spec/extensions/ui_image_spec.rb +8 -0
- data/spec/extensions/ui_view_spec.rb +111 -0
- data/spec/simple_view_spec.rb +193 -0
- metadata +118 -0
@@ -0,0 +1,111 @@
|
|
1
|
+
describe "SimpleView::UIView" do
|
2
|
+
describe "name accessor" do
|
3
|
+
it "should get and set view name" do
|
4
|
+
view = UIView.alloc.initWithFrame(CGRectZero)
|
5
|
+
view.name = "view_name"
|
6
|
+
view.name.should == "view_name"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "dimensions" do
|
11
|
+
it "should set left" do
|
12
|
+
view = UIView.alloc.initWithFrame(CGRectZero)
|
13
|
+
view.left = 10
|
14
|
+
view.left.should == 10
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should set right" do
|
18
|
+
superview = UIView.alloc.initWithFrame(CGRectMake(0, 0, 100, 100))
|
19
|
+
view = UIView.alloc.initWithFrame(CGRectZero)
|
20
|
+
superview.addSubview(view)
|
21
|
+
view.right = 10
|
22
|
+
view.right.should == 10
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should set top" do
|
26
|
+
view = UIView.alloc.initWithFrame(CGRectZero)
|
27
|
+
view.top = 11
|
28
|
+
view.top.should == 11
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should set bottom" do
|
32
|
+
superview = UIView.alloc.initWithFrame(CGRectMake(0, 0, 100, 100))
|
33
|
+
view = UIView.alloc.initWithFrame(CGRectZero)
|
34
|
+
superview.addSubview(view)
|
35
|
+
view.bottom = 10
|
36
|
+
view.bottom.should == 10
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should set width" do
|
40
|
+
view = UIView.alloc.initWithFrame(CGRectZero)
|
41
|
+
view.width = 12
|
42
|
+
view.width.should == 12
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should set height" do
|
46
|
+
view = UIView.alloc.initWithFrame(CGRectZero)
|
47
|
+
view.height = 13
|
48
|
+
view.height.should == 13
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#find" do
|
53
|
+
before do
|
54
|
+
@parent = UIView.alloc.initWithFrame(CGRectZero)
|
55
|
+
@child = UIView.alloc.initWithFrame(CGRectZero)
|
56
|
+
@child.name = "nemo"
|
57
|
+
@parent.addSubview(@child)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should find subview by name" do
|
61
|
+
@parent.find("nemo").should == @child
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should find subview by name using alias method" do
|
65
|
+
@parent.subview("nemo").should == @child
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should return nil if subview cannot be found" do
|
69
|
+
@parent.find("nemo").should == @child
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#sibling" do
|
74
|
+
before do
|
75
|
+
@parent = UIView.alloc.initWithFrame(CGRectZero)
|
76
|
+
@child = UIView.alloc.initWithFrame(CGRectZero)
|
77
|
+
@child.name = 'me'
|
78
|
+
@sibling = UIView.alloc.initWithFrame(CGRectZero)
|
79
|
+
@sibling.name = 'sib'
|
80
|
+
@parent.addSubview @child
|
81
|
+
@parent.addSubview @sibling
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should find sibling by name" do
|
85
|
+
@child.sibling('sib').should == @sibling
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "#closest" do
|
90
|
+
before do
|
91
|
+
@grand_parent = UIView.alloc.initWithFrame(CGRectZero)
|
92
|
+
@parent = UIView.alloc.initWithFrame(CGRectZero)
|
93
|
+
@child = UIView.alloc.initWithFrame(CGRectZero)
|
94
|
+
@child.name = 'me'
|
95
|
+
@closest = UIView.alloc.initWithFrame(CGRectZero)
|
96
|
+
@closest.name = 'mom'
|
97
|
+
@parent.addSubview @child
|
98
|
+
@grand_parent.addSubview @parent
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should find view by name which is 1 level up" do
|
102
|
+
@parent.addSubview @closest
|
103
|
+
@child.closest('mom').should == @closest
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should find view by name which is 2 levels up" do
|
107
|
+
@grand_parent.addSubview @closest
|
108
|
+
@child.closest('mom').should == @closest
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
describe "SimpleView" do
|
2
|
+
describe "Layout" do
|
3
|
+
describe "#setup" do
|
4
|
+
class DummyController
|
5
|
+
include SimpleView::Layout
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should execute the block within view object scope" do
|
9
|
+
view = UIView.alloc.initWithFrame(CGRectZero)
|
10
|
+
DummyController.new.setup view do
|
11
|
+
@view.frame = CGRectMake(0, 0, 10, 10)
|
12
|
+
end
|
13
|
+
view.frame.should == CGRectMake(0, 0, 10, 10)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "Styles" do
|
19
|
+
it "should define a style and retrieve it" do
|
20
|
+
style = {color: :red}
|
21
|
+
|
22
|
+
SimpleView::Styles.define :test, style
|
23
|
+
|
24
|
+
SimpleView::Styles.for(:test).should == style
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "ViewProxy" do
|
29
|
+
it "should convert locals to instance variables" do
|
30
|
+
view = UIView.alloc.init
|
31
|
+
local_a = Object.new
|
32
|
+
local_b = Object.new
|
33
|
+
|
34
|
+
proxy = SimpleView::ViewProxy.new(view, local_a: local_a, local_b: local_b)
|
35
|
+
|
36
|
+
proxy.view.should == view
|
37
|
+
proxy.local_a.should == local_a
|
38
|
+
proxy.local_b.should == local_b
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#add" do
|
42
|
+
it "should add view with options" do
|
43
|
+
frame = CGRectMake(0, 0, 10, 10)
|
44
|
+
alpha = 0.5
|
45
|
+
backgroundColor = UIColor.redColor
|
46
|
+
|
47
|
+
proxy = SimpleView::ViewProxy.new
|
48
|
+
view = proxy.add UIView, frame: frame, alpha: alpha, backgroundColor: backgroundColor
|
49
|
+
view.frame.should == frame
|
50
|
+
view.alpha.should == alpha
|
51
|
+
view.backgroundColor.should == backgroundColor
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#add with predefined styles" do
|
55
|
+
it "should add view with default style" do
|
56
|
+
SimpleView::Styles.define UIView, backgroundColor: UIColor.redColor
|
57
|
+
|
58
|
+
proxy = SimpleView::ViewProxy.new
|
59
|
+
view = proxy.add UIView
|
60
|
+
view.backgroundColor.should == UIColor.redColor
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should add view with custom style" do
|
64
|
+
SimpleView::Styles.define :blue, backgroundColor: UIColor.blueColor
|
65
|
+
|
66
|
+
proxy = SimpleView::ViewProxy.new
|
67
|
+
view = proxy.add UIView, styles: :blue
|
68
|
+
view.backgroundColor.should == UIColor.blueColor
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should add view with multiple custom styles" do
|
72
|
+
SimpleView::Styles.define :blue, backgroundColor: UIColor.blueColor
|
73
|
+
SimpleView::Styles.define :alpha, alpha: 0.5
|
74
|
+
|
75
|
+
proxy = SimpleView::ViewProxy.new
|
76
|
+
view = proxy.add UIView, styles: [:blue, :alpha]
|
77
|
+
view.backgroundColor.should == UIColor.blueColor
|
78
|
+
view.alpha.should == 0.5
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should add view with custom style overriding default style" do
|
82
|
+
SimpleView::Styles.define UIView, backgroundColor: UIColor.redColor
|
83
|
+
SimpleView::Styles.define :blue, backgroundColor: UIColor.blueColor
|
84
|
+
|
85
|
+
proxy = SimpleView::ViewProxy.new
|
86
|
+
view = proxy.add UIView, styles: :blue
|
87
|
+
view.backgroundColor.should == UIColor.blueColor
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should execute block" do
|
92
|
+
proxy = SimpleView::ViewProxy.new
|
93
|
+
view = proxy.add UIView do
|
94
|
+
label
|
95
|
+
end
|
96
|
+
view.subviews.first.class.should == UILabel
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should add view to superview" do
|
100
|
+
super_view = UIView.alloc.init
|
101
|
+
proxy = SimpleView::ViewProxy.new(super_view)
|
102
|
+
subview = proxy.add UIView
|
103
|
+
super_view.subviews.first.should == subview
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "shorthand methods" do
|
108
|
+
before do
|
109
|
+
@proxy = SimpleView::ViewProxy.new
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should create UIButton" do
|
113
|
+
@proxy.button.class.should == UIRoundedRectButton
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should create UIDatePicker" do
|
117
|
+
@proxy.date_picker.class.should == UIDatePicker
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should create UIImageView" do
|
121
|
+
@proxy.image_view.class.should == UIImageView
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should create UILabel" do
|
125
|
+
@proxy.label.class.should == UILabel
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should create UIPageControl" do
|
129
|
+
@proxy.page_control.class.should == UIPageControl
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should create UIPickerView" do
|
133
|
+
@proxy.picker_view.class.should == UIPickerView
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should create UIProgressView" do
|
137
|
+
@proxy.progress_view.class.should == UIProgressView
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should create UIScrollView" do
|
141
|
+
@proxy.scroll_view.class.should == UIScrollView
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should create UISearchBar" do
|
145
|
+
@proxy.search_bar.class.should == UISearchBar
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should create UISegmentedControl" do
|
149
|
+
@proxy.segmented_control.class.should == UISegmentedControl
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should create UISlider" do
|
153
|
+
@proxy.slider.class.should == UISlider
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should create UIStepper" do
|
157
|
+
@proxy.stepper.class.should == UIStepper
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should create UISwitch" do
|
161
|
+
@proxy.switch.class.should == UISwitch
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should create UITabBar" do
|
165
|
+
@proxy.tab_bar.class.should == UITabBar
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should create UITableView" do
|
169
|
+
@proxy.table_view.class.should == UITableView
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should create UITableViewCell" do
|
173
|
+
@proxy.table_view_cell.class.should == UITableViewCell
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should create UITextField" do
|
177
|
+
@proxy.text_field.class.should == UITextField
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should create UITextView" do
|
181
|
+
@proxy.text_view.class.should == UITextView
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should create UIToolbar" do
|
185
|
+
@proxy.toolbar.class.should == UIToolbar
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should create UIWebView" do
|
189
|
+
@proxy.web_view.class.should == UIWebView
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple-view
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sean Ho
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-29 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: DSL for UIKit for RubyMotion
|
15
|
+
email:
|
16
|
+
- sean.ho@conceptable.net
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- .rvmrc
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
25
|
+
- LICENSE
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- app/app_delegate.rb
|
29
|
+
- app/simple_view_controller.rb
|
30
|
+
- lib/simple-view.rb
|
31
|
+
- lib/simple_view/builders/helpers/has_background_color.rb
|
32
|
+
- lib/simple_view/builders/helpers/has_color.rb
|
33
|
+
- lib/simple_view/builders/helpers/has_font.rb
|
34
|
+
- lib/simple_view/builders/helpers/has_text_color.rb
|
35
|
+
- lib/simple_view/builders/helpers/has_tint_color.rb
|
36
|
+
- lib/simple_view/builders/ui_activity_indicator_view_builder.rb
|
37
|
+
- lib/simple_view/builders/ui_button_builder.rb
|
38
|
+
- lib/simple_view/builders/ui_control_builder.rb
|
39
|
+
- lib/simple_view/builders/ui_image_view_builder.rb
|
40
|
+
- lib/simple_view/builders/ui_label_builder.rb
|
41
|
+
- lib/simple_view/builders/ui_progress_view_builder.rb
|
42
|
+
- lib/simple_view/builders/ui_search_bar_builder.rb
|
43
|
+
- lib/simple_view/builders/ui_segmented_control_builder.rb
|
44
|
+
- lib/simple_view/builders/ui_slider_builder.rb
|
45
|
+
- lib/simple_view/builders/ui_switch_builder.rb
|
46
|
+
- lib/simple_view/builders/ui_tab_bar_builder.rb
|
47
|
+
- lib/simple_view/builders/ui_table_view_builder.rb
|
48
|
+
- lib/simple_view/builders/ui_table_view_cell_builder.rb
|
49
|
+
- lib/simple_view/builders/ui_text_field_builder.rb
|
50
|
+
- lib/simple_view/builders/ui_text_view_builder.rb
|
51
|
+
- lib/simple_view/builders/ui_toolbar_builder.rb
|
52
|
+
- lib/simple_view/builders/ui_view_builder.rb
|
53
|
+
- lib/simple_view/extensions/string.rb
|
54
|
+
- lib/simple_view/extensions/ui_color.rb
|
55
|
+
- lib/simple_view/extensions/ui_font.rb
|
56
|
+
- lib/simple_view/extensions/ui_image.rb
|
57
|
+
- lib/simple_view/extensions/ui_view.rb
|
58
|
+
- lib/simple_view/layout.rb
|
59
|
+
- lib/simple_view/styles.rb
|
60
|
+
- lib/simple_view/version.rb
|
61
|
+
- lib/simple_view/view_proxy.rb
|
62
|
+
- resources/test.jpg
|
63
|
+
- simple_view.gemspec
|
64
|
+
- spec/builders/ui_activity_indicator_view_builder_spec.rb
|
65
|
+
- spec/builders/ui_button_builder_spec.rb
|
66
|
+
- spec/builders/ui_control_builder_spec.rb
|
67
|
+
- spec/builders/ui_image_view_builder_spec.rb
|
68
|
+
- spec/builders/ui_progress_view_builder_spec.rb
|
69
|
+
- spec/builders/ui_segmented_control_builder_spec.rb
|
70
|
+
- spec/builders/ui_table_view_builder_spec.rb
|
71
|
+
- spec/builders/ui_table_view_cell_builder_spec.rb
|
72
|
+
- spec/builders/ui_view_builder_spec.rb
|
73
|
+
- spec/extensions/string_spec.rb
|
74
|
+
- spec/extensions/ui_color_spec.rb
|
75
|
+
- spec/extensions/ui_font_spec.rb
|
76
|
+
- spec/extensions/ui_image_spec.rb
|
77
|
+
- spec/extensions/ui_view_spec.rb
|
78
|
+
- spec/simple_view_spec.rb
|
79
|
+
homepage: https://github.com/seanho/SimpleView
|
80
|
+
licenses: []
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.8.24
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: DSL for UIKit for RubyMotion
|
103
|
+
test_files:
|
104
|
+
- spec/builders/ui_activity_indicator_view_builder_spec.rb
|
105
|
+
- spec/builders/ui_button_builder_spec.rb
|
106
|
+
- spec/builders/ui_control_builder_spec.rb
|
107
|
+
- spec/builders/ui_image_view_builder_spec.rb
|
108
|
+
- spec/builders/ui_progress_view_builder_spec.rb
|
109
|
+
- spec/builders/ui_segmented_control_builder_spec.rb
|
110
|
+
- spec/builders/ui_table_view_builder_spec.rb
|
111
|
+
- spec/builders/ui_table_view_cell_builder_spec.rb
|
112
|
+
- spec/builders/ui_view_builder_spec.rb
|
113
|
+
- spec/extensions/string_spec.rb
|
114
|
+
- spec/extensions/ui_color_spec.rb
|
115
|
+
- spec/extensions/ui_font_spec.rb
|
116
|
+
- spec/extensions/ui_image_spec.rb
|
117
|
+
- spec/extensions/ui_view_spec.rb
|
118
|
+
- spec/simple_view_spec.rb
|