Usage
Note that there is a Main App and an App2. This is to demonstrate that you can give links relative to the app, but if they are mounted with an extra prefix (using Rack#map, for example) the helper will respect that and produce the right href attribute.
Installation and loading
Start by installing:
gem 'sinatra-exstatic-assets'
Then require it in your Sinatra app.
require 'sinatra/exstatic_assets'
The helpers
Use these helpers in your views.
By default, the querystring is appended with parameter of "ts" (for timestamp) and the mtime of the file.
The code:
Output: You can choose to take an SHA1 of the file instead: Output: To set the timestamp for all calls, use the settings object: It's set to :mtime_int by default. The timestamp formatting applies to all method calls (except for favicon, because favicons aren't cached in the same manner) but can be overridden by including the option in the method call e.g. Would mean that the resultant stylesheet would have an SHA1 string appended, but other method calls without the "timestamp_format: :mtime_int" would have an mtime appended. The code:
Output: When a URL is given, no timestamp is appended. If the javascript was a file, then like stylesheet_tag above, it would have a timestamp appended. The code:
Output: The code:
Output:stylesheet_tag
Default use:
stylesheet_tag "/css/screen.css"
Alternative timestamp format
stylesheet_tag "/css/screen.css", timestamp_format: :sha1
set :timestamp_format, :sha1
set :timestamp_format, :sha1
stylesheet_tag "/css/screen.css", timestamp_format: :mtime_int
javascript_tag
Using a URL
javascript_tag "http://code.jquery.com/jquery-1.9.1.min.js"
image_tag
image_tag "http://farm3.staticflickr.com/2474/3609420787_f7fc0e53c7.jpg", width: "500", height: "375", alt: "Magic Ball"
favicon_tag
favicon_tag