Module: Tynn::Static
- Defined in:
- lib/tynn/static.rb
Overview
Public: Adds support for static files (javascript files, images, stylesheets, etc).
Examples
require "tynn"
require "tynn/static"
Tynn.plugin(Tynn::Static, ["/js", "/css"])
By default, serves all requests beginning with the given paths from the folder public
in the current directory (e.g. public/js/*
, public/css/*
). You can change the default by passing the :root
option.
Examples
Tynn.plugin(Tynn::Static, ["/js", "/css"], root: "assets")
Under the hood, it uses the Rack::Static
middleware. Thus, supports all the options available by the middleware. Check Rack::Static for more information.
Examples
Tynn.plugin(Tynn::Static, ["/js", "/css"], index: "index.html")
Class Method Summary collapse
-
.setup(app, urls, opts = {}) ⇒ Object
Internal: Configures Rack::Static middleware.
Class Method Details
.setup(app, urls, opts = {}) ⇒ Object
Internal: Configures Rack::Static middleware.
32 33 34 35 36 37 38 39 |
# File 'lib/tynn/static.rb', line 32 def self.setup(app, urls, opts = {}) = opts.dup [:urls] ||= urls [:root] ||= File.("public", Dir.pwd) app.use(Rack::Static, ) end |