class SlideAssets < Protocol::HTTP::Middleware
- Inherits from
Protocol::HTTP::Middleware
Serves scoped presentation stylesheets and their adjacent assets.
Definitions
def initialize(delegate, root:, stylesheets:)
Signature
-
parameter
delegateProtocol::HTTP::Middleware The next middleware.
-
parameter
rootString The presentation slides root.
-
parameter
stylesheetsProc Returns the currently discovered stylesheets.
Implementation
def initialize(delegate, root:, stylesheets:)
super(delegate)
@root = File.realpath(root)
@stylesheets = stylesheets
end
def call(request)
Serve a presentation stylesheet or adjacent asset.
Implementation
def call(request)
path = request_path(request)
return super unless path&.start_with?(Stylesheet::PREFIX)
unless request.method == "GET" || request.method == "HEAD"
return Protocol::HTTP::Response[405, [["allow", "GET, HEAD"]]]
end
relative_path = decode_path(path.delete_prefix(Stylesheet::PREFIX))
return Protocol::HTTP::Response[404] unless relative_path
if File.extname(relative_path) == ".css"
serve_stylesheet(request, relative_path)
else
serve_asset(request, relative_path)
end
end