Class: Csso::JsLib

Inherits:
Object
  • Object
show all
Defined in:
lib/csso/js_lib.rb

Overview

low-level wrapper around the js lib

Instance Method Summary collapse

Constructor Details

#initialize(verbose = false) ⇒ JsLib

Returns a new instance of JsLib.



8
9
10
11
12
13
14
15
# File 'lib/csso/js_lib.rb', line 8

def initialize(verbose = false)
  if verbose && ExecJS.runtime.is_a?(ExecJS::ExternalRuntime)
    warn "You're using ExecJS::ExternalRuntime, did you forget to add therubyracer or other execjs runtime to gemfile?"
  end

  lib = File.read(File.expand_path("../../#{CSSO_JS_LIB}", File.dirname(__FILE__)))
  raise 'cannot compile or what?' unless (@csso = ExecJS.runtime.compile(lib))
end

Instance Method Details

#compress(css, structural_optimization = true) ⇒ Object



17
18
19
20
21
22
# File 'lib/csso/js_lib.rb', line 17

def compress(css, structural_optimization = true)
  # TODO: raise ArgumentError, "expect css to be a String" unless css.is_a?(String)
  return nil unless css.is_a?(String)

  @csso.call('do_compression', css, structural_optimization)
end

#compress_with_sourcemap(css, filename, structural_optimization = true) ⇒ Object



24
25
26
27
28
# File 'lib/csso/js_lib.rb', line 24

def compress_with_sourcemap(css, filename, structural_optimization = true)
  return nil unless css.is_a?(String)

  @csso.call('do_compression_with_map', css, filename, structural_optimization)
end