simple-view 0.1.3 → 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.
Files changed (64) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile.lock +1 -1
  3. data/README.md +14 -7
  4. data/Rakefile +3 -7
  5. data/app/app_delegate.rb +2 -0
  6. data/app/simple_view_controller.rb +33 -15
  7. data/app/user_info_controller.rb +67 -0
  8. data/app/view_anchoring_controller.rb +27 -0
  9. data/lib/simple-view.rb +1 -7
  10. data/lib/simple_view/extensions/fixnum.rb +9 -0
  11. data/lib/simple_view/extensions/string.rb +16 -3
  12. data/lib/simple_view/extensions/ui_color.rb +2 -2
  13. data/lib/simple_view/extensions/ui_font.rb +2 -2
  14. data/lib/simple_view/extensions/ui_image.rb +2 -2
  15. data/lib/simple_view/extensions/ui_view.rb +48 -81
  16. data/lib/simple_view/layout.rb +1 -1
  17. data/lib/simple_view/styles.rb +4 -4
  18. data/lib/simple_view/version.rb +1 -1
  19. data/lib/simple_view/view_builder.rb +250 -0
  20. data/lib/simple_view/view_proxy.rb +22 -44
  21. data/spec/acceptance/view_anchoring_controller_spec.rb +82 -0
  22. data/spec/extensions/fixnum_spec.rb +15 -0
  23. data/spec/extensions/string_spec.rb +1 -1
  24. data/spec/extensions/ui_color_spec.rb +1 -1
  25. data/spec/extensions/ui_font_spec.rb +1 -1
  26. data/spec/extensions/ui_image_spec.rb +1 -1
  27. data/spec/extensions/ui_view_spec.rb +1 -17
  28. data/spec/layout_spec.rb +15 -0
  29. data/spec/styles_spec.rb +17 -0
  30. data/spec/view_builder_spec.rb +229 -0
  31. data/spec/view_proxy_spec.rb +172 -0
  32. metadata +18 -44
  33. data/lib/simple_view/builders/helpers/has_background_color.rb +0 -10
  34. data/lib/simple_view/builders/helpers/has_color.rb +0 -9
  35. data/lib/simple_view/builders/helpers/has_font.rb +0 -9
  36. data/lib/simple_view/builders/helpers/has_text_color.rb +0 -11
  37. data/lib/simple_view/builders/helpers/has_tint_color.rb +0 -10
  38. data/lib/simple_view/builders/ui_activity_indicator_view_builder.rb +0 -12
  39. data/lib/simple_view/builders/ui_button_builder.rb +0 -32
  40. data/lib/simple_view/builders/ui_control_builder.rb +0 -9
  41. data/lib/simple_view/builders/ui_image_view_builder.rb +0 -38
  42. data/lib/simple_view/builders/ui_label_builder.rb +0 -18
  43. data/lib/simple_view/builders/ui_progress_view_builder.rb +0 -28
  44. data/lib/simple_view/builders/ui_search_bar_builder.rb +0 -31
  45. data/lib/simple_view/builders/ui_segmented_control_builder.rb +0 -28
  46. data/lib/simple_view/builders/ui_slider_builder.rb +0 -52
  47. data/lib/simple_view/builders/ui_switch_builder.rb +0 -10
  48. data/lib/simple_view/builders/ui_tab_bar_builder.rb +0 -20
  49. data/lib/simple_view/builders/ui_table_view_builder.rb +0 -15
  50. data/lib/simple_view/builders/ui_table_view_cell_builder.rb +0 -19
  51. data/lib/simple_view/builders/ui_text_field_builder.rb +0 -8
  52. data/lib/simple_view/builders/ui_text_view_builder.rb +0 -8
  53. data/lib/simple_view/builders/ui_toolbar_builder.rb +0 -11
  54. data/lib/simple_view/builders/ui_view_builder.rb +0 -58
  55. data/spec/builders/ui_activity_indicator_view_builder_spec.rb +0 -12
  56. data/spec/builders/ui_button_builder_spec.rb +0 -12
  57. data/spec/builders/ui_control_builder_spec.rb +0 -5
  58. data/spec/builders/ui_image_view_builder_spec.rb +0 -31
  59. data/spec/builders/ui_progress_view_builder_spec.rb +0 -12
  60. data/spec/builders/ui_segmented_control_builder_spec.rb +0 -13
  61. data/spec/builders/ui_table_view_builder_spec.rb +0 -12
  62. data/spec/builders/ui_table_view_cell_builder_spec.rb +0 -17
  63. data/spec/builders/ui_view_builder_spec.rb +0 -35
  64. data/spec/simple_view_spec.rb +0 -193
@@ -1,15 +0,0 @@
1
- module SimpleView
2
- module Builders
3
- class UITableViewBuilder < UIViewBuilder
4
- def view_for_class(klass, options = {})
5
- style = options.delete(:style) || UITableViewStylePlain
6
- klass.alloc.initWithFrame(CGRectZero, style: style)
7
- end
8
-
9
- def setSeparatorColor color
10
- @view.separatorColor = color.to_color
11
- end
12
- alias_method :setSeparator_color, :setSeparatorColor
13
- end
14
- end
15
- end
@@ -1,19 +0,0 @@
1
- module SimpleView
2
- module Builders
3
- class UITableViewCellBuilder < UIViewBuilder
4
- def view_for_class(klass, options = {})
5
- style = options.delete(:style) || UITableViewCellStyleDefault
6
- identifier = options.delete(:reuseIdentifier) || options.delete(:reuse_identifier)
7
- klass.alloc.initWithStyle(style, reuseIdentifier: identifier)
8
- end
9
-
10
- def setImage image
11
- @view.image = image.to_image
12
- end
13
-
14
- def setSelectedImage image
15
- @view.selectedImage = image.to_image
16
- end
17
- end
18
- end
19
- end
@@ -1,8 +0,0 @@
1
- module SimpleView
2
- module Builders
3
- class UITextFieldBuilder < UIViewBuilder
4
- include SimpleView::Builders::HasFont
5
- include SimpleView::Builders::HasTextColor
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module SimpleView
2
- module Builders
3
- class UITextViewBuilder < UIViewBuilder
4
- include SimpleView::Builders::HasFont
5
- include SimpleView::Builders::HasTextColor
6
- end
7
- end
8
- end
@@ -1,11 +0,0 @@
1
- module SimpleView
2
- module Builders
3
- class UIToolbarBuilder < UIViewBuilder
4
- include SimpleView::Builders::HasTintColor
5
-
6
- def setBackgroundImage image, forToolbarPosition: position, barMetrics: metrics
7
- @view.setBackgroundImage image.to_image, forToolbarPosition: position, barMetrics: metrics
8
- end
9
- end
10
- end
11
- end
@@ -1,58 +0,0 @@
1
- module SimpleView
2
- module Builders
3
- class UIViewBuilder
4
- include SimpleView::Builders::HasBackgroundColor
5
-
6
- STRUCTS_MAP = {
7
- CGAffineTransform => Proc.new {|v| NSValue.valueWithCGAffineTransform(v) },
8
- CGPoint => Proc.new {|v| NSValue.valueWithCGPoint(v) },
9
- CGRect => Proc.new {|v| NSValue.valueWithCGRect(v) },
10
- CGSize => Proc.new {|v| NSValue.valueWithCGSize(v) },
11
- UIEdgeInsets => Proc.new {|v| NSValue.valueWithUIEdgeInsets(v) },
12
- UIOffset => Proc.new {|v| NSValue.valueWithUIOffset(v) }
13
- }
14
-
15
- attr_reader :view
16
-
17
- def build klass, options = {}
18
- options = options_for_class klass, options
19
- @view = view_for_class klass, options
20
-
21
- if options
22
- options.each do |k,v|
23
- options[k] = STRUCTS_MAP[v.class].call(v) if STRUCTS_MAP.has_key?(v.class)
24
- end
25
- setValuesForKeysWithDictionary options
26
- end
27
-
28
- @view
29
- end
30
-
31
- def view_for_class klass, options = {}
32
- klass.alloc.initWithFrame(CGRectZero)
33
- end
34
-
35
- def options_for_class klass, options = {}
36
- class_style = SimpleView::Styles.for(klass) || {}
37
- custom_styles = options.delete(:styles)
38
-
39
- if custom_styles.is_a?(Symbol)
40
- style = SimpleView::Styles.for(custom_styles)
41
- class_style.update(style) if style
42
-
43
- elsif custom_styles.is_a?(Array)
44
- custom_styles.each do |custom_style|
45
- style = SimpleView::Styles.for(custom_style)
46
- class_style.update(style) if style
47
- end
48
- end
49
-
50
- class_style.update(options)
51
- end
52
-
53
- def setValue value, forUndefinedKey: key
54
- @view.setValue value, forKey: key
55
- end
56
- end
57
- end
58
- end
@@ -1,12 +0,0 @@
1
- describe "UIActivityIndicatorViewBuilder" do
2
- it "should build UIActivityIndicatorView" do
3
- view = SimpleView::Builders::UIActivityIndicatorViewBuilder.new.build(UIActivityIndicatorView)
4
- view.class.should == UIActivityIndicatorView
5
- view.activityIndicatorViewStyle.should == UIActivityIndicatorViewStyleWhite
6
- end
7
-
8
- it "should build UIActivityIndicatorView with style" do
9
- view = SimpleView::Builders::UIActivityIndicatorViewBuilder.new.build(UIActivityIndicatorView, style: UIActivityIndicatorViewStyleGray)
10
- view.activityIndicatorViewStyle.should == UIActivityIndicatorViewStyleGray
11
- end
12
- end
@@ -1,12 +0,0 @@
1
- describe "UIButtonBuilder" do
2
- it "should build UIButton" do
3
- button = SimpleView::Builders::UIButtonBuilder.new.build(UIButton)
4
- button.class.should == UIRoundedRectButton
5
- button.buttonType.should == UIButtonTypeRoundedRect
6
- end
7
-
8
- it "should build UIButton with buttonType" do
9
- button = SimpleView::Builders::UIButtonBuilder.new.build(UIButton, buttonType: UIButtonTypeDetailDisclosure)
10
- button.buttonType.should == UIButtonTypeDetailDisclosure
11
- end
12
- end
@@ -1,5 +0,0 @@
1
- describe "UIControlBuilder" do
2
- it "should build UIControl" do
3
- SimpleView::Builders::UIControlBuilder.new.build(UIControl).class.should == UIControl
4
- end
5
- end
@@ -1,31 +0,0 @@
1
- describe "UIImageViewBuilder" do
2
- it "should build UIImageView" do
3
- image_view = SimpleView::Builders::UIImageViewBuilder.new.build(UIImageView)
4
- image_view.class.should == UIImageView
5
- end
6
-
7
- it "should build UIImageView with image" do
8
- image = UIImage.imageNamed "test.jpg"
9
- image_view = SimpleView::Builders::UIImageViewBuilder.new.build(UIImageView, image: image)
10
- image_view.image.should == image
11
- end
12
-
13
- it "should build UIImageView with image string" do
14
- image_view = SimpleView::Builders::UIImageViewBuilder.new.build(UIImageView, image: "test.jpg")
15
- image_view.image.class.should == UIImage
16
- end
17
-
18
- it "should build UIImageView with image and highlightedImage" do
19
- image = UIImage.imageNamed "test.jpg"
20
- highlighted = UIImage.imageNamed "test.jpg"
21
- image_view = SimpleView::Builders::UIImageViewBuilder.new.build(UIImageView, image: image, highlightedImage: highlighted)
22
- image_view.image.should == image
23
- image_view.highlightedImage.should == highlighted
24
- end
25
-
26
- it "should build UIImageView with image string and highlightedImage string" do
27
- image_view = SimpleView::Builders::UIImageViewBuilder.new.build(UIImageView, image: "test.jpg", highlightedImage: "test.jpg")
28
- image_view.image.class.should == UIImage
29
- image_view.highlightedImage.class.should == UIImage
30
- end
31
- end
@@ -1,12 +0,0 @@
1
- describe "UIProgressViewBuilder" do
2
- it "should build UIProgressView" do
3
- view = SimpleView::Builders::UIProgressViewBuilder.new.build(UIProgressView)
4
- view.class.should == UIProgressView
5
- view.progressViewStyle.should == UIProgressViewStyleDefault
6
- end
7
-
8
- it "should build UIProgressView with style" do
9
- view = SimpleView::Builders::UIProgressViewBuilder.new.build(UIProgressView, style: UIProgressViewStyleBar)
10
- view.progressViewStyle.should == UIProgressViewStyleBar
11
- end
12
- end
@@ -1,13 +0,0 @@
1
- describe "UISegmentedControlBuilder" do
2
- it "should build UISegmentedControl" do
3
- view = SimpleView::Builders::UISegmentedControlBuilder.new.build(UISegmentedControl)
4
- view.class.should == UISegmentedControl
5
- view.numberOfSegments.should == 0
6
- end
7
-
8
- it "should build UISegmentedControl with items" do
9
- items = ["ABC"]
10
- view = SimpleView::Builders::UISegmentedControlBuilder.new.build(UISegmentedControl, items: items)
11
- view.numberOfSegments.should == 1
12
- end
13
- end
@@ -1,12 +0,0 @@
1
- describe "UITableViewBuilder" do
2
- it "should build UITableView" do
3
- view = SimpleView::Builders::UITableViewBuilder.new.build(UITableView)
4
- view.class.should == UITableView
5
- view.style.should == UITableViewStylePlain
6
- end
7
-
8
- it "should build UITableView with style" do
9
- view = SimpleView::Builders::UITableViewBuilder.new.build(UITableView, style: UITableViewStyleGrouped)
10
- view.style.should == UITableViewStyleGrouped
11
- end
12
- end
@@ -1,17 +0,0 @@
1
- describe "UITableViewCellBuilder" do
2
- it "should build UITableViewCell" do
3
- view = SimpleView::Builders::UITableViewCellBuilder.new.build(UITableViewCell)
4
- view.class.should == UITableViewCell
5
- view.style.should == UITableViewCellStyleDefault
6
- end
7
-
8
- it "should build UITableViewCell with style" do
9
- view = SimpleView::Builders::UITableViewCellBuilder.new.build(UITableViewCell, style: UITableViewCellStyleSubtitle)
10
- view.style.should == UITableViewCellStyleSubtitle
11
- end
12
-
13
- it "should build UITableViewCell with style and reuseIdentifier" do
14
- view = SimpleView::Builders::UITableViewCellBuilder.new.build(UITableViewCell, reuseIdentifier: "CellIdentifier")
15
- view.reuseIdentifier.should == "CellIdentifier"
16
- end
17
- end
@@ -1,35 +0,0 @@
1
- describe "UIViewBuilder" do
2
- it "should build UIView" do
3
- SimpleView::Builders::UIViewBuilder.new.build(UIView).class.should == UIView
4
- end
5
-
6
- describe "#backgroundColor" do
7
- it "should set backgroundColor by HTML code" do
8
- view = SimpleView::Builders::UIViewBuilder.new.build(UIView, backgroundColor: "#f00")
9
-
10
- r = Pointer.new(:float)
11
- g = Pointer.new(:float)
12
- b = Pointer.new(:float)
13
- a = Pointer.new(:float)
14
- view.backgroundColor.getRed(r, green: g, blue: b, alpha: a)
15
- r[0].should == 1
16
- g[0].should == 0
17
- b[0].should == 0
18
- a[0].should == 1
19
- end
20
-
21
- it "should set background_color by HTML code" do
22
- view = SimpleView::Builders::UIViewBuilder.new.build(UIView, background_color: "#f00")
23
-
24
- r = Pointer.new(:float)
25
- g = Pointer.new(:float)
26
- b = Pointer.new(:float)
27
- a = Pointer.new(:float)
28
- view.backgroundColor.getRed(r, green: g, blue: b, alpha: a)
29
- r[0].should == 1
30
- g[0].should == 0
31
- b[0].should == 0
32
- a[0].should == 1
33
- end
34
- end
35
- end
@@ -1,193 +0,0 @@
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