Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save drakmail/10577784 to your computer and use it in GitHub Desktop.
Save drakmail/10577784 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.3'
s.platform = Gem::Platform::RUBY
s.author = 'Jørgen Orehøj Erichsen, Alexander Maslov'
s.email = 'joe@erichsen.net, drakmail@gmail.com'
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 actionpack from Rails 3.2.5
#
# 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://github.com/steel/sprockets/commit/6327afc3341e34efd1dfdcfad08e3b9d85f7fd4a
# https://github.com/hornairs/sprockets-rails-parallel
require 'sprockets/static_compiler'
require 'parallel'
module Sprockets
class StaticCompiler
def compile
manifest = {}
logical_paths = []
env.each_logical_path(paths) do |logical_path|
logical_paths << logical_path
end
# Compute!
Parallel.map(logical_paths) do |logical_path|
if asset = env.find_asset(logical_path)
digest_path = write_asset(asset)
manifest[asset.logical_path] = digest_path
manifest[aliased_path_for(asset.logical_path)] = digest_path
end
end
write_manifest(manifest) if @manifest
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment