Class Jammit::Controller
In: lib/jammit/controller.rb
Parent: ActionController::Base

The JammitController is added to your Rails application when the Gem is loaded. It takes responsibility for /assets, and dynamically packages any missing or uncached asset packages.

Methods

Constants

VALID_FORMATS = [:css, :js]
SUFFIX_STRIPPER = /-(datauri|mhtml)\Z/
NOT_FOUND_PATH = "#{Jammit.public_root}/404.html"

Public Instance methods

The "package" action receives all requests for asset packages that haven‘t yet been cached. The package will be built, cached, and gzipped.

Private Instance methods

Tells the Jammit::Packager to cache and gzip an asset package. We can‘t just use the built-in "cache_page" because we need to ensure that the timestamp that ends up in the MHTML is also on the cached file.

If we‘re generating MHTML/CSS, return a stylesheet with the absolute request URL to the client, and cache a version with the timestamped cache URL swapped in.

Render the 404 page, if one exists, for any packages that don‘t.

Extracts the package name, extension (:css, :js), and variant (:datauri, :mhtml) from the incoming URL.

Generate the complete, timestamped, MHTML url — if we‘re rendering a dynamic MHTML package, we‘ll need to put one URL in the response, and a different one into the cached package.

[Validate]