Sha256: 3957a10c4d8dee388344ec39f6713f3af9b7b410a33efb5d972bde0a80a322ef

Contents?: true

Size: 1.04 KB

Versions: 7

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Hanami
  class View
    # Provides a baseline environment across all the templates, parts and scopes
    # in a given rendering.
    #
    # @abstract Subclass this and add your own methods (along with a custom
    #   `#initialize` if you wish to inject dependencies)
    #
    # @api public
    # @since 2.1.0
    class Context
      include DecoratedAttributes

      # @api private
      # @since 2.1.0
      attr_reader :_rendering

      # @api private
      # @since 2.1.0
      def self.new(rendering: RenderingMissing.new, **args)
        allocate.tap do |obj|
          obj.instance_variable_set(:@_rendering, rendering)
          obj.send(:initialize, **args)
        end
      end

      # Returns a new instance of Context
      #
      # @api public
      # @since 2.1.0
      def initialize(**)
      end

      # @api private
      # @since 2.1.0
      def dup_for_rendering(rendering)
        dup.tap do |obj|
          obj.instance_variable_set(:@_rendering, rendering)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hanami-view-2.2.0 lib/hanami/view/context.rb
hanami-view-2.2.0.rc1 lib/hanami/view/context.rb
hanami-view-2.2.0.beta2 lib/hanami/view/context.rb
hanami-view-2.2.0.beta1 lib/hanami/view/context.rb
hanami-view-2.1.0 lib/hanami/view/context.rb
hanami-view-2.1.0.rc3 lib/hanami/view/context.rb
hanami-view-2.1.0.rc2 lib/hanami/view/context.rb