Sha256: 746664354de3e7d78acc6e49b79125599be605c33adde474b080a03796de63c1

Contents?: true

Size: 1.48 KB

Versions: 10

Compression:

Stored size: 1.48 KB

Contents

module AngularSprinkles
  module Mixins
    module Controller
      def initialize(*args)
        counter = Counter.new
        key_generator = KeyGenerator.new(counter: counter)

        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: ContentCache.new,
            context: context,
            yield_to: JavaScript::PREFIX
          })
          @_sprinkles.content_yielder.call(@_sprinkles.constructor)
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
angular_sprinkles-0.2.9 lib/angular_sprinkles/mixins/controller.rb
angular_sprinkles-0.2.8 lib/angular_sprinkles/mixins/controller.rb
angular_sprinkles-0.2.7 lib/angular_sprinkles/mixins/controller.rb
angular_sprinkles-0.2.6 lib/angular_sprinkles/mixins/controller.rb
angular_sprinkles-0.2.5 lib/angular_sprinkles/mixins/controller.rb
angular_sprinkles-0.2.4 lib/angular_sprinkles/mixins/controller.rb
angular_sprinkles-0.2.3 lib/angular_sprinkles/mixins/controller.rb
angular_sprinkles-0.2.2 lib/angular_sprinkles/mixins/controller.rb
angular_sprinkles-0.2.1 lib/angular_sprinkles/mixins/controller.rb
angular_sprinkles-0.2.0 lib/angular_sprinkles/mixins/controller.rb