Sha256: b2376da8b1dc0428da2196e6eefe15f9ef1a2bd9876e3f306fe8bb75f79ffa6d

Contents?: true

Size: 1.26 KB

Versions: 18

Compression:

Stored size: 1.26 KB

Contents

# @provides MotionKit::BaseLayoutClassMethods
module MotionKit
  module BaseLayoutClassMethods
    def target_klasses
      # We don't want subclasses, just BaseLayout
      return BaseLayout.target_klasses unless self == BaseLayout
      @target_klasses ||= {}
    end

    def targets(klass=nil)
      return nil if klass.nil? && self == BaseLayout
      return @targets || superclass.targets if klass.nil?
      @targets = klass

      if BaseLayout.target_klasses.key?(klass) && BaseLayout.target_klasses[klass] != self
        NSLog('WARNING!  The class “%@” was registered with the layout class “%@”',
          klass, BaseLayout.target_klasses[klass])
      end
      BaseLayout.target_klasses[klass] = self

      nil
    end

    # Instantiates a new Layout instance using `layout` as the root-level layout
    def layout_for(klass)
      memoized_klass = memoize(klass)
      memoized_klass && memoized_klass.new
    end

    # Cache registered classes
    def memoize(klass)
      @memoize ||= {}
      @memoize[klass] ||= begin
        while klass
          break if registered_class = target_klasses[klass]
          klass = klass.superclass
        end
        @memoize[klass] = registered_class if registered_class
      end
      @memoize[klass]
    end

  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
motion-kit-1.1.1 lib/motion-kit/helpers/base_layout_class_methods.rb
motion-kit-1.1.0 lib/motion-kit/helpers/base_layout_class_methods.rb
motion-kit-1.0.3 lib/motion-kit/helpers/base_layout_class_methods.rb
motion-kit-1.0.2 lib/motion-kit/helpers/base_layout_class_methods.rb
motion-kit-1.0.1 lib/motion-kit/helpers/base_layout_class_methods.rb
motion-kit-1.0.0 lib/motion-kit/helpers/base_layout_class_methods.rb
motion-kit-0.18.0 lib/motion-kit/helpers/base_layout_class_methods.rb
motion-kit-0.17.0 lib/motion-kit/helpers/base_layout_class_methods.rb
motion-kit-0.16.0 lib/motion-kit/helpers/base_layout_class_methods.rb
motion-kit-0.15.0 lib/motion-kit/helpers/base_layout_class_methods.rb
motion-kit-0.14.2 lib/motion-kit/helpers/base_layout_class_methods.rb
motion-kit-0.14.1 lib/motion-kit/helpers/base_layout_class_methods.rb
motion-kit-0.14.0 lib/motion-kit/helpers/base_layout_class_methods.rb
motion-kit-0.13.0 lib/motion-kit/helpers/base_layout_class_methods.rb
motion-kit-0.12.0 lib/motion-kit/layouts/base_layout_class_methods.rb
motion-kit-0.11.2 lib/motion-kit/layouts/base_layout_class_methods.rb
motion-kit-0.11.1 lib/motion-kit/layouts/base_layout_class_methods.rb
motion-kit-0.11.0 lib/motion-kit/layouts/base_layout_class_methods.rb