Skip to content

Instantly share code, notes, and snippets.

@brandonaaron
Created September 27, 2010 19:58
Show Gist options
  • Save brandonaaron/599704 to your computer and use it in GitHub Desktop.
Save brandonaaron/599704 to your computer and use it in GitHub Desktop.
require 'lib/jsmin'
# override the write_asset_file_contents so that it will minify js in production via jsmin.rb
module ActionView
module Helpers
module AssetTagHelper
alias_method :write_asset_file_contents_stock, :write_asset_file_contents
def write_asset_file_contents(joined_asset_path, asset_paths)
ret = write_asset_file_contents_stock(joined_asset_path, asset_paths)
if File.extname(joined_asset_path) == ".js"
tmp_path = "#{RAILS_ROOT}/tmp/asset_combined.js"
FileUtils.cp(joined_asset_path, tmp_path)
File.open(tmp_path, 'r') do |tmp|
File.open(joined_asset_path, 'w') { |file| file.write(JSMin.minify(tmp)) }
end
FileUtils.rm(tmp_path)
end
ret
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment