assets-minify-rails 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/assets/minify/compressor.rb +5 -0
- data/lib/assets/minify/logger.rb +29 -0
- data/lib/assets/minify/version.rb +1 -1
- data/lib/assets-minify-rails.rb +1 -1
- data/lib/tasks/assets/minify/compress.rake +6 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c7cc84f9bcb346139a7a4e4e8b169b702e9e0d65a9c7c08ac6c6262692bd93a
|
4
|
+
data.tar.gz: 665fc7a34cd0ea06c6189155ee9ceb34fc18885f5c68b588f3ac0176edd9f80f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5705dec369e87a884bb3db149fc467dde074e2672458f038f72ba8f807edd07f2c25f09e878108363171e770bd546692e4a43644a048947355b75ebd4a9fe252
|
7
|
+
data.tar.gz: 905666225651b9f36f65a326463a2a6a83bcaa6e75f36778cfc805b66de807240b2c16928b8dfe3bc5d43c0295daa31b4fb3e4c18e71400d436b68deac97c073
|
@@ -1,7 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'mkmf'
|
2
3
|
|
3
4
|
module Assets::Minify
|
4
5
|
class Compressor
|
6
|
+
attr_accessor :config, :file_path
|
7
|
+
|
5
8
|
def initialize(file_path)
|
6
9
|
@config = ::Rails.application.config
|
7
10
|
@file_path = file_path
|
@@ -20,6 +23,8 @@ module Assets::Minify
|
|
20
23
|
case css_compressor
|
21
24
|
when :yui, :yui_compressor
|
22
25
|
::YUI::CssCompressor.new.compress(File.read(@file_path))
|
26
|
+
when :postcss
|
27
|
+
`npx postcss #{@file_path}`
|
23
28
|
end
|
24
29
|
end
|
25
30
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Assets::Minify
|
4
|
+
class Logger < StandardError
|
5
|
+
attr_accessor :file_path, :before_size, :after_size, :total_before_size, :total_after_size
|
6
|
+
mattr_accessor :logger, default: ::Logger.new(STDOUT)
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@total_after_size = 0
|
10
|
+
@total_before_size = 0
|
11
|
+
end
|
12
|
+
|
13
|
+
def start(file_path)
|
14
|
+
@file_path = file_path
|
15
|
+
@before_size = File.size(file_path)
|
16
|
+
@total_before_size += @before_size
|
17
|
+
end
|
18
|
+
|
19
|
+
def minified
|
20
|
+
@after_size = File.size(@file_path)
|
21
|
+
@total_after_size += @after_size
|
22
|
+
logger.info "Minify #{@file_path} #{@before_size} to #{@after_size} (#{@after_size > 0 ? 100 - @before_size / @after_size : '-'}%)"
|
23
|
+
end
|
24
|
+
|
25
|
+
def finished
|
26
|
+
logger.info "Total minify ratio #{@total_before_size} to #{@total_after_size} (#{@total_after_size > 0 ? 100 - (@total_before_size.to_f / @total_after_size).round(2) : '-'}%)"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/assets-minify-rails.rb
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
require_relative "assets/minify/version"
|
4
4
|
require_relative "assets/minify/errors"
|
5
|
+
require_relative "assets/minify/logger"
|
5
6
|
require_relative "assets/minify/compressor"
|
6
7
|
require_relative "assets/minify/output_path"
|
7
8
|
require_relative "assets/minify/railtie"
|
8
9
|
|
9
10
|
module Assets::Minify
|
10
|
-
mattr_accessor :logger, default: Logger.new(STDOUT)
|
11
11
|
end
|
@@ -7,20 +7,24 @@ namespace :assets_minify do
|
|
7
7
|
output_path = Assets::Minify::OutputPath.new(
|
8
8
|
::Rails.application.config.assets.output_path
|
9
9
|
)
|
10
|
+
logger = Assets::Minify::Logger.new
|
10
11
|
|
11
12
|
output_path.files.each do | file_path |
|
12
13
|
compressor = Assets::Minify::Compressor.new(file_path)
|
14
|
+
logger.start(file_path)
|
13
15
|
case file_path.to_s
|
14
16
|
when /\.js$/
|
15
17
|
next unless compressor.js_compressor
|
16
18
|
File.write(file_path, compressor.js_compress)
|
17
|
-
Assets::Minify.logger.info "Minify #{file_path}"
|
18
19
|
when /\.css$/
|
19
20
|
next unless compressor.css_compressor
|
20
21
|
File.write(file_path, compressor.css_compress)
|
21
|
-
|
22
|
+
else
|
23
|
+
next
|
22
24
|
end
|
25
|
+
logger.minified
|
23
26
|
end
|
27
|
+
logger.finished
|
24
28
|
end
|
25
29
|
end
|
26
30
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assets-minify-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yubele
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- lib/assets-minify-rails.rb
|
78
78
|
- lib/assets/minify/compressor.rb
|
79
79
|
- lib/assets/minify/errors.rb
|
80
|
+
- lib/assets/minify/logger.rb
|
80
81
|
- lib/assets/minify/output_path.rb
|
81
82
|
- lib/assets/minify/railtie.rb
|
82
83
|
- lib/assets/minify/version.rb
|