Module: WebPipe::DryView

Included in:
Conn
Defined in:
lib/web_pipe/extensions/hanami_view/hanami_view.rb

Overview

See the docs for the extension linked from the README.

Constant Summary collapse

VIEW_CONTEXT_KEY =

Where to find in #config request's view context generator.

:view_context
DEFAULT_VIEW_CONTEXT =

Default request's view context

->(_conn) { Types::EMPTY_HASH }

Instance Method Summary collapse

Instance Method Details

#view(view_spec, **kwargs) ⇒ Object

Sets string output of a view as response body.

If the view is not a Hanami::View instance, it is resolved from the configured container.

kwargs is used as the input for the view (the arguments that Hanami::View#call receives). If they doesn't contain an explicit context: key, it can be added through the injection of the result of a lambda present in context's :view_context.(see Hanami::View::Context#with).

Parameters:

  • view_spec (Hanami::View, Any)
  • kwargs (Hash)

    Arguments to pass along to Hanami::View#call

Returns:

  • WebPipe::Conn



32
33
34
35
36
37
38
39
40
41
# File 'lib/web_pipe/extensions/hanami_view/hanami_view.rb', line 32

def view(view_spec, **kwargs)
  view_instance = view_instance(view_spec)
  view_input = view_input(kwargs, view_instance)

  set_response_body(
    view_instance.call(
      **view_input
    ).to_str
  )
end