Module: Locomotive::Steam::YUICompressorErrors

Defined in:
lib/locomotive/steam/initializers/sprockets.rb

Instance Method Summary collapse

Instance Method Details

#_compress(command, tempfile) ⇒ Object

:nocov:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/locomotive/steam/initializers/sprockets.rb', line 43

def _compress(command, tempfile)
  begin
    # FIXME: catch only useful information from the stderr output
    # output, errors, exit_status = '', [], nil
    output, errors, exit_status = Open3.capture3(command)
    errors = errors.split("\n").find_all { |l| l =~ /\s+[0-9]/ }
    [output, errors, exit_status]
  rescue Exception => e
    # windows shells tend to blow up here when the command fails
    raise RuntimeError, "compression failed: %s" % e.message
  ensure
    tempfile.close!
  end
end

#compress(stream_or_string) ⇒ Object

:nocov:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/locomotive/steam/initializers/sprockets.rb', line 24

def compress(stream_or_string)
  streamify(stream_or_string) do |stream|
    tempfile      = new_tempfile(stream)
    full_command  = "%s %s" % [command, tempfile.path]

    output, errors, exit_status = _compress(full_command, tempfile)

    if exit_status.exitstatus.zero?
      output
    else
      # Bourne shells tend to blow up here when the command fails, usually
      # because java is missing
      raise YUICompressorRuntimeError.new("Command '%s' returned non-zero exit status" %
        full_command, errors)
    end
  end
end

#new_tempfile(stream) ⇒ Object

:nocov:



59
60
61
62
63
64
# File 'lib/locomotive/steam/initializers/sprockets.rb', line 59

def new_tempfile(stream)
  Tempfile.new('yui_compress').tap do |tempfile|
    tempfile.write stream.read
    tempfile.flush
  end
end