Sha256: 5edc65d2fc605765df5ed5b04cf8bb978f76688ed9b5814f513f82942ea1f7d7

Contents?: true

Size: 1.5 KB

Versions: 6

Compression:

Stored size: 1.5 KB

Contents

module AngularSprinkles
  module Mixins
    module Controller
      def initialize(*args)
        key_generator = KeyGenerator.new({
          counter: Counter.new,
          cache: Cache.new
        })

        constructor_collection = ConstructorCollection.new({
          json_wrapper: JavaScript::ConstructorThis,
          object_wrapper: ObjectKeyWrapper
        })

        constructor = Constructor.new({
          json_wrapper: JavaScript::ConstructorWrapper,
          collection: constructor_collection
        })

        @_sprinkles = Context.new({
          key_generator: key_generator,
          constructor: constructor,
          constructor_collection: constructor_collection
        })

        super
      end

      def bindable(object)
        object = object.to_a if object.is_a?(::ActiveRecord::Relation)
        object.map!(&method(:bindable)) if object.is_a?(Array)
        key = @_sprinkles.key_generator.call(object)
        @_sprinkles.constructor_collection.push(object, key)
        ModelDecorator.new({
          object: object,
          key: key,
          json_wrapper: JavaScript::BindVariable,
          object_wrapper: ObjectKeyWrapper
        })
      end

      def view_context
        super.tap do |context|
          @_sprinkles.content_yielder = ContentYielder.new({
            cache: Cache.new,
            context: context,
            yield_to: JavaScript::PREFIX
          })
          @_sprinkles.content_yielder.call(@_sprinkles.constructor)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
angular_sprinkles-0.3.0 lib/angular_sprinkles/mixins/controller.rb
angular_sprinkles-0.2.14 lib/angular_sprinkles/mixins/controller.rb
angular_sprinkles-0.2.13 lib/angular_sprinkles/mixins/controller.rb
angular_sprinkles-0.2.12 lib/angular_sprinkles/mixins/controller.rb
angular_sprinkles-0.2.11 lib/angular_sprinkles/mixins/controller.rb
angular_sprinkles-0.2.10 lib/angular_sprinkles/mixins/controller.rb