class Sitepress::Renderers::Server
Renders resources by invoking a rack call to the Rails application. From my experiments rendering as of 2021, this is the most reliable way to render resources. Rendering via `Renderers::Controller` has lots of various subtle issues that are surprising. People don't like surprises, so I opted to render through a slightly heavier stack.
Attributes
rails_app[R]
resource[R]
Public Class Methods
new(resource, rails_app = Rails.application)
click to toggle source
# File lib/sitepress/renderers/server.rb, line 11 def initialize(resource, rails_app = Rails.application) @rails_app = rails_app @resource = resource end
Public Instance Methods
render()
click to toggle source
# File lib/sitepress/renderers/server.rb, line 16 def render code, headers, response = rails_app.routes.call env response.body rescue => e raise RenderingError.new "Error rendering #{resource.request_path.inspect} at #{resource.asset.path.expand_path.to_s.inspect}:\n#{e.message}" end
Private Instance Methods
env()
click to toggle source
# File lib/sitepress/renderers/server.rb, line 24 def env { "PATH_INFO"=> resource.request_path, "REQUEST_METHOD"=>"GET", "rack.input" => "GET" } end