module Roda::RodaPlugins::TimestampPublic

  1. lib/roda/plugins/timestamp_public.rb

The timestamp_public plugin adds a timestamp_path method for constructing timestamp paths, and a r.timestamp_public routing method to serve static files from a directory (using the public plugin). This plugin is useful when you want to modify the path to static files when the modify timestamp on the file changes, ensuring that requests for the static file will not be cached.

Note that while this plugin will not serve files outside of the public directory, for performance reasons it does not check the path of the file is inside the public directory when getting the modify timestamp. If the timestamp_path method is called with untrusted input, it is possible for an attacker to get the modify timestamp for any file on the file system.


# Use public folder as location of files, and static as the path prefix
plugin :timestamp_public

# Use /path/to/app/static as location of files, and public as the path prefix
opts[:root] = '/path/to/app'
plugin :public, root: 'static', prefix: 'public'

# Assuming public is the location of files, and static is the path prefix
r.route do
  # Make GET /static/1238099123/images/foo.png look for public/images/foo.png

  r.get "example" do
    # "/static/1238099123/images/foo.png"


Public Class

  1. configure

Public Class methods

configure(app, opts={})

Use options given to setup timestamped file serving. The following option is recognized by the plugin:


The prefix for paths, before the timestamp segment

The options given are also passed to the public plugin.

[show source]
   # File lib/roda/plugins/timestamp_public.rb
44 def self.configure(app, opts={})
45   app.plugin :public, opts
46   app.opts[:timestamp_public_prefix] = (opts[:prefix] || app.opts[:timestamp_public_prefix] || "static").dup.freeze
47 end