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



20
21
22
23
24
# File 'lib/autoprefixer-rails/sprockets.rb', line 20

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
# File 'lib/autoprefixer-rails/sprockets.rb', line 11

def process(context, css, opts)
  root   = Pathname.new(context.root_path)
  input  = context.pathname.relative_path_from(root).to_s
  output = input.chomp(File.extname(input)) + '.css'

  @processor.process(css, opts.merge(from: input, to: output)).css
end