4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/css_compressor.rb', line 4
def compress(source)
res = source
begin
file_in = Tempfile.new
file_in.write(source)
file_in.flush
file_in.fsync
file_in.close
res = `yarn run cleancss #{file_in.path}`
puts 'cleancss returned nothing' if res.blank?
rescue StandardError => e
puts "Exception while processing css #{e}"
ErrorReporting.error(e, 'Exception while compressing css')
ensure
file_in.flush
file_in.fsync
file_in.close
file_in.unlink
end
res
end
|