Module: Roda::RodaPlugins::Public
- Defined in:
- lib/roda/plugins/public.rb
Overview
The public plugin adds a r.public
routing method to serve static files from a directory.
The public plugin recognizes the application’s :root option, and defaults to using the public
subfolder of the application’s :root
option. If the application’s :root option is not set, it defaults to the the public
folder in the working directory. Additionally, if a relative path is provided as the :root option to the plugin, it will be considered relative to the application’s :root
option.
Examples:
opts[:root] = '/path/to/app'
plugin :public
plugin :public, :root=>'static'
Defined Under Namespace
Modules: RequestMethods
Constant Summary collapse
- SPLIT =
Regexp.union(*[File::SEPARATOR, File::ALT_SEPARATOR].compact)
- PARSER =
RUBY_VERSION >= '1.9' ? URI::DEFAULT_PARSER : URI
- NULL_BYTE =
"\0".freeze
Class Method Summary collapse
-
.configure(app, opts = {}) ⇒ Object
Use options given to setup a Rack::File instance for serving files.
Class Method Details
.configure(app, opts = {}) ⇒ Object
Use options given to setup a Rack::File instance for serving files. Options:
- :default_mime
-
The default mime type to use if the mime type is not recognized.
- :gzip
-
Whether to serve already gzipped files with a .gz extension for clients supporting gzipped transfer encoding.
- :headers
-
A hash of headers to use for statically served files
- :root
-
Use this option for the root of the public directory (default: “public”)
36 37 38 39 40 |
# File 'lib/roda/plugins/public.rb', line 36 def self.configure(app, opts={}) root = app.(opts[:root]||"public") app.opts[:public_server] = ::Rack::File.new(root, opts[:headers]||{}, opts[:default_mime] || 'text/plain') app.opts[:public_gzip] = opts[:gzip] end |