Forked from joerichsen/parallel_assets_compiler.gemspec
Created
September 19, 2012 09:31
-
-
Save maksar/3748697 to your computer and use it in GitHub Desktop.
Microgem for compiling assets in parallel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
Gem::Specification.new do |s| | |
s.name = 'parallel_assets_compiler' | |
s.version = '0.2.2' | |
s.platform = Gem::Platform::RUBY | |
s.author = 'Jørgen Orehøj Erichsen' | |
s.email = '[email protected]' | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
# Collect paths | |
logical_paths = [] | |
env.each_logical_path do |logical_path| | |
if File.basename(logical_path)[/[^\.]+/, 0] == 'index' | |
logical_path.sub!(/\/index\./, '.') | |
end | |
logical_paths << logical_path if compile_path?(logical_path) | |
end | |
# Compute! | |
results = Parallel.map(logical_paths, in_threads: 2) do |logical_path| | |
if asset = env.find_asset(logical_path) | |
[logical_path, write_asset(asset)] | |
end | |
end | |
write_manifest(Hash[results]) if @manifest | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment