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,11 @@
|
|
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
|
@@ -0,0 +1,58 @@
|
|
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
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module SimpleView
|
2
|
+
module String
|
3
|
+
def to_color
|
4
|
+
html_colour = self.gsub(%r{[#;]}, '')
|
5
|
+
case html_colour.size
|
6
|
+
when 3
|
7
|
+
colours = html_colour.scan(%r{[0-9A-Fa-f]}).map { |el| (el * 2).to_i(16) }
|
8
|
+
when 6
|
9
|
+
colours = html_colour.scan(%r<[0-9A-Fa-f]{2}>).map { |el| el.to_i(16) }
|
10
|
+
else
|
11
|
+
raise ArgumentError
|
12
|
+
end
|
13
|
+
|
14
|
+
::UIColor.colorWithRed(colours[0]/255.0, green: colours[1]/255.0, blue: colours[2]/255.0, alpha: 1)
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_font
|
18
|
+
bold = false
|
19
|
+
italic = false
|
20
|
+
size = ::UIFont.systemFontSize
|
21
|
+
font_name = nil
|
22
|
+
|
23
|
+
self.split(' ').each do |comp|
|
24
|
+
if comp == "bold"
|
25
|
+
bold = true
|
26
|
+
elsif comp == "italic"
|
27
|
+
italic = true
|
28
|
+
elsif comp.to_f > 0
|
29
|
+
size = comp.to_f
|
30
|
+
elsif comp.length > 4
|
31
|
+
font_name = comp
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
if font_name
|
36
|
+
::UIFont.fontWithName(font_name, size: size)
|
37
|
+
elsif bold
|
38
|
+
::UIFont.boldSystemFontOfSize(size)
|
39
|
+
elsif italic
|
40
|
+
::UIFont.italicSystemFontOfSize(size)
|
41
|
+
else
|
42
|
+
::UIFont.systemFontOfSize(size)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_image
|
47
|
+
::UIImage.imageNamed self
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
String.send(:include, SimpleView::String)
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module SimpleView
|
2
|
+
module UIView
|
3
|
+
attr_accessor :name, :bottom, :right, :anchors
|
4
|
+
|
5
|
+
def find name
|
6
|
+
subviews.each do |subview|
|
7
|
+
return subview if subview.name == name
|
8
|
+
end
|
9
|
+
nil
|
10
|
+
end
|
11
|
+
alias_method :subview, :find
|
12
|
+
|
13
|
+
def sibling name
|
14
|
+
if superview
|
15
|
+
superview.find name
|
16
|
+
else
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def closest name
|
22
|
+
view = sibling name
|
23
|
+
if view.nil? && superview
|
24
|
+
view = superview.closest name
|
25
|
+
end
|
26
|
+
view
|
27
|
+
end
|
28
|
+
|
29
|
+
def invalidate_size
|
30
|
+
f = self.frame
|
31
|
+
max_width = superview ? superview.bounds.size.width : 0
|
32
|
+
max_height = superview ? superview.bounds.size.height : 0
|
33
|
+
|
34
|
+
@anchors ||= [:top, :left]
|
35
|
+
anchor_top = @anchors.include?(:top)
|
36
|
+
anchor_left = @anchors.include?(:left)
|
37
|
+
anchor_bottom = @anchors.include?(:bottom)
|
38
|
+
anchor_right = @anchors.include?(:right)
|
39
|
+
|
40
|
+
self.autoresizingMask = UIViewAutoresizingNone
|
41
|
+
self.autoresizingMask |= UIViewAutoresizingFlexibleTopMargin unless anchor_top
|
42
|
+
self.autoresizingMask |= UIViewAutoresizingFlexibleLeftMargin unless anchor_left
|
43
|
+
self.autoresizingMask |= UIViewAutoresizingFlexibleBottomMargin unless anchor_bottom
|
44
|
+
self.autoresizingMask |= UIViewAutoresizingFlexibleRightMargin unless anchor_right
|
45
|
+
self.autoresizingMask |= UIViewAutoresizingFlexibleWidth if anchor_left && anchor_right
|
46
|
+
self.autoresizingMask |= UIViewAutoresizingFlexibleHeight if anchor_top && anchor_bottom
|
47
|
+
|
48
|
+
if (anchor_left && anchor_right) || (anchor_left && !@right.nil?)
|
49
|
+
f.size.width = max_width - self.left - @right.to_i
|
50
|
+
elsif anchor_right
|
51
|
+
f.origin.x = max_width - self.width - @right.to_i
|
52
|
+
elsif !anchor_left && !anchor_right
|
53
|
+
f.origin.x = max_width / 2 - f.size.width / 2
|
54
|
+
end
|
55
|
+
|
56
|
+
if (anchor_top && anchor_bottom) || (anchor_top && !@bottom.nil?)
|
57
|
+
f.size.height = max_height - self.top - @bottom.to_i
|
58
|
+
elsif anchor_bottom
|
59
|
+
f.origin.y = max_height - self.height - @bottom.to_i
|
60
|
+
elsif !anchor_top && !anchor_bottom
|
61
|
+
f.origin.y = max_height / 2 - f.size.height / 2
|
62
|
+
end
|
63
|
+
|
64
|
+
self.frame = f
|
65
|
+
end
|
66
|
+
|
67
|
+
def top
|
68
|
+
self.frame.origin.y
|
69
|
+
end
|
70
|
+
|
71
|
+
def setTop value
|
72
|
+
self.frame = [[self.frame.origin.x, value], [self.frame.size.width, self.frame.size.height]]
|
73
|
+
end
|
74
|
+
|
75
|
+
def left
|
76
|
+
self.frame.origin.x
|
77
|
+
end
|
78
|
+
|
79
|
+
def setLeft value
|
80
|
+
self.frame = [[value, self.frame.origin.y], [self.frame.size.width, self.frame.size.height]]
|
81
|
+
end
|
82
|
+
|
83
|
+
def width
|
84
|
+
self.frame.size.width
|
85
|
+
end
|
86
|
+
|
87
|
+
def setWidth value
|
88
|
+
self.frame = [[self.frame.origin.x, self.frame.origin.y], [value, self.frame.size.height]]
|
89
|
+
end
|
90
|
+
|
91
|
+
def height
|
92
|
+
self.frame.size.height
|
93
|
+
end
|
94
|
+
|
95
|
+
def setHeight value
|
96
|
+
self.frame = [[self.frame.origin.x, self.frame.origin.y], [self.frame.size.width, value]]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
UIView.send(:include, SimpleView::UIView)
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module SimpleView
|
2
|
+
class ViewProxy
|
3
|
+
attr_reader :view
|
4
|
+
|
5
|
+
def initialize view = nil, locals = {}
|
6
|
+
@view = view
|
7
|
+
@locals = locals
|
8
|
+
|
9
|
+
if @locals
|
10
|
+
@locals.each do |k, v|
|
11
|
+
self.class.send :attr_accessor, k
|
12
|
+
self.instance_variable_set "@#{k}", v
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def build_view klass, options = {}
|
18
|
+
builder_class = "#{klass}Builder"
|
19
|
+
|
20
|
+
if SimpleView::Builders.const_defined? builder_class
|
21
|
+
SimpleView::Builders.const_get(builder_class).new.build klass, options
|
22
|
+
else
|
23
|
+
if klass < UIControl
|
24
|
+
SimpleView::Builders::UIControlBuilder.new.build klass, options
|
25
|
+
else
|
26
|
+
SimpleView::Builders::UIViewBuilder.new.build klass, options
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def add klass, options = {}, &block
|
32
|
+
subview = build_view klass, options
|
33
|
+
|
34
|
+
@view.addSubview(subview) unless @view.nil?
|
35
|
+
|
36
|
+
if block_given?
|
37
|
+
child_layout = ViewProxy.new(subview, @locals)
|
38
|
+
child_layout.instance_eval &block
|
39
|
+
end
|
40
|
+
|
41
|
+
subview.sizeToFit if options[:width].nil? && options[:height].nil? && options[:right].nil? && options[:bottom].nil?
|
42
|
+
subview.invalidate_size
|
43
|
+
subview
|
44
|
+
end
|
45
|
+
|
46
|
+
def activity_indicator(options = {}, &block) add(::UIActivityIndicatorView, options, &block); end
|
47
|
+
def button(options = {}, &block) add(::UIButton, options, &block); end
|
48
|
+
def date_picker(options = {}, &block) add(::UIDatePicker, options, &block); end
|
49
|
+
def image_view(options = {}, &block) add(::UIImageView, options, &block); end
|
50
|
+
def label(options = {}, &block) add(::UILabel, options, &block); end
|
51
|
+
def page_control(options = {}, &block) add(::UIPageControl, options, &block); end
|
52
|
+
def picker_view(options = {}, &block) add(::UIPickerView, options, &block); end
|
53
|
+
def progress_view(options = {}, &block) add(::UIProgressView, options, &block); end
|
54
|
+
def rect(options = {}, &block) add(::UIView, options, &block); end
|
55
|
+
def scroll_view(options = {}, &block) add(::UIScrollView, options, &block); end
|
56
|
+
def search_bar(options = {}, &block) add(::UISearchBar, options, &block); end
|
57
|
+
def segmented_control(options = {}, &block) add(::UISegmentedControl, options, &block); end
|
58
|
+
def slider(options = {}, &block) add(::UISlider, options, &block); end
|
59
|
+
def stepper(options = {}, &block) add(::UIStepper, options, &block); end
|
60
|
+
def switch(options = {}, &block) add(::UISwitch, options, &block); end
|
61
|
+
def tab_bar(options = {}, &block) add(::UITabBar, options, &block); end
|
62
|
+
def table_view(options = {}, &block) add(::UITableView, options, &block); end
|
63
|
+
def table_view_cell(options = {}, &block) add(::UITableViewCell, options, &block); end
|
64
|
+
def text_field(options = {}, &block) add(::UITextField, options, &block); end
|
65
|
+
def text_view(options = {}, &block) add(::UITextView, options, &block); end
|
66
|
+
def toolbar(options = {}, &block) add(::UIToolbar, options, &block); end
|
67
|
+
def web_view(options = {}, &block) add(::UIWebView, options, &block); end
|
68
|
+
end
|
69
|
+
end
|
data/resources/test.jpg
ADDED
Binary file
|
data/simple_view.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/simple_view/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Sean Ho"]
|
6
|
+
gem.email = ["sean.ho@conceptable.net"]
|
7
|
+
gem.description = "DSL for UIKit for RubyMotion"
|
8
|
+
gem.summary = "DSL for UIKit for RubyMotion"
|
9
|
+
gem.homepage = "https://github.com/seanho/SimpleView"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = "simple-view"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = SimpleView::VERSION
|
16
|
+
end
|
@@ -0,0 +1,12 @@
|
|
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
|
@@ -0,0 +1,12 @@
|
|
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
|
@@ -0,0 +1,31 @@
|
|
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
|
@@ -0,0 +1,12 @@
|
|
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
|
@@ -0,0 +1,13 @@
|
|
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
|
@@ -0,0 +1,12 @@
|
|
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
|
@@ -0,0 +1,17 @@
|
|
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
|
@@ -0,0 +1,35 @@
|
|
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
|
@@ -0,0 +1,38 @@
|
|
1
|
+
describe "SimpleView::String" do
|
2
|
+
describe "#to_color" do
|
3
|
+
it "should return color by hex code" do
|
4
|
+
"#f00".to_color.should == UIColor.redColor
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#to_font" do
|
9
|
+
it "should return font by size" do
|
10
|
+
font = "13".to_font
|
11
|
+
font.to_font.pointSize.should == 13
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return bold font by size" do
|
15
|
+
font = "bold 13".to_font
|
16
|
+
font.pointSize.should == 13
|
17
|
+
font.fontName.should.match /bold/i
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return italic font by size" do
|
21
|
+
font = "italic 13".to_font
|
22
|
+
font.pointSize.should == 13
|
23
|
+
font.fontName.should.match /oblique/i
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return font by size and name" do
|
27
|
+
font = "13 ArialMT".to_font
|
28
|
+
font.pointSize.should == 13
|
29
|
+
font.fontName.should == "ArialMT"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#to_image" do
|
34
|
+
it "should return image by filename" do
|
35
|
+
"test.jpg".to_image.should == UIImage.imageNamed("test.jpg")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|