lib/jammit/controller.rb in jammit-0.3.0 vs lib/jammit/controller.rb in jammit-0.3.1

- old
+ new

@@ -9,21 +9,20 @@ SUFFIX_STRIPPER = /-(datauri|mhtml)\Z/ NOT_FOUND_PATH = "#{PUBLIC_ROOT}/404.html" - after_filter :cache_package if perform_caching - # The "package" action receives all requests for asset packages that haven't # yet been cached. The package will be built, cached, and gzipped. def package parse_request case @extension - when :js then render :js => Jammit.packager.pack_javascripts(@package) + when :js then render :js => (@contents = Jammit.packager.pack_javascripts(@package)) when :css then render :text => generate_stylesheets, :content_type => 'text/css' - when :jst then render :js => Jammit.packager.pack_templates(@package) + when :jst then render :js => (@contents = Jammit.packager.pack_templates(@package)) end + cache_package if perform_caching rescue Jammit::PackageNotFound package_not_found end @@ -32,11 +31,11 @@ # 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. def cache_package dir = File.join(page_cache_directory, Jammit.package_path) - Jammit.packager.cache(@package, @extension, @contents || response.body, dir, @variant, @mtime) + Jammit.packager.cache(@package, @extension, @contents, dir, @variant, @mtime) end # 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. @@ -47,11 +46,11 @@ # 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. def generate_stylesheets - return Jammit.packager.pack_stylesheets(@package, @variant) unless @variant == :mhtml + return @contents = Jammit.packager.pack_stylesheets(@package, @variant) unless @variant == :mhtml @mtime = Time.now request_url = prefix_url(request.request_uri) cached_url = prefix_url(Jammit.asset_url(@package, @extension, @variant, @mtime)) css = Jammit.packager.pack_stylesheets(@package, @variant, request_url) @contents = css.gsub(request_url, cached_url) if perform_caching @@ -83,10 +82,10 @@ end # Make the Jammit::Controller available to Rails as a top-level controller. ::JammitController = Jammit::Controller -if RAILS_ENV == 'development' +if Rails.env.development? ActionController::Base.class_eval do append_before_filter { Jammit.reload! } end end