Skip to content

Commit

Permalink
Minor refactoring on view proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
seanhotw committed Jan 26, 2013
1 parent ac96b58 commit 7f5b49b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/simple_view/view_proxy.rb
Expand Up @@ -15,9 +15,14 @@ def initialize view = nil, locals = {}
end

def add klass, options = {}, &block
subview = create klass, options, &block
view.addSubview(subview) unless view.nil?
subview
end

def create klass, options = {}, &block
bounds = view.nil? ? CGRectZero : view.bounds
subview = ViewBuilder.view_for klass, bounds, options
view.addSubview(subview) unless view.nil?

if block_given?
child_layout = ViewProxy.new subview, locals
Expand All @@ -27,9 +32,9 @@ def add klass, options = {}, &block
subview
end

[::UIActionSheet, ::UIActivityIndicatorView, ::UIButton, ::UIDatePicker, ::UIImageView, ::UILabel, ::UIPageControl,
::UIPickerView, ::UIProgressView, ::UIScrollView, ::UISearchBar, ::UISegmentedControl, ::UISlider,
::UIStepper, ::UISwitch, ::UITabBar, ::UITableView, ::UITableViewCell, ::UITextField, ::UITextView,
[::UIActionSheet, ::UIActivityIndicatorView, ::UIButton, ::UIDatePicker, ::UIImageView, ::UILabel,
::UIPageControl, ::UIPickerView, ::UIProgressView, ::UIScrollView, ::UISearchBar, ::UISegmentedControl,
::UISlider, ::UIStepper, ::UISwitch, ::UITabBar, ::UITableView, ::UITableViewCell, ::UITextField, ::UITextView,
::UIToolbar, ::UIWebView].each do |klass|
shorthand = "#{klass}"[2..-1].underscore.to_sym
define_method(shorthand) do |*args, &block|
Expand Down

0 comments on commit 7f5b49b

Please sign in to comment.