Debian Codegraph @

lib/autoprefixer-rails/sprockets.rb

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