Sha256: c91fcea9d3b709e661e3c51220277734599ef8139885bb9cced2aaec42f1288c

Contents?: true

Size: 1.55 KB

Versions: 2

Compression:

Stored size: 1.55 KB

Contents

require 'csso/version'

module Csso
  autoload :JsLib,      'csso/js_lib'
  autoload :Compressor, 'csso/compressor'

  def self.js_api
    @csso ||= Csso::JsLib.new
  end

  def self.install(sprockets)
    unless sprockets
      raise "no compatible sprockets found" unless Sprockets.respond_to? :register_compressor
      Sprockets.register_compressor('text/css', :csso, Compressor)
      return
    end
    if sprockets.respond_to? :register_compressor
      sprockets.register_compressor('text/css', :csso, Compressor)
      sprockets.css_compressor = :csso
    else
      Sprockets::Compressors.register_css_compressor(:csso, 'Csso::Compressor', :default => true)
    end
  end

  def self.optimize(css, maniac_mode=false, structural_optimization=true)
    if maniac_mode
      maniac_mode = 4 unless maniac_mode.is_a?(Integer) && maniac_mode > 0
      begin
        prev_css = css
        css = Optimizer.new.optimize(css, structural_optimization)
        maniac_mode -= 1
      end while maniac_mode > 0 && prev_css != css
      css
    else
      Optimizer.new.optimize(css, structural_optimization)
    end
  end

  def self.optimize_with_sourcemap css, filename, structural_optimization=true
    return nil unless css.is_a?(String)
    return css if css.size <= 3
    Csso.js_api.compress_with_sourcemap(css, filename, structural_optimization)
  end


  class Optimizer
    def optimize(css, structural_optimization=true)
      return nil unless css.is_a?(String)
      return css if css.size <= 3
      Csso.js_api.compress(css, structural_optimization)
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
csso-rails-0.8.0 lib/csso.rb
csso-rails-0.7.1 lib/csso.rb