use the sass and uglifier gems to minify assets

did committed Feb 10, 2017
commit 6d64a42c35bfe208abe225d0ea0bd4c7ea7d75dd
Showing 4 changed files with 33 additions and 103 deletions
Gemfile.lock +16 -13
@@ @@ -3,7 +3,7 @@ PATH
specs:
locomotivecms_steam (1.3.0)
RedCloth (~> 4.3.2)
- autoprefixer-rails (~> 6.3.3.1)
+ autoprefixer-rails (~> 6.7.2)
bcrypt (~> 3.1.11)
chronic (~> 0.10.2)
coffee-script (~> 2.4.1)
@@ @@ -24,8 +24,9 @@ PATH
rack-rewrite (~> 1.5.1)
rack_csrf (~> 2.5.0)
sanitize (~> 4.0.1)
- sass (~> 3.4.21)
- sprockets (~> 3.5.2)
+ sass (~> 3.4.23)
+ sprockets (~> 3.7.1)
+ uglifier (~> 3.0.4)
GEM
remote: https://rubygems.org/
@@ @@ -40,7 +41,7 @@ GEM
addressable (2.5.0)
public_suffix (~> 2.0, >= 2.0.2)
attr_extras (4.4.0)
- autoprefixer-rails (6.3.3.1)
+ autoprefixer-rails (6.7.2)
execjs
bcrypt (3.1.11)
bson (4.1.1)
@@ @@ -53,7 +54,7 @@ GEM
coffee-script (2.4.1)
coffee-script-source
execjs
- coffee-script-source (1.11.1)
+ coffee-script-source (1.12.2)
colorize (0.8.1)
compass (1.0.3)
chunky_png (~> 1.2)
@@ @@ -67,7 +68,7 @@ GEM
sass (>= 3.3.0, < 3.5)
compass-import-once (1.0.5)
sass (>= 3.2, < 3.5)
- concurrent-ruby (1.0.2)
+ concurrent-ruby (1.0.4)
coveralls (0.8.15)
json (>= 1.8, < 3)
simplecov (~> 0.12.0)
@@ @@ -83,7 +84,7 @@ GEM
rack (>= 1.3.0)
duktape (1.3.0.6)
execjs (2.7.0)
- ffi (1.9.14)
+ ffi (1.9.17)
flamegraph (0.9.5)
haml (4.0.7)
tilt
@@ @@ -116,12 +117,12 @@ GEM
mimetype-fu (0.1.2)
mini_portile2 (2.1.0)
minitest (5.10.1)
- moneta (0.8.0)
+ moneta (0.8.1)
mongo (2.2.7)
bson (~> 4.0)
morphine (0.1.1)
multi_json (1.12.1)
- multi_xml (0.5.5)
+ multi_xml (0.6.0)
nokogiri (1.6.8.1)
mini_portile2 (~> 2.1.0)
nokogumbo (1.4.10)
@@ @@ -136,7 +137,7 @@ GEM
pry-byebug (3.3.0)
byebug (~> 8.0)
pry (~> 0.10)
- public_suffix (2.0.4)
+ public_suffix (2.0.5)
puma (3.6.0)
rack (2.0.1)
rack-cache (1.6.1)
@@ @@ -150,7 +151,7 @@ GEM
rack (>= 1.1.0)
rake (10.4.2)
rb-fsevent (0.9.8)
- rb-inotify (0.9.7)
+ rb-inotify (0.9.8)
ffi (>= 0.5.0)
rspec (3.4.0)
rspec-core (~> 3.4.0)
@@ @@ -169,14 +170,14 @@ GEM
crass (~> 1.0.2)
nokogiri (>= 1.4.4)
nokogumbo (~> 1.4.1)
- sass (3.4.22)
+ sass (3.4.23)
simplecov (0.12.0)
docile (~> 1.1.0)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
slop (3.6.0)
- sprockets (3.5.2)
+ sprockets (3.7.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
stackprof (0.2.9)
@@ @@ -190,6 +191,8 @@ GEM
tins (1.12.0)
tzinfo (1.2.2)
thread_safe (~> 0.1)
+ uglifier (3.0.4)
+ execjs (>= 0.3.0, < 3)
yui-compressor (0.12.0)
PLATFORMS
locomotive/steam/initializers/sprockets.rb b/lib/locomotive/steam/initializers/sprockets.rb +6 -80
@@ @@ -2,69 +2,13 @@ require 'sprockets'
require 'sass'
require 'coffee_script'
require 'compass'
+ require 'uglifier'
require 'autoprefixer-rails'
- require 'open3'
require 'execjs'
module Locomotive::Steam
- class YUICompressorRuntimeError < RuntimeError
- attr_reader :errors
- #:nocov:
- def initialize(msg, errors)
- super(msg)
- @errors = errors
- end
- end
-
- module YUICompressorErrors
-
- #:nocov:
- 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
-
- #:nocov:
- 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
-
- #:nocov:
- def new_tempfile(stream)
- Tempfile.new('yui_compress').tap do |tempfile|
- tempfile.write stream.read
- tempfile.flush
- end
- end
-
- end
-
class SprocketsEnvironment < ::Sprockets::Environment
attr_reader :steam_path
@@ @@ -76,7 +20,7 @@ module Locomotive::Steam
append_steam_paths
- install_yui_compressor(options)
+ install_minifiers if options[:minify]
install_autoprefixer
@@ @@ -97,24 +41,10 @@ module Locomotive::Steam
Compass::Frameworks::ALL.each { |f| append_path(f.stylesheets_directory) }
end
- def install_yui_compressor(options)
- return unless options[:minify]
-
- if is_java_installed?
- require 'yui/compressor'
-
- [YUI::JavaScriptCompressor, YUI::CssCompressor].each do |klass|
- klass.send(:include, YUICompressorErrors)
- end
-
- # minify javascripts and stylesheets
- self.js_compressor = YUI::JavaScriptCompressor.new
- self.css_compressor = YUI::CssCompressor.new
- else
- message = "[Important] YUICompressor requires java to be installed. The JAVA_HOME variable should also be set.\n"
- Locomotive::Common::Logger.warn message.red
- false
- end
+ def install_minifiers
+ # minify javascripts and stylesheets
+ self.js_compressor = :uglify
+ self.css_compressor = :scss
end
def install_autoprefixer
@@ @@ -134,10 +64,6 @@ module Locomotive::Steam
end
end
- def is_java_installed?
- `which java` != '' && (!ENV['JAVA_HOME'].blank? && File.exists?(ENV['JAVA_HOME']))
- end
-
end
end
locomotivecms_steam.gemspec +4 -3
@@ @@ -34,11 +34,12 @@ Gem::Specification.new do |spec|
spec.add_dependency 'moneta', '~> 0.8.0'
spec.add_dependency 'rack_csrf', '~> 2.5.0'
- spec.add_dependency 'sprockets', '~> 3.5.2'
- spec.add_dependency 'sass', '~> 3.4.21'
+ spec.add_dependency 'sprockets', '~> 3.7.1'
+ spec.add_dependency 'sass', '~> 3.4.23'
+ spec.add_dependency 'uglifier', '~> 3.0.4'
spec.add_dependency 'coffee-script', '~> 2.4.1'
spec.add_dependency 'compass', '~> 1.0.3'
- spec.add_dependency 'autoprefixer-rails', '~> 6.3.3.1'
+ spec.add_dependency 'autoprefixer-rails', '~> 6.7.2'
spec.add_dependency 'kramdown', '~> 1.10.0'
spec.add_dependency 'RedCloth', '~> 4.3.2'
spec/unit/initializers/sprockets_spec.rb +7 -7
@@ @@ -8,19 +8,19 @@ describe Locomotive::Steam::SprocketsEnvironment do
let(:options) { { minify: true } }
let(:env) { described_class.new(root, options) }
- describe '#install_yui_compressor' do
+ # describe '#install_yui_compressor' do
- context 'java not installed' do
+ # context 'java not installed' do
- before { allow(env).to receive(:is_java_installed?).and_return(false) }
+ # before { allow(env).to receive(:is_java_installed?).and_return(false) }
- subject { env.send(:install_yui_compressor, options) }
+ # subject { env.send(:install_yui_compressor, options) }
- it { is_expected.to eq(false) }
+ # it { is_expected.to eq(false) }
- end
+ # end
- end
+ # end
describe '#install_autoprefixer' do