Sha256: 7932ea5a4adf1eb33f75030158d9ef6a49ea6cce275270ded57a1b818115cb3a

Contents?: true

Size: 1.46 KB

Versions: 10

Compression:

Stored size: 1.46 KB

Contents

class Roda
  module RodaPlugins
    # The static plugin loads the Rack::Static middleware into the application.
    # It mainly exists to make serving static files simpler, by supplying
    # defaults to Rack::Static that are appropriate for Roda.
    #
    # The static plugin recognizes the application's :root option, and by default
    # sets the Rack::Static +:root+ option to the +public+ subfolder of the application's
    # +:root+ option.  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.
    #
    # Since the :urls option for Rack::Static is always required, the static plugin
    # uses a separate option for it.
    # 
    # Examples:
    #
    #   opts[:root] = '/path/to/app'
    #   plugin :static, ['/js', '/css'] # path: /path/to/app/public
    #   plugin :static, ['/images'], :root=>'pub'  # path: /path/to/app/pub
    #   plugin :static, ['/media'], :root=>'/path/to/public' # path: /path/to/public
    module Static
      # Load the Rack::Static middleware.  Use the paths given as the :urls option,
      # and set the :root option to be relative to the application's :root option.
      def self.configure(app, paths, opts={})
        opts = opts.dup
        opts[:urls] = paths
        opts[:root] =  File.expand_path(opts[:root]||"public", app.opts[:root])
        app.use ::Rack::Static, opts
      end
    end

    register_plugin(:static, Static)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
roda-2.9.0 lib/roda/plugins/static.rb
roda-2.8.0 lib/roda/plugins/static.rb
roda-2.7.0 lib/roda/plugins/static.rb
roda-2.6.0 lib/roda/plugins/static.rb
roda-2.5.1 lib/roda/plugins/static.rb
roda-2.5.0 lib/roda/plugins/static.rb
roda-2.4.0 lib/roda/plugins/static.rb
roda-2.3.0 lib/roda/plugins/static.rb
roda-2.2.0 lib/roda/plugins/static.rb
roda-2.1.0 lib/roda/plugins/static.rb