Class: Sitepress::Server
- Inherits:
-
Object
- Object
- Sitepress::Server
- Defined in:
- lib/sitepress/server.rb
Overview
Run a Sitepress site as a rack app.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(site:) ⇒ Server
constructor
A new instance of Server.
Constructor Details
#initialize(site:) ⇒ Server
Returns a new instance of Server.
4 5 6 |
# File 'lib/sitepress/server.rb', line 4 def initialize(site: ) @site = site end |
Instance Method Details
#call(env) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sitepress/server.rb', line 8 def call(env) req = Rack::Request.new(env) resource = @site.get req.path if resource mime_type = resource.mime_type.to_s context = RenderingContext.new(resource: resource, site: @site) body = context.render [ 200, {"Content-Type" => mime_type}, Array(body) ] else [ 404, {"Content-Type" => "text/plain"}, ["Not Found"]] end end |