Module: Hanami::Extensions::View::Context

Defined in:
lib/hanami/extensions/view/context.rb

Overview

View context for views in Hanami apps.

Since:

  • 2.1.0

Defined Under Namespace

Modules: ClassExtension

Class Method Summary collapse

Class Method Details

.context_class(slice) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a context class for the given slice. If a context class is not defined, defines a class named ‘Views::Context` within the slice’s namespace.

Since:

  • 2.1.0



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/hanami/extensions/view/context.rb', line 19

def context_class(slice)
  views_namespace = views_namespace(slice)

  if views_namespace.const_defined?(:Context)
    return views_namespace.const_get(:Context)
  end

  views_namespace.const_set(:Context, Class.new(context_superclass(slice)).tap { |klass|
    klass.configure_for_slice(slice)
  })
end