class Cuprum::Rails::Responses::Html::RenderResponse
Encapsulates an HTML response that renders a given template.
Attributes
assigns[R]
@return [Hash] variables to assign when rendering the template.
layout[R]
@return [String] the layout to render.
status[R]
@return [Integer] the HTTP status of the response.
template[R]
@return [String, Symbol] the template to render.
Public Class Methods
new(template, assigns: {}, layout: nil, status: 200)
click to toggle source
@param assigns [Hash] Variables to assign when rendering the template. @param layout [String] The layout to render. @param status [Integer] The HTTP status of the response. @param template [String, Symbol] The template to render.
# File lib/cuprum/rails/responses/html/render_response.rb, line 12 def initialize(template, assigns: {}, layout: nil, status: 200) @assigns = assigns @layout = layout @status = status @template = template end
Public Instance Methods
call(renderer)
click to toggle source
Calls the renderer’s render method with the template and parameters.
@param renderer [#render] The context for executing the response, such as
a Rails controller.
# File lib/cuprum/rails/responses/html/render_response.rb, line 35 def call(renderer) assign_variables(renderer) options = { status: status } options[:layout] = layout if layout renderer.render(template, **options) end
Private Instance Methods
assign_variables(renderer)
click to toggle source
# File lib/cuprum/rails/responses/html/render_response.rb, line 46 def assign_variables(renderer) assigns.each do |key, value| renderer.instance_variable_set("@#{key}", value) end end