-
-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathsprockets.rb
64 lines (54 loc) · 1.73 KB
/
sprockets.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# frozen_string_literal: true
require "pathname"
module AutoprefixerRails
# Register autoprefixer postprocessor in Sprockets and fix common issues
class Sprockets
def self.register_processor(processor)
@processor = processor
end
# Sprockets 3 and 4 API
def self.call(input)
filename = input[:filename]
source = input[:data]
run(filename, source)
end
# Add prefixes to `css`
def self.run(filename, css)
output = filename.chomp(File.extname(filename)) + ".css"
result = @processor.process(css, from: filename, to: output)
result.warnings.each do |warning|
warn "autoprefixer: #{warning}"
end
result.css
end
# Register postprocessor in Sprockets depend on issues with other gems
def self.install(env)
if ::Sprockets::VERSION.to_f < 4
env.register_postprocessor("text/css",
::AutoprefixerRails::Sprockets)
else
env.register_bundle_processor("text/css",
::AutoprefixerRails::Sprockets)
end
end
# Register postprocessor in Sprockets depend on issues with other gems
def self.uninstall(env)
if ::Sprockets::VERSION.to_f < 4
env.unregister_postprocessor("text/css",
::AutoprefixerRails::Sprockets)
else
env.unregister_bundle_processor("text/css",
::AutoprefixerRails::Sprockets)
end
end
# Sprockets 2 API new and render
def initialize(filename)
@filename = filename
@source = yield
end
# Sprockets 2 API new and render
def render(*)
self.class.run(@filename, @source)
end
end
end