Skip to content

Instantly share code, notes, and snippets.

@wmoxam
Created December 17, 2008 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wmoxam/37228 to your computer and use it in GitHub Desktop.
Save wmoxam/37228 to your computer and use it in GitHub Desktop.
# Rails doesn't have a way to pre-generate javascript cache files
# This is lifted directly from rails ..
def write_asset_file_contents(joined_asset_path, asset_paths)
unless file_exist?(joined_asset_path)
FileUtils.mkdir_p(File.dirname(joined_asset_path))
File.open(joined_asset_path, "w+") { |cache| cache.write(join_asset_file_contents(asset_paths)) }
end
end
namespace :javascript do
desc "Generate cached javascript files"
task :regenerate, :roles => :app, :primary => true do
javascripts_dir = "#{release_path}/public/javascripts"
app_version = `cat #{release_path}/app_version`.match(/(\d+)/)[1]
cache_destination = File.join(javascripts_dir, "cache/all_#{app_version}")
source_files = ['prototype', 'effects', 'dragdrop', 'controls', 'application'].collect { |name| File.join(javascripts_dir, "#{name}.js") }
write_asset_file_contents cache_destination, source_files
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment