Class: Jammit::Controller

Inherits:
ActionController::Base
  • Object
show all
Defined in:
lib/jammit/controller.rb

Overview

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.

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#packageObject

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



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/jammit/controller.rb', line 18

def package
  parse_request
  template_ext = Jammit.template_extension.to_sym
  case @extension
  when :js
    render :js => (@contents = Jammit.packager.pack_javascripts(@package))
  when template_ext
    render :js => (@contents = Jammit.packager.pack_templates(@package))
  when :css
    render :text => generate_stylesheets, :content_type => 'text/css'
  end
  cache_package if perform_caching && (@extension != template_ext)
rescue Jammit::PackageNotFound
  package_not_found
end