Skip to content

Instantly share code, notes, and snippets.

@mcasimir
Created July 11, 2012 21:30
Show Gist options
  • Select an option

  • Save mcasimir/3093713 to your computer and use it in GitHub Desktop.

Select an option

Save mcasimir/3093713 to your computer and use it in GitHub Desktop.
Assets Rake
namespace :assets do
task :compile => :environment do
require 'sprockets'
# workaround used also by native assets:precompile:all to load sprockets hooks
_ = ActionView::Base
# ==============================================
# = Read configuration from Rails / assets.yml =
# ==============================================
env = Rails.application.assets
target = File.join(::Rails.public_path, Rails.application.config.assets.prefix)
assets = YAML.load_file(Rails.root.join('config', 'assets.yml'))
manifest_path = Rails.root.join(target, 'manifest.yml')
digest = !!Rails.application.config.assets.digest
manifest = digest
# =======================
# = Old manifest backup =
# =======================
manifest_old = File.exists?(manifest_path) ? YAML.load_file(manifest_path) : {}
# ==================
# = Compile assets =
# ==================
compiler = Sprockets::StaticCompiler.new(env,
target,
assets,
:digest => digest,
:manifest => manifest)
compiler.compile
# ===================================
# = Merge new manifest into old one =
# ===================================
manifest_new = File.exists?(manifest_path) ? YAML.load_file(manifest_path) : {}
File.open(manifest_path, 'w') do |out|
YAML.dump(manifest_old.merge(manifest_new), out)
end
# ===============================
# = Compress assets if required =
# ===============================
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment