Sha256: c000d036d8e4fb1dcee8064151240e06fb5b5756bda2564a17b5c3453b52b9e7

Contents?: true

Size: 1.16 KB

Versions: 36

Compression:

Stored size: 1.16 KB

Contents

require 'sprockets/server'

module Opal
  module Sprockets
    module SourceMapHeaderPatch
      # Adds the source map header to all sprocket responses for assets
      # with a .rb or .opal extension in the extension chain.
      def headers_with_opal_source_maps(env, asset, length)
        headers_without_opal_source_maps(env, asset, length).tap do |current_headers|
          if asset.pathname.to_s =~ /\.(rb|opal)\b/
            base_path = asset.logical_path.gsub('.js', '')
            current_headers['X-SourceMap'] = "#{::Opal::Sprockets::SourceMapHeaderPatch.prefix}/#{base_path}.map"
          end
        end
      end

      def self.included(base)
        # Poor man's alias_method_chain :)
        base.send(:alias_method, :headers_without_opal_source_maps, :headers)
        base.send(:alias_method, :headers, :headers_with_opal_source_maps)
      end

      def self.inject!(prefix)
        self.prefix = prefix
        unless ::Sprockets::Server.ancestors.include?(self)
          ::Sprockets::Server.send :include, self
        end
      end

      def self.prefix
        @prefix
      end

      def self.prefix= val
        @prefix = val
      end
    end
  end
end


Version data entries

36 entries across 36 versions & 3 rubygems

Version Path
opal-sprockets-0.4.2.pre.1.0.11.0.3.1 lib/opal/sprockets/source_map_header_patch.rb
opal-0.10.6 lib/opal/sprockets/source_map_header_patch.rb
opal-0.10.6.beta lib/opal/sprockets/source_map_header_patch.rb
opal-sprockets-0.4.1.0.11.0.3.1 lib/opal/sprockets/source_map_header_patch.rb
opal-sprockets-0.4.1.0.11.0.rc1.3.1 lib/opal/sprockets/source_map_header_patch.rb
opal-0.10.5 lib/opal/sprockets/source_map_header_patch.rb
opal-sprockets-0.4.1.0.11.0.rc1.3.1.beta2 lib/opal/sprockets/source_map_header_patch.rb
opal-0.10.4 lib/opal/sprockets/source_map_header_patch.rb
opal-sprockets-0.4.0.0.11.0.rc1.3.1.beta2 lib/opal/sprockets/source_map_header_patch.rb
opal-0.10.3 lib/opal/sprockets/source_map_header_patch.rb
opal-sprockets-0.4.0.0.11.dev.3.1.beta1 lib/opal/sprockets/source_map_header_patch.rb
opal-0.10.2 lib/opal/sprockets/source_map_header_patch.rb
opal-0.10.1 lib/opal/sprockets/source_map_header_patch.rb
opal-0.10.0 lib/opal/sprockets/source_map_header_patch.rb
opal-0.10.0.rc2 lib/opal/sprockets/source_map_header_patch.rb
opal-0.9.4 lib/opal/sprockets/source_map_header_patch.rb
opal-0.9.3 lib/opal/sprockets/source_map_header_patch.rb
opal-0.10.0.rc1 lib/opal/sprockets/source_map_header_patch.rb
opal-0.10.0.beta5 lib/opal/sprockets/source_map_header_patch.rb
opal-0.10.0.beta4 lib/opal/sprockets/source_map_header_patch.rb