Skip to content

Instantly share code, notes, and snippets.

@tobiashm
Created January 2, 2014 08:53
Show Gist options
  • Save tobiashm/8216558 to your computer and use it in GitHub Desktop.
Save tobiashm/8216558 to your computer and use it in GitHub Desktop.
Rake task to generate appcache manifest for Rails assets
namespace :appcache do
desc "Create manifest"
task :create do
sprockets_manifest = Rails.root.join("public/assets/manifest.yml")
abort "#{sprockets_manifest} not found" unless sprockets_manifest.exist?
prefix = Rails.configuration.assets.prefix
files = YAML.load(sprockets_manifest.open).map { |_, file| "#{prefix}/#{file}" }
Rails.root.join("public/manifest.appcache").open("w") do |out|
out << "CACHE MANIFEST\n\n"
out << "# " << `git rev-parse HEAD` << "\n"
out << files.join("\n")
out << "\n"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment