lib/jammit/controller.rb in jammit-0.4.4 vs lib/jammit/controller.rb in jammit-0.5.0
- old
+ new
@@ -3,24 +3,27 @@
# 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.
class Controller < ActionController::Base
- VALID_FORMATS = [:css, :js, :jst]
+ VALID_FORMATS = [:css, :js]
SUFFIX_STRIPPER = /-(datauri|mhtml)\Z/
NOT_FOUND_PATH = "#{PUBLIC_ROOT}/404.html"
# 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 => (@contents = Jammit.packager.pack_javascripts(@package))
- when :css then render :text => generate_stylesheets, :content_type => 'text/css'
- when :jst then render :js => (@contents = Jammit.packager.pack_templates(@package))
+ when :js
+ render :js => (@contents = Jammit.packager.pack_javascripts(@package))
+ when Jammit.template_extension.to_sym
+ render :js => (@contents = Jammit.packager.pack_templates(@package))
+ when :css
+ render :text => generate_stylesheets, :content_type => 'text/css'
end
cache_package if perform_caching
rescue Jammit::PackageNotFound
package_not_found
end
@@ -55,16 +58,16 @@
css = Jammit.packager.pack_stylesheets(@package, @variant, request_url)
@contents = css.gsub(request_url, cached_url) if perform_caching
css
end
- # Extracts the package name, extension (:css, :js, :jst), and variant
- # (:datauri, :mhtml) from the incoming URL.
+ # Extracts the package name, extension (:css, :js), and variant (:datauri,
+ # :mhtml) from the incoming URL.
def parse_request
pack = params[:package]
@extension = params[:extension].to_sym
- raise PackageNotFound unless VALID_FORMATS.include?(@extension)
+ raise PackageNotFound unless (VALID_FORMATS + [Jammit.template_extension.to_sym]).include?(@extension)
if Jammit.embed_assets
suffix_match = pack.match(SUFFIX_STRIPPER)
@variant = Jammit.embed_assets && suffix_match && suffix_match[1].to_sym
pack.sub!(SUFFIX_STRIPPER, '')
end
@@ -82,10 +85,10 @@
end
# Make the Jammit::Controller available to Rails as a top-level controller.
::JammitController = Jammit::Controller
-if Rails.env.development?
+if defined?(Rails) && Rails.env.development?
ActionController::Base.class_eval do
append_before_filter { Jammit.reload! }
end
end