Class: Sitepress::Renderers::Server
- Inherits:
-
Object
- Object
- Sitepress::Renderers::Server
- Defined in:
- lib/sitepress/renderers/server.rb
Overview
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.
Instance Attribute Summary collapse
-
#rails_app ⇒ Object
readonly
Returns the value of attribute rails_app.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
-
#initialize(resource, rails_app = Rails.application) ⇒ Server
constructor
A new instance of Server.
- #render ⇒ Object
Constructor Details
#initialize(resource, rails_app = Rails.application) ⇒ Server
Returns a new instance of Server.
11 12 13 14 |
# File 'lib/sitepress/renderers/server.rb', line 11 def initialize(resource, rails_app = Rails.application) @rails_app = rails_app @resource = resource end |
Instance Attribute Details
#rails_app ⇒ Object (readonly)
Returns the value of attribute rails_app.
9 10 11 |
# File 'lib/sitepress/renderers/server.rb', line 9 def rails_app @rails_app end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
9 10 11 |
# File 'lib/sitepress/renderers/server.rb', line 9 def resource @resource end |
Instance Method Details
#render ⇒ Object
16 17 18 19 20 21 |
# 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..to_s.inspect}:\n#{e.}" end |