lib/teacup/layout.rb in teacup-1.2.8 vs lib/teacup/layout.rb in teacup-1.2.9
- old
+ new
@@ -99,11 +99,11 @@
# layout(carousel) do
# subview(UIImage, backgroundColor: UIColor.colorWithImagePattern(image)
# end
#
def layout(view_or_class, name_or_properties=nil, properties_or_nil=nil, &block)
- view = to_instance(view_or_class)
+ view = Teacup.to_instance(view_or_class)
name = nil
properties = properties_or_nil
if name_or_properties.is_a? Hash
@@ -180,32 +180,19 @@
# layout(carousel) do
# subview(UIImage, backgroundColor: UIColor.colorWithImagePattern(image)
# end
#
def subview(class_or_instance, *args, &block)
- instance = to_instance(class_or_instance)
+ instance = Teacup.to_instance(class_or_instance)
(superview_chain.last || top_level_view).addSubview(instance)
layout(instance, *args, &block)
instance
end
protected
-
- def to_instance(class_or_instance)
- if class_or_instance.is_a? Class
- unless class_or_instance <= UIView
- raise "Expected subclass of UIView, got: #{class_or_instance.inspect}"
- end
- return class_or_instance.new
- elsif class_or_instance.is_a?(UIView)
- return class_or_instance
- else
- raise "Expected a UIView, got: #{class_or_instance.inspect}"
- end
- end
# Get's the current stack of views in nested calls to layout.
#
# The view at the end of the stack is the one into which subviews
# are currently being attached.