6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/squash/javascript/patches.rb', line 6
def sourcemap
relative_path = if pathname.to_s.include?(Rails.root.to_s)
pathname.relative_path_from(Rails.root)
else
pathname
end.to_s
relative_path.gsub! /(?<=\.js)\..*$/, ''
resource_path = [Rails.application.config.assets.prefix, logical_path].join('/')
mappings = Array.new
to_s.lines.each_with_index do |_, index|
offset = SourceMap::Offset.new(index, 0)
mappings << SourceMap::Mapping.new(relative_path, offset, offset)
end
SourceMap::Map.new(mappings, resource_path)
end
|