Sha256: fb29fa0b59bdc651b1e6d3eedd5e3778a56bbed87935883f1f814770b564ed6b

Contents?: true

Size: 1.59 KB

Versions: 51

Compression:

Stored size: 1.59 KB

Contents

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

Version data entries

51 entries across 36 versions & 2 rubygems

Version Path
autoprefixer-rails-9.8.6 lib/autoprefixer-rails/sprockets.rb
autoprefixer-rails-9.8.5 lib/autoprefixer-rails/sprockets.rb
autoprefixer-rails-9.8.4 lib/autoprefixer-rails/sprockets.rb
autoprefixer-rails-9.8.3 lib/autoprefixer-rails/sprockets.rb
autoprefixer-rails-9.8.2 lib/autoprefixer-rails/sprockets.rb
autoprefixer-rails-9.8.1 lib/autoprefixer-rails/sprockets.rb
autoprefixer-rails-9.7.6 lib/autoprefixer-rails/sprockets.rb
autoprefixer-rails-9.7.5 lib/autoprefixer-rails/sprockets.rb
autoprefixer-rails-9.7.4 lib/autoprefixer-rails/sprockets.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/autoprefixer-rails-9.7.3/lib/autoprefixer-rails/sprockets.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/autoprefixer-rails-9.7.1/lib/autoprefixer-rails/sprockets.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/autoprefixer-rails-9.6.1/lib/autoprefixer-rails/sprockets.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/autoprefixer-rails-9.6.4/lib/autoprefixer-rails/sprockets.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/autoprefixer-rails-9.6.1.1/lib/autoprefixer-rails/sprockets.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/autoprefixer-rails-9.6.5/lib/autoprefixer-rails/sprockets.rb
autoprefixer-rails-9.7.3 lib/autoprefixer-rails/sprockets.rb
autoprefixer-rails-9.7.2 lib/autoprefixer-rails/sprockets.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/autoprefixer-rails-9.6.1.1/lib/autoprefixer-rails/sprockets.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/autoprefixer-rails-9.6.1/lib/autoprefixer-rails/sprockets.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/autoprefixer-rails-9.6.4/lib/autoprefixer-rails/sprockets.rb