Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions lib/autoprefixer-rails/sprockets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,34 @@ def self.register_processor(processor)

# Sprockets 3 and 4 API
def self.call(input)
filename = input[:filename]
source = input[:data]
run(filename, source)
filename = input[:filename]
source = input[:data]
previous_map = input[:metadata] && input[:metadata][:map]

output = filename.chomp(File.extname(filename)) + ".css"
map_param = previous_map ? {
inline: false, # do not generate inline source map
prev: false, # omit previous source map if embedded in source css
annotation: false, # do not append source map comment to css
sourcesContent: false,
} : nil
result = @processor.process(source, from: filename, to: output, map: map_param)

result.warnings.each do |warning|
warn "autoprefixer: #{warning}"
end

css = result.css
map = result.map && JSON.parse(result.map)
if previous_map && map
# map = ::Sprockets::SourceMapUtils.format_source_map(map, input)
map = ::Sprockets::SourceMapUtils.combine_source_maps previous_map, map
end

{
data: css,
map: map || previous_map,
}
end

# Add prefixes to `css`
Expand Down