Sha256: 0968fce4281527ecd7558ea7350be7e74a1652bd8a9bc49774e7e3cdaace20ac

Contents?: true

Size: 1.56 KB

Versions: 27

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true
module Sprockets
  module Preprocessors
    # Private: Adds a default map to assets when one is not present
    #
    # If the input file already has a source map, it effectively returns the original
    # result. Otherwise it maps 1 for 1 lines original to generated. This is needed
    # Because other generators run after might depend on having a valid source map
    # available.
    class DefaultSourceMap
      def call(input)
        result        = { data: input[:data] }
        map           = input[:metadata][:map]
        filename      = input[:filename]
        load_path     = input[:load_path]
        lines         = input[:data].lines.length
        basename      = File.basename(filename)
        mime_exts     = input[:environment].config[:mime_exts]
        pipeline_exts = input[:environment].config[:pipeline_exts]
        if map.nil? || map.empty?
          result[:map] = {
            "version"   => 3,
            "file"      => PathUtils.split_subpath(load_path, filename),
            "mappings"  => default_mappings(lines),
            "sources"   => [PathUtils.set_pipeline(basename, mime_exts, pipeline_exts, :source)],
            "names"     => []
          }
        else
          result[:map] = map
        end

        result[:map]["x_sprockets_linecount"] = lines
        return result
      end

      private

      def default_mappings(lines)
        if (lines == 0)
          ""
        elsif (lines == 1)
          "AAAA"
        else
          "AAAA;" + "AACA;"*(lines - 2) + "AACA"
        end
      end
    end
  end
end

Version data entries

27 entries across 26 versions & 10 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/sprockets-4.2.1/lib/sprockets/preprocessors/default_source_map.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/sprockets-4.2.1/lib/sprockets/preprocessors/default_source_map.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/sprockets-4.2.1/lib/sprockets/preprocessors/default_source_map.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/sprockets-4.2.1/lib/sprockets/preprocessors/default_source_map.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/sprockets-4.1.1/lib/sprockets/preprocessors/default_source_map.rb
sprockets-4.2.1 lib/sprockets/preprocessors/default_source_map.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/sprockets-4.1.1/lib/sprockets/preprocessors/default_source_map.rb
sprockets-4.2.0 lib/sprockets/preprocessors/default_source_map.rb
sprockets-4.1.1 lib/sprockets/preprocessors/default_source_map.rb
sprockets-4.1.0 lib/sprockets/preprocessors/default_source_map.rb
sprockets-4.0.3 lib/sprockets/preprocessors/default_source_map.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/preprocessors/default_source_map.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/preprocessors/default_source_map.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/preprocessors/default_source_map.rb
sprockets-4.0.2 lib/sprockets/preprocessors/default_source_map.rb
sprockets-4.0.1 lib/sprockets/preprocessors/default_source_map.rb
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/sprockets-4.0.0/lib/sprockets/preprocessors/default_source_map.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/sprockets-4.0.0/lib/sprockets/preprocessors/default_source_map.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/preprocessors/default_source_map.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/preprocessors/default_source_map.rb