Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. Alexander revised this gist Apr 13, 2014. 2 changed files with 11 additions and 14 deletions.
    6 changes: 3 additions & 3 deletions parallel_assets_compiler.gemspec
    Original file line number Diff line number Diff line change
    @@ -2,10 +2,10 @@

    Gem::Specification.new do |s|
    s.name = 'parallel_assets_compiler'
    s.version = '0.2.0'
    s.version = '0.3'
    s.platform = Gem::Platform::RUBY
    s.author = 'Jørgen Orehøj Erichsen'
    s.email = '[email protected]'
    s.author = 'Jørgen Orehøj Erichsen, Alexander Maslov'
    s.email = '[email protected], [email protected]'
    s.summary = 'Compile assets in parallel'
    s.description = 'Compile assets in parallel to speed up deployment'

    19 changes: 8 additions & 11 deletions parallel_assets_compiler.rb
    Original file line number Diff line number Diff line change
    @@ -17,23 +17,20 @@ module Sprockets
    class StaticCompiler

    def compile
    # Collect paths
    manifest = {}
    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)
    env.each_logical_path(paths) do |logical_path|
    logical_paths << logical_path
    end

    # Compute!
    results = Parallel.map(logical_paths) do |logical_path|
    Parallel.map(logical_paths) do |logical_path|
    if asset = env.find_asset(logical_path)
    [logical_path, write_asset(asset)]
    digest_path = write_asset(asset)
    manifest[asset.logical_path] = digest_path
    manifest[aliased_path_for(asset.logical_path)] = digest_path
    end
    end

    write_manifest(Hash[results]) if @manifest
    write_manifest(manifest) if @manifest
    end

    end
  2. @joerichsen joerichsen revised this gist Aug 3, 2012. 2 changed files with 11 additions and 7 deletions.
    2 changes: 1 addition & 1 deletion parallel_assets_compiler.gemspec
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    Gem::Specification.new do |s|
    s.name = 'parallel_assets_compiler'
    s.version = '0.1.0'
    s.version = '0.2.0'
    s.platform = Gem::Platform::RUBY
    s.author = 'Jørgen Orehøj Erichsen'
    s.email = '[email protected]'
    16 changes: 10 additions & 6 deletions parallel_assets_compiler.rb
    Original file line number Diff line number Diff line change
    @@ -17,19 +17,23 @@ module Sprockets
    class StaticCompiler

    def compile
    manifest = {}
    # Collect paths
    logical_paths = []
    env.each_logical_path { |logical_path| logical_paths << logical_path }
    Parallel.map(logical_paths) do |logical_path|
    env.each_logical_path do |logical_path|
    if File.basename(logical_path)[/[^\.]+/, 0] == 'index'
    logical_path.sub!(/\/index\./, '.')
    end
    next unless compile_path?(logical_path)
    logical_paths << logical_path if compile_path?(logical_path)
    end

    # Compute!
    results = Parallel.map(logical_paths) do |logical_path|
    if asset = env.find_asset(logical_path)
    manifest[logical_path] = write_asset(asset)
    [logical_path, write_asset(asset)]
    end
    end
    write_manifest(manifest) if @manifest

    write_manifest(Hash[results]) if @manifest
    end

    end
  3. @joerichsen joerichsen revised this gist Jun 5, 2012. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions parallel_assets_compiler.gemspec
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # -*- encoding: utf-8 -*-

    Gem::Specification.new do |s|
    s.name = 'parallel_assets_compiler'
    s.version = '0.1.0'
  4. @joerichsen joerichsen revised this gist Jun 5, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions parallel_assets_compiler.rb
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,7 @@
    # https://github.com/hornairs/sprockets-rails-parallel

    require 'sprockets/static_compiler'
    require 'parallel'

    module Sprockets
    class StaticCompiler
  5. @joerichsen joerichsen revised this gist Jun 5, 2012. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions parallel_assets_compiler.rb
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,10 @@
    #
    # 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
  6. @joerichsen joerichsen revised this gist Jun 5, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion parallel_assets_compiler.rb
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@
    # https://github.com/steel/sprockets/commit/6327afc3341e34efd1dfdcfad08e3b9d85f7fd4a
    # https://github.com/hornairs/sprockets-rails-parallel

    require 'sprockets/static_compiler
    require 'sprockets/static_compiler'

    module Sprockets
    class StaticCompiler
  7. @joerichsen joerichsen revised this gist Jun 5, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion parallel_assets_compiler.rb
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@
    # https://github.com/steel/sprockets/commit/6327afc3341e34efd1dfdcfad08e3b9d85f7fd4a
    # https://github.com/hornairs/sprockets-rails-parallel

    require 'sprockets/railtie'
    require 'sprockets/static_compiler
    module Sprockets
    class StaticCompiler
  8. @joerichsen joerichsen revised this gist Jun 5, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion parallel_assets_compiler.rb
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@
    # https://github.com/steel/sprockets/commit/6327afc3341e34efd1dfdcfad08e3b9d85f7fd4a
    # https://github.com/hornairs/sprockets-rails-parallel

    require 'action_pack'
    require 'sprockets/railtie'

    module Sprockets
    class StaticCompiler
  9. @joerichsen joerichsen revised this gist Jun 5, 2012. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion parallel_assets_compiler.rb
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,8 @@
    # https://github.com/steel/sprockets/commit/6327afc3341e34efd1dfdcfad08e3b9d85f7fd4a
    # https://github.com/hornairs/sprockets-rails-parallel

    require 'action_pack'

    module Sprockets
    class StaticCompiler

    @@ -26,4 +28,4 @@ def compile
    end

    end
    end
    end
  10. @joerichsen joerichsen revised this gist Jun 5, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions parallel_assets_compiler.gemspec
    Original file line number Diff line number Diff line change
    @@ -11,4 +11,5 @@ Gem::Specification.new do |s|
    s.require_path = '.'

    s.add_dependency('parallel')
    s.add_dependency('actionpack')
    end
  11. @joerichsen joerichsen revised this gist Jun 5, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion parallel_assets_compiler.gemspec
    Original file line number Diff line number Diff line change
    @@ -10,5 +10,5 @@ Gem::Specification.new do |s|
    s.files = ['parallel_assets_compiler.rb']
    s.require_path = '.'

    s.add_development_dependency('parallel')
    s.add_dependency('parallel')
    end
  12. @joerichsen joerichsen created this gist Jun 5, 2012.
    14 changes: 14 additions & 0 deletions parallel_assets_compiler.gemspec
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    Gem::Specification.new do |s|
    s.name = 'parallel_assets_compiler'
    s.version = '0.1.0'
    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_development_dependency('parallel')
    end
    29 changes: 29 additions & 0 deletions parallel_assets_compiler.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    # Compile assets in parallel to speed up deployment
    #
    # Works by monkey patching actionpack from Rails 3.2.5
    #
    # Inspired by
    # https://github.com/steel/sprockets/commit/6327afc3341e34efd1dfdcfad08e3b9d85f7fd4a
    # https://github.com/hornairs/sprockets-rails-parallel

    module Sprockets
    class StaticCompiler

    def compile
    manifest = {}
    logical_paths = []
    env.each_logical_path { |logical_path| logical_paths << logical_path }
    Parallel.map(logical_paths) do |logical_path|
    if File.basename(logical_path)[/[^\.]+/, 0] == 'index'
    logical_path.sub!(/\/index\./, '.')
    end
    next unless compile_path?(logical_path)
    if asset = env.find_asset(logical_path)
    manifest[logical_path] = write_asset(asset)
    end
    end
    write_manifest(manifest) if @manifest
    end

    end
    end