Sha256: ae615cbf6e740072cace089013d99f0cc33fc2d5289efb0ef61bdeeb6768d691

Contents?: true

Size: 1.3 KB

Versions: 34

Compression:

Stored size: 1.3 KB

Contents

require 'action_view/helpers'
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

34 entries across 33 versions & 12 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/sprockets-rails-3.5.2/lib/sprockets/rails/context.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/sprockets-rails-3.5.2/lib/sprockets/rails/context.rb
sprockets-rails-3.5.2 lib/sprockets/rails/context.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/sprockets-rails-3.5.1/lib/sprockets/rails/context.rb
sprockets-rails-3.5.1 lib/sprockets/rails/context.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/sprockets-rails-3.5.0/lib/sprockets/rails/context.rb
sprockets-rails-3.5.0 lib/sprockets/rails/context.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/sprockets-rails-3.4.2/lib/sprockets/rails/context.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/sprockets-rails-3.4.2/lib/sprockets/rails/context.rb
sprockets-rails-3.4.2 lib/sprockets/rails/context.rb
sprockets-rails-3.4.1 lib/sprockets/rails/context.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/sprockets-rails-3.3.0/lib/sprockets/rails/context.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/sprockets-rails-3.3.0/lib/sprockets/rails/context.rb
sprockets-rails-3.4.0 lib/sprockets/rails/context.rb
sprockets-rails-3.3.0 lib/sprockets/rails/context.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/sprockets-rails-3.2.2/lib/sprockets/rails/context.rb
sprockets-rails-3.2.2 lib/sprockets/rails/context.rb
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/context.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/context.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/context.rb