Sha256: e33b0a8ad6f1a31de4367a4e301c22346c0b97ae28f8f503397245d1142f67bd

Contents?: true

Size: 1.29 KB

Versions: 19

Compression:

Stored size: 1.29 KB

Contents

require 'action_view'
require 'sprockets'

module Sprockets
  module Rails
    module Context
      include ActionView::Helpers::AssetUrlHelper
      include ActionView::Helpers::AssetTagHelper

      def self.included(klass)
        klass.class_eval do
          class_attribute :config, :assets_prefix, :digest_assets
        end
      end

      def compute_asset_path(path, options = {})
        @dependencies << 'actioncontroller-asset-url-config'

        begin
          asset_uri = resolve(path)
        rescue FileNotFound
          # TODO: eh, we should be able to use a form of locate that returns
          # nil instead of raising an exception.
        end

        if asset_uri
          asset = link_asset(path)
          digest_path = asset.digest_path
          path = digest_path if digest_assets
          File.join(assets_prefix || "/", path)
        else
          super
        end
      end
    end
  end

  register_dependency_resolver 'actioncontroller-asset-url-config' do |env|
    config = env.context_class.config
    [config.relative_url_root,
    (config.asset_host unless config.asset_host.respond_to?(:call))]
  end

  # fallback to the default pipeline when using Sprockets 3.x
  unless config[:pipelines].include? :debug
    register_pipeline :debug, config[:pipelines][:default]
  end
end

Version data entries

19 entries across 19 versions & 5 rubygems

Version Path
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sprockets-rails-3.2.0/lib/sprockets/rails/context.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.2.0/lib/sprockets/rails/context.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.2.0/lib/sprockets/rails/context.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.2.0/lib/sprockets/rails/context.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.2.0/lib/sprockets/rails/context.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.2.0/lib/sprockets/rails/context.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.2.0/lib/sprockets/rails/context.rb
autocompl-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.2.0/lib/sprockets/rails/context.rb
abaci-0.3.0 vendor/bundle/gems/sprockets-rails-3.1.1/lib/sprockets/rails/context.rb
sprockets-rails-3.2.0 lib/sprockets/rails/context.rb
sprockets-rails-3.1.1 lib/sprockets/rails/context.rb
sprockets-rails-3.1.0 lib/sprockets/rails/context.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.0.4/lib/sprockets/rails/context.rb
sprockets-rails-3.0.4 lib/sprockets/rails/context.rb
sprockets-rails-3.0.3 lib/sprockets/rails/context.rb
sprockets-rails-3.0.2 lib/sprockets/rails/context.rb
sprockets-rails-3.0.1 lib/sprockets/rails/context.rb
sprockets-rails-3.0.0 lib/sprockets/rails/context.rb
sprockets-rails-3.0.0.beta2 lib/sprockets/rails/context.rb