Sha256: cf82d2d011d0b5d145603287ad6f6ee428ea50705cf8ac593980c44dca578083

Contents?: true

Size: 844 Bytes

Versions: 2

Compression:

Stored size: 844 Bytes

Contents

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]
        if map.nil? || map.empty?
          result[:map] ||= []
          input[:data].each_line.with_index do |_, index|
            line = index + 1
            result[:map] << { source: input[:source_path], generated: [line , 0], original: [line, 0] }
          end
        end
        return result
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sprockets-4.0.0.beta2 lib/sprockets/preprocessors/default_source_map.rb
sprockets-4.0.0.beta1 lib/sprockets/preprocessors/default_source_map.rb