The relative_path plugin adds a relative_path method that accepts an absolute path and returns a path relative to the current request by adding an appropriate prefix:
plugin :relative_path route do |r| relative_path("/foo") end # GET / "./foo" # GET /bar "./foo" # GET /bar/ "../foo" # GET /bar/baz/quux "../../foo"
It also offers a relative_prefix method that returns a string that can be prepended to an absolute path. This can be more efficient if you need to convert multiple paths.
This plugin is mostly designed for applications using Roda
as a static site generator, where the generated site can be hosted at any subpath.