class CssMedia::Sprockets

Register cssmedia postprocessor in Sprockets and fix common issues

Public Class Methods

call(input) click to toggle source

Sprockets 3 and 4 API

# File lib/css_media/sprockets.rb, line 11
def self.call(input)
  filename  = input[:filename]
  source    = input[:data]
  run(filename, source)
end
install(env) click to toggle source

Register postprocessor in Sprockets depend on issues with other gems

# File lib/css_media/sprockets.rb, line 30
def self.install(env)
  if ::Sprockets::VERSION.to_f < 4
    env.register_postprocessor('text/css',
      ::CssMedia::Sprockets)
  else
    env.register_bundle_processor('text/css',
      ::CssMedia::Sprockets)
  end
end
new(filename, &block) click to toggle source

Sprockets 2 API new and render

# File lib/css_media/sprockets.rb, line 52
def initialize(filename, &block)
  @filename = filename
  @source   = block.call
end
register_processor(processor) click to toggle source
# File lib/css_media/sprockets.rb, line 6
def self.register_processor(processor)
  @processor = processor
end
run(filename, css) click to toggle source

Add prefixes to `css`

# File lib/css_media/sprockets.rb, line 18
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|
    $stderr.puts "css_media: #{ warning }"
  end

  result.css
end
uninstall(env) click to toggle source

Register postprocessor in Sprockets depend on issues with other gems

# File lib/css_media/sprockets.rb, line 41
def self.uninstall(env)
  if ::Sprockets::VERSION.to_f < 4
    env.unregister_postprocessor('text/css',
      ::CssMedia::Sprockets)
  else
    env.unregister_bundle_processor('text/css',
      ::CssMedia::Sprockets)
  end
end

Public Instance Methods

render(_, _) click to toggle source

Sprockets 2 API new and render

# File lib/css_media/sprockets.rb, line 58
def render(_, _)
  self.class.run(@filename, @source)
end