Sha256: b1ac21d21041a271a7798cbd13e117528480fb86040cbfe5c52f0589e24b3c0f

Contents?: true

Size: 1.04 KB

Versions: 10

Compression:

Stored size: 1.04 KB

Contents

# CSSO complains when using node as an execJS runtime, but we currently have
# to due to a bug in therubyracer (or maybe execJS?)

require 'execjs'

module Csso
  class JsLib

    def initialize
      spec = Gem::Specification.find_by_name("csso-rails")
      path = spec.gem_dir

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

    def compress css, structural_optimization=true
      @csso.call("do_compression", css, !structural_optimization)
    end
  end


  # https://github.com/Vasfed/csso-rails/pull/23/files
  def self.install(sprockets)
    if sprockets.respond_to? :register_compressor
      compressor = Compressor.new
      sprockets.register_compressor('text/css', :csso, proc { |context, css|
        compressor.compress(css)
      })
      sprockets.css_compressor = :csso
    else
      Sprockets::Compressors.register_css_compressor(:csso, 'Csso::Compressor', default: true)
    end
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
volt-0.9.7.pre8 lib/volt/utils/csso_patch.rb
volt-0.9.7.pre7 lib/volt/utils/csso_patch.rb
volt-0.9.7.pre6 lib/volt/utils/csso_patch.rb
volt-0.9.7.pre5 lib/volt/utils/csso_patch.rb
volt-0.9.7.pre3 lib/volt/utils/csso_patch.rb
volt-0.9.7.pre2 lib/volt/utils/csso_patch.rb
volt-0.9.6 lib/volt/utils/csso_patch.rb
volt-0.9.6.pre3 lib/volt/utils/csso_patch.rb
volt-0.9.6.pre2 lib/volt/utils/csso_patch.rb
volt-0.9.6.pre1 lib/volt/utils/csso_patch.rb