Module: Cuprum::Rails::Responders::Html::Rendering

Included in:
Cuprum::Rails::Responders::HtmlResponder
Defined in:
lib/cuprum/rails/responders/html/rendering.rb

Overview

Implements generating HTML response objects.

Instance Method Summary collapse

Instance Method Details

#head(status:) ⇒ Cuprum::Rails::Responses::HeadResponse

Creates a HeadResponse based on the given HTTP status.

Parameters:

  • status (Integer)

    the HTTP status of the response.

Returns:



13
14
15
# File 'lib/cuprum/rails/responders/html/rendering.rb', line 13

def head(status:)
  Cuprum::Rails::Responses::HeadResponse.new(status: status)
end

#redirect_back(fallback_location: '/', flash: {}, status: 302) ⇒ Object

Creates a RedirectBackResponse based on the given HTTP status.

Parameters:

  • fallback_location (String) (defaults to: '/')

    the path or url to redirect to if the previous location cannot be determined.

  • flash (Hash) (defaults to: {})

    the flash messages to set.

  • status (Integer) (defaults to: 302)

    the HTTP status of the response.



23
24
25
26
# File 'lib/cuprum/rails/responders/html/rendering.rb', line 23

def redirect_back(fallback_location: '/', flash: {}, status: 302)
  Cuprum::Rails::Responses::Html::RedirectBackResponse
    .new(fallback_location: fallback_location, flash: flash, status: status)
end

#redirect_to(path, flash: {}, status: 302) ⇒ Cuprum::Rails::Responses::Html::RedirectResponse

Creates a RedirectResponse based on the given path and HTTP status.

Parameters:

  • flash (Hash) (defaults to: {})

    the flash messages to set.

  • path (String)

    the path or url to redirect to.

  • status (Integer) (defaults to: 302)

    the HTTP status of the response.

Returns:



35
36
37
38
# File 'lib/cuprum/rails/responders/html/rendering.rb', line 35

def redirect_to(path, flash: {}, status: 302)
  Cuprum::Rails::Responses::Html::RedirectResponse
    .new(path, flash: flash, status: status)
end

#render(template, assigns: nil, flash: {}, layout: nil, status: 200) ⇒ Cuprum::Rails::Responses::Html::RenderResponse

Creates a RenderResponse based on the given template and parameters.

Parameters:

  • assigns (Hash) (defaults to: nil)

    variables to assign when rendering the template.

  • flash (Hash) (defaults to: {})

    the flash messages to set.

  • layout (String) (defaults to: nil)

    the layout to render.

  • status (Integer) (defaults to: 200)

    the HTTP status of the response.

  • template (String, Symbol)

    the template to render.

Returns:



49
50
51
52
53
54
55
56
57
# File 'lib/cuprum/rails/responders/html/rendering.rb', line 49

def render(template, assigns: nil, flash: {}, layout: nil, status: 200)
  Cuprum::Rails::Responses::Html::RenderResponse.new(
    template,
    assigns: assigns || default_assigns,
    flash:   flash,
    layout:  layout,
    status:  status
  )
end