Sha256: 5221bb2da2842e26de35d793982a2aa08eaa48da7a34f8e83e3ba367e64b407d

Contents?: true

Size: 989 Bytes

Versions: 6

Compression:

Stored size: 989 Bytes

Contents

module Csso
  class Compressor
    def self.call(input)
      require 'csso'
      #TODO: settings?
      if input[:metadata] && input[:metadata][:map]
        css, map = 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'
        )
        map = Sprockets::SourceMapUtils.combine_source_maps(
          input[:metadata][:map],
          Sprockets::SourceMapUtils.decode_json_source_map(map)["mappings"]
        )
        { data: css, map: map }
      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

    class Legacy
      def self.compress data
        Compressor.call(data: data)[:data]
      end
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
csso-rails-0.8.1 lib/csso/compressor.rb
csso-rails-0.8.0 lib/csso/compressor.rb
csso-rails-0.7.1 lib/csso/compressor.rb
csso-rails-0.7.0 lib/csso/compressor.rb
csso-rails-0.6.0 lib/csso/compressor.rb
csso-rails-0.5.0 lib/csso/compressor.rb