Class: AutoprefixerRails::Sprockets

Inherits:
Object
  • Object
show all
Defined in:
lib/autoprefixer-rails/sprockets.rb

Overview

Register autoprefixer postprocessor in Sprockets and fix common issues

Instance Method Summary collapse

Constructor Details

#initialize(processor) ⇒ Sprockets

Returns a new instance of Sprockets.



6
7
8
# File 'lib/autoprefixer-rails/sprockets.rb', line 6

def initialize(processor)
  @processor = processor
end

Instance Method Details

#install(assets, opts = {}) ⇒ Object

Register postprocessor in Sprockets depend on issues with other gems



24
25
26
27
28
# File 'lib/autoprefixer-rails/sprockets.rb', line 24

def install(assets, opts = {})
  assets.register_postprocessor('text/css', :autoprefixer) do |context, css|
    process(context, css, opts)
  end
end

#process(context, css, opts) ⇒ Object

Add prefixes for ‘css`



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/autoprefixer-rails/sprockets.rb', line 11

def process(context, css, opts)
  input  = context.pathname.to_s
  output = input.chomp(File.extname(input)) + '.css'
  result = @processor.process(css, opts.merge(from: input, to: output))

  result.warnings.each do |warning|
    $stderr.puts "autoprefixer: #{ warning }"
  end

  result.css
end