Skip to content

Instantly share code, notes, and snippets.

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 juno/5771290 to your computer and use it in GitHub Desktop.
Save juno/5771290 to your computer and use it in GitHub Desktop.
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = 'parallel_assets_compiler'
s.version = '0.2.0'
s.platform = Gem::Platform::RUBY
s.author = 'Jørgen Orehøj Erichsen'
s.email = 'joe@erichsen.net'
s.summary = 'Compile assets in parallel'
s.description = 'Compile assets in parallel to speed up deployment'
s.files = ['parallel_assets_compiler.rb']
s.require_path = '.'
s.add_dependency('parallel')
s.add_dependency('actionpack')
end
# Compile assets in parallel to speed up deployment
#
# Works by monkey patching to sprockets-rails 2.0.0 (for Rails 4.0.0)
#
# Use it by adding this to your Gemfile and run bundle install
#
# gem 'parallel_assets_compiler', :git => 'git://gist.github.com/2873091.git'
#
# Inspired by
# https://gist.github.com/joerichsen/2873091
# https://github.com/steel/sprockets/commit/6327afc3341e34efd1dfdcfad08e3b9d85f7fd4a
# https://github.com/hornairs/sprockets-rails-parallel
require 'sprockets/manifest'
require 'parallel'
module Sprockets
class Manifest
def compile(*args)
raise Error, "manifest requires environment for compilation" unless environment
paths = environment.each_logical_path(*args).to_a +
args.flatten.select { |fn| Pathname.new(fn).absolute? if fn.is_a?(String)}
local_assets = []
paths.each do |path|
if asset = find_asset(path)
files[asset.digest_path] = {
'logical_path' => asset.logical_path,
'mtime' => asset.mtime.iso8601,
'size' => asset.bytesize,
'digest' => asset.digest
}
assets[asset.logical_path] = asset.digest_path
local_assets << asset
end
end
Parallel.each(local_assets) do |asset|
target = File.join(dir, asset.digest_path)
if File.exist?(target)
logger.debug "Skipping #{target}, already exists"
else
logger.info "Writing #{target}"
asset.write_to target
asset.write_to "#{target}.gz" if asset.is_a?(BundledAsset)
end
save
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment