lib/teacup-ios/style.rb in teacup-2.1.12 vs lib/teacup-ios/style.rb in teacup-2.1.13
- old
+ new
@@ -1,12 +1,11 @@
# Fixes here should be copied to teacup-osx/style.rb
module Teacup
# The Style class is where the precedence rules are applied. A Style can
# query the Stylesheet that created it to look up other styles (for
- # `extends:`) and to import other Stylesheets. If it is handed a target (e.g.
- # a `UIView` instance) and orientation, it will merge those in appropriately
- # as well.
+ # `extends:`) and to import other Stylesheets. If it is handed a class (e.g.
+ # `UIView`) and orientation, it will merge those in appropriately as well.
class Style < Hash
attr_accessor :stylename
attr_accessor :stylesheet
Orientations = [:portrait, :upside_up, :upside_down, :landscape, :landscape_left, :landscape_right]
@@ -27,11 +26,11 @@
# returns the value - `nil` has special meaning when querying :portrait or :upside_up
def supports? orientation_key
supports[orientation_key]
end
- def build(target=nil, rotation_orientation=nil, seen={})
+ def build(target_class=nil, rotation_orientation=nil, seen={})
properties = Style.new
properties.stylename = self.stylename
properties.stylesheet = self.stylesheet
# if we have an orientation, only apply those styles. otherwise apply the
@@ -70,11 +69,11 @@
# now we can merge extends, and imported_stylesheets. before merging,
# these will go through the same process that we just finished on the
# local style
if stylesheet && stylesheet.is_a?(Teacup::Stylesheet)
stylesheet.imported_stylesheets.reverse.each do |stylesheet|
- imported_properties = stylesheet.query(self.stylename, target, rotation_orientation, seen)
+ imported_properties = stylesheet.query(self.stylename, target_class, rotation_orientation, seen)
delete_keys.each do |key|
imported_properties.delete(key)
end
Teacup::merge_defaults! properties, imported_properties
end
@@ -83,22 +82,22 @@
also_includes = [also_includes] unless also_includes.is_a? Array
# turn style names into Hashes by querying them on the stylesheet
# (this does not pass `seen`, because this is a new query)
also_includes.each do |also_include|
- extended_properties = stylesheet.query(also_include, target, rotation_orientation)
+ extended_properties = stylesheet.query(also_include, target_class, rotation_orientation)
delete_keys.each do |key|
extended_properties.delete(key)
end
Teacup::merge_defaults! properties, extended_properties
end
end
properties.delete(:extends)
# if we know the class of the target, we can apply styles via class
- # inheritance. We do not pass `target` in this case.
- if target
- target.class.ancestors.each do |ancestor|
+ # inheritance.
+ if target_class
+ target_class.class.ancestors.each do |ancestor|
extended_properties = stylesheet.query(ancestor, nil, rotation_orientation)
Teacup::merge_defaults!(properties, extended_properties)
end
end
end