Module: Csso

Defined in:
lib/csso.rb,
lib/csso/cli.rb,
lib/csso/js_lib.rb,
lib/csso/railtie.rb,
lib/csso/version.rb,
lib/csso/compressor.rb

Overview

base interface

Defined Under Namespace

Modules: CLI Classes: Compressor, JsLib, Optimizer, Railtie

Constant Summary collapse

VERSION =
'1.0.0'
CSSO_JS_LIB =
'vendor/csso/csso.js'

Class Method Summary collapse

Class Method Details

.install(sprockets) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/csso.rb', line 14

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::Legacy', :default => true)
    sprockets.css_compressor = Csso::Compressor::Legacy
  end
end

.js_apiObject



10
11
12
# File 'lib/csso.rb', line 10

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

.optimize(css, maniac_mode = false, structural_optimization = true) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/csso.rb', line 30

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
    loop do
      prev_css = css
      css = Csso.js_api.compress(css, structural_optimization)
      maniac_mode -= 1
      break if maniac_mode <= 0 || prev_css == css
    end
    css
  else
    Csso.js_api.compress(css, structural_optimization)
  end
end

.optimize_with_sourcemap(css, filename, structural_optimization = true) ⇒ Object



45
46
47
48
49
50
# File 'lib/csso.rb', line 45

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