Sha256: eb1b62f29347a04b0227551b6d26ffcc3f4a70546ca1452caa1cebdb72faba81

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module Csso
  # sprockets-compatible compressor
  class Compressor
    def self.call(input)
      require 'csso'
      # TODO: settings?
      if input[:metadata] && input[:metadata][:map]
        css, map_json = Csso.optimize_with_sourcemap(
          input[:data],
          # Sprockets::PathUtils.split_subpath(input[:load_path], input[:filename])
          # sprockets seems to ignore filenames here, so we may save some mem:
          'uri'
        )

        {
          data: css,
          map: Sprockets::SourceMapUtils.combine_source_maps(input[:metadata][:map], JSON.parse(map_json))
        }
      else
        { data: Csso.optimize(input[:data], true) }
      end
    end

    # sprockets 2:

    def initialize(_path, &block)
      @block = block
    end

    def render(_context, _opts = {})
      self.class.call(data: @block.call)[:data]
    end

    # for old sprockets
    class Legacy
      def self.compress(data)
        Compressor.call(data: data)[:data]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
csso-rails-1.0.0 lib/csso/compressor.rb
csso-rails-0.9.0 lib/csso/compressor.rb