Sha256: 43b8457cbbeaf69fb56569916c4db65a545d5b55cc149274abebe61716e15506

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module Hanami
  module Extensions
    module View
      # Provides slice-specific helper methods any view object requiring access to helpers.
      #
      # @api public
      # @since 2.1.0
      class SliceConfiguredHelpers < Module
        attr_reader :slice

        # @api private
        # @since 2.1.0
        def initialize(slice)
          super()
          @slice = slice
        end

        # @api private
        # @since 2.1.0
        def extended(klass)
          include_helpers(klass)
        end

        # @return [String]
        #
        # @api public
        # @since 2.1.0
        def inspect
          "#<#{self.class.name}[#{slice.name}]>"
        end

        private

        def include_helpers(klass)
          if mod = helpers_module(slice.app)
            klass.include(mod)
          end

          if mod = helpers_module(slice)
            klass.include(mod)
          end
        end

        def helpers_module(slice)
          return unless slice.namespace.const_defined?(:Views)
          return unless slice.namespace.const_get(:Views).const_defined?(:Helpers)

          slice.namespace.const_get(:Views).const_get(:Helpers)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hanami-2.1.0 lib/hanami/extensions/view/slice_configured_helpers.rb
hanami-2.1.0.rc3 lib/hanami/extensions/view/slice_configured_helpers.rb
hanami-2.1.0.rc2 lib/hanami/extensions/view/slice_configured_helpers.rb