Module: Sprockets::Compressors

Defined in:
lib/sprockets/compressors.rb

Constant Summary collapse

@@css_compressors =
{}
@@js_compressors =
{}
@@default_css_compressor =
nil
@@default_js_compressor =
nil

Class Method Summary collapse

Class Method Details

.register_css_compressor(name, klass, options = {}) ⇒ Object


8
9
10
11
# File 'lib/sprockets/compressors.rb', line 8

def self.register_css_compressor(name, klass, options = {})
  @@default_css_compressor = name.to_sym if options[:default] || @@default_css_compressor.nil?
  @@css_compressors[name.to_sym] = {:klass => klass.to_s, :require => options[:require]}
end

.register_js_compressor(name, klass, options = {}) ⇒ Object


13
14
15
16
# File 'lib/sprockets/compressors.rb', line 13

def self.register_js_compressor(name, klass, options = {})
  @@default_js_compressor = name.to_sym if options[:default] || @@default_js_compressor.nil?
  @@js_compressors[name.to_sym] = {:klass => klass.to_s, :require => options[:require]}
end

.registered_css_compressor(name) ⇒ Object


18
19
20
21
22
23
24
25
26
# File 'lib/sprockets/compressors.rb', line 18

def self.registered_css_compressor(name)
  if name.respond_to?(:to_sym)
    compressor = @@css_compressors[name.to_sym] || @@css_compressors[@@default_css_compressor]
    require compressor[:require] if compressor[:require]
    compressor[:klass].constantize.new
  else
    name
  end
end

.registered_js_compressor(name) ⇒ Object


28
29
30
31
32
33
34
35
36
# File 'lib/sprockets/compressors.rb', line 28

def self.registered_js_compressor(name)
  if name.respond_to?(:to_sym)
    compressor = @@js_compressors[name.to_sym] || @@js_compressors[@@default_js_compressor]
    require compressor[:require] if compressor[:require]
    compressor[:klass].constantize.new
  else
    name
  end
end