csso-rails 0.8.2 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/ruby_csso +1 -0
- data/csso-rails.gemspec +29 -25
- data/lib/csso/cli.rb +16 -15
- data/lib/csso/compressor.rb +11 -7
- data/lib/csso/js_lib.rb +15 -11
- data/lib/csso/railtie.rb +8 -10
- data/lib/csso/version.rb +3 -1
- data/lib/csso-rails.rb +2 -0
- data/lib/csso.rb +16 -13
- data/vendor/csso/csso.js +2 -8
- metadata +13 -28
- data/lib/csso/csso.js.erb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6862690966e276e0608530646f9b634c2bd1a4d444a673128ff054211f58b7d
|
4
|
+
data.tar.gz: 989cd8260e016051e4e07e44cb85037337d479b993bf313782189e570678955d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4d7a0d8874889644bfb838e008dc101b916bbe5b29dda6f225a6c127a89968568357d537fa55224292fcfa96f937015360c51d79b70013d7a5c5997487e6382
|
7
|
+
data.tar.gz: c12bfcecf3aeda0964108ecdf8173d813281e8650819c86c5afb11d2d223be4ec31de04d60b45b9322ea97878c0a09b42f117f6c240007f1bb27e3fcb22952f7
|
data/bin/ruby_csso
CHANGED
data/csso-rails.gemspec
CHANGED
@@ -1,41 +1,45 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
4
|
+
require 'csso/version'
|
4
5
|
|
5
6
|
Gem::Specification.new do |s|
|
6
|
-
s.name =
|
7
|
+
s.name = 'csso-rails'
|
7
8
|
s.version = Csso::VERSION
|
8
9
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = [
|
10
|
-
s.email = [
|
11
|
-
s.homepage =
|
12
|
-
s.summary =
|
13
|
-
s.description =
|
10
|
+
s.authors = ['Vasily Fedoseyev']
|
11
|
+
s.email = ['vasilyfedoseyev@gmail.com']
|
12
|
+
s.homepage = 'https://github.com/Vasfed/csso-rails'
|
13
|
+
s.summary = 'CSS Stylesheet optimizer/compressor for Rails'
|
14
|
+
s.description = 'Invoke the CSSO from Ruby'
|
14
15
|
s.license = 'MIT'
|
15
16
|
|
16
|
-
s.rubyforge_project =
|
17
|
+
s.rubyforge_project = 'csso-rails'
|
17
18
|
|
18
|
-
s.files
|
19
|
+
s.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
20
|
f.match(Regexp.union(
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
%r{^gemfiles/},
|
22
|
+
%r{lib/csso/csso.js.erb},
|
23
|
+
%r{^spec/},
|
24
|
+
/^\./,
|
25
|
+
/^Appraisals/,
|
26
|
+
/^Gemfile/,
|
27
|
+
/^Rakefile/
|
28
|
+
))
|
27
29
|
end
|
28
|
-
s.files
|
30
|
+
s.files += [Csso::CSSO_JS_LIB]
|
29
31
|
|
30
32
|
s.bindir = 'bin'
|
31
|
-
s.executables = `git ls-files -z -- bin/*`.split("\x0").map
|
32
|
-
|
33
|
+
s.executables = `git ls-files -z -- bin/*`.split("\x0").map do |f|
|
34
|
+
File.basename(f)
|
35
|
+
end
|
36
|
+
s.require_paths = ['lib']
|
33
37
|
|
38
|
+
s.required_ruby_version = '>= 1.9.2' # rubocop:disable Gemspec/RequiredRubyVersion
|
34
39
|
s.add_dependency 'execjs', '>= 1'
|
35
40
|
|
36
|
-
s.add_development_dependency 'bundler', '~> 1.15'
|
37
|
-
s.add_development_dependency 'rake'
|
38
|
-
s.add_development_dependency 'minitest'
|
39
|
-
s.add_development_dependency 'mocha'
|
40
41
|
s.add_development_dependency 'appraisal'
|
42
|
+
s.add_development_dependency 'bundler'
|
43
|
+
s.add_development_dependency 'minitest', '>= 5.0'
|
44
|
+
s.add_development_dependency 'rake'
|
41
45
|
end
|
data/lib/csso/cli.rb
CHANGED
@@ -1,40 +1,41 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# encofing: utf-8
|
2
4
|
|
3
5
|
require 'optparse'
|
4
6
|
|
5
7
|
module Csso
|
8
|
+
# :nodoc
|
6
9
|
module CLI
|
7
|
-
def self.run!(argv=ARGV)
|
10
|
+
def self.run!(argv = ARGV)
|
8
11
|
maniac = false
|
9
|
-
opts = OptionParser.new do |opts|
|
12
|
+
opts = OptionParser.new do |opts| # rubocop:disable Lint/ShadowingOuterLocalVariable
|
10
13
|
opts.version = Csso::VERSION
|
11
14
|
opts.banner = "CSS Optimizer (ruby bindings by vasfed) version #{opts.version}"
|
12
|
-
opts.separator
|
13
|
-
opts.separator
|
15
|
+
opts.separator ''
|
16
|
+
opts.separator 'Usage:'
|
14
17
|
opts.separator " #{opts.program_name} [options] FILE [FILE2 [FILE3 [...]]"
|
15
18
|
opts.separator " #{opts.program_name} [options] < some_file.css"
|
16
|
-
opts.separator
|
17
|
-
opts.separator
|
18
|
-
opts.separator
|
19
|
+
opts.separator ''
|
20
|
+
opts.separator 'All input files are concatenated and fed to stdout after processing.'
|
21
|
+
opts.separator ''
|
19
22
|
|
20
|
-
opts.separator
|
21
|
-
opts.on(
|
23
|
+
opts.separator 'Options:'
|
24
|
+
opts.on('-m', '--[no-]maniac', '"Maniac mode" optimizes input multiple times until optimization stops to give any results.') do |v|
|
22
25
|
maniac = v
|
23
26
|
end
|
24
27
|
|
25
|
-
opts.on_tail(
|
28
|
+
opts.on_tail('-v', '--version', 'Print version information') do
|
26
29
|
return puts opts.ver
|
27
30
|
end
|
28
|
-
opts.on_tail(
|
31
|
+
opts.on_tail('-h', '--help', 'Show this message') do
|
29
32
|
return puts opts.help
|
30
33
|
end
|
31
34
|
end
|
32
35
|
|
33
36
|
opts.parse!(argv)
|
34
37
|
|
35
|
-
if $stdin.tty? && argv.empty?
|
36
|
-
return puts opts.help
|
37
|
-
end
|
38
|
+
return puts opts.help if $stdin.tty? && argv.empty?
|
38
39
|
|
39
40
|
ARGV.replace(argv)
|
40
41
|
css = ARGF.read
|
data/lib/csso/compressor.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Csso
|
4
|
+
# sprockets-compatible compressor
|
2
5
|
class Compressor
|
3
6
|
def self.call(input)
|
4
7
|
require 'csso'
|
5
|
-
#TODO: settings?
|
8
|
+
# TODO: settings?
|
6
9
|
if input[:metadata] && input[:metadata][:map]
|
7
|
-
css, map_json = Csso.optimize_with_sourcemap(
|
10
|
+
css, map_json = Csso.optimize_with_sourcemap(
|
11
|
+
input[:data],
|
8
12
|
# Sprockets::PathUtils.split_subpath(input[:load_path], input[:filename])
|
9
13
|
# sprockets seems to ignore filenames here, so we may save some mem:
|
10
14
|
'uri'
|
@@ -21,19 +25,19 @@ module Csso
|
|
21
25
|
|
22
26
|
# sprockets 2:
|
23
27
|
|
24
|
-
def initialize
|
28
|
+
def initialize(_path, &block)
|
25
29
|
@block = block
|
26
30
|
end
|
27
31
|
|
28
|
-
def render
|
29
|
-
self.class.call(
|
32
|
+
def render(_context, _opts = {})
|
33
|
+
self.class.call(data: @block.call)[:data]
|
30
34
|
end
|
31
35
|
|
36
|
+
# for old sprockets
|
32
37
|
class Legacy
|
33
|
-
def self.compress
|
38
|
+
def self.compress(data)
|
34
39
|
Compressor.call(data: data)[:data]
|
35
40
|
end
|
36
41
|
end
|
37
|
-
|
38
42
|
end
|
39
43
|
end
|
data/lib/csso/js_lib.rb
CHANGED
@@ -1,26 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'execjs'
|
2
4
|
|
3
5
|
module Csso
|
6
|
+
# low-level wrapper around the js lib
|
4
7
|
class JsLib
|
5
|
-
|
6
|
-
def initialize verbose=false
|
8
|
+
def initialize(verbose = false)
|
7
9
|
if verbose && ExecJS.runtime.is_a?(ExecJS::ExternalRuntime)
|
8
10
|
warn "You're using ExecJS::ExternalRuntime, did you forget to add therubyracer or other execjs runtime to gemfile?"
|
9
11
|
end
|
10
12
|
|
11
|
-
lib = File.read(File.expand_path(
|
12
|
-
unless @csso = ExecJS.runtime.compile(lib)
|
13
|
-
raise 'cannot compile or what?'
|
14
|
-
end
|
13
|
+
lib = File.read(File.expand_path("../../#{CSSO_JS_LIB}", File.dirname(__FILE__)))
|
14
|
+
raise 'cannot compile or what?' unless (@csso = ExecJS.runtime.compile(lib))
|
15
15
|
end
|
16
16
|
|
17
|
-
def compress
|
18
|
-
|
19
|
-
|
17
|
+
def compress(css, structural_optimization = true)
|
18
|
+
# TODO: raise ArgumentError, "expect css to be a String" unless css.is_a?(String)
|
19
|
+
return nil unless css.is_a?(String)
|
20
20
|
|
21
|
-
|
22
|
-
@csso.call("do_compression_with_map", css, filename, structural_optimization)
|
21
|
+
@csso.call('do_compression', css, structural_optimization)
|
23
22
|
end
|
24
23
|
|
24
|
+
def compress_with_sourcemap(css, filename, structural_optimization = true)
|
25
|
+
return nil unless css.is_a?(String)
|
26
|
+
|
27
|
+
@csso.call('do_compression_with_map', css, filename, structural_optimization)
|
28
|
+
end
|
25
29
|
end
|
26
30
|
end
|
data/lib/csso/railtie.rb
CHANGED
@@ -1,20 +1,18 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'action_controller/railtie'
|
4
4
|
|
5
|
+
module Csso
|
6
|
+
# hook into rails init
|
5
7
|
class Railtie < ::Rails::Railtie
|
6
|
-
initializer
|
7
|
-
#NB: app.assets may be nil, sprockets-rails creates env in after_initialize
|
8
|
+
initializer 'csso.environment', after: 'sprockets.environment' do |app|
|
9
|
+
# NB: app.assets may be nil, sprockets-rails creates env in after_initialize
|
8
10
|
Csso.install(app.assets)
|
9
11
|
end
|
10
12
|
|
11
13
|
# saas-rails-3.2.4(and may be others) sets itself as default, ignoring config? => override :(
|
12
|
-
initializer
|
13
|
-
if app.config.assets.enabled
|
14
|
-
app.config.assets.css_compressor = :csso
|
15
|
-
end
|
14
|
+
initializer 'csso.setup', after: :setup_compression, group: :all do |app|
|
15
|
+
app.config.assets.css_compressor = :csso if app.config.assets.enabled
|
16
16
|
end
|
17
|
-
|
18
17
|
end
|
19
|
-
|
20
18
|
end
|
data/lib/csso/version.rb
CHANGED
data/lib/csso-rails.rb
CHANGED
data/lib/csso.rb
CHANGED
@@ -1,16 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'csso/version'
|
2
4
|
|
5
|
+
# base interface
|
3
6
|
module Csso
|
4
7
|
autoload :JsLib, 'csso/js_lib'
|
5
8
|
autoload :Compressor, 'csso/compressor'
|
6
9
|
|
7
10
|
def self.js_api
|
8
|
-
@
|
11
|
+
@js_api ||= Csso::JsLib.new
|
9
12
|
end
|
10
13
|
|
11
14
|
def self.install(sprockets)
|
12
15
|
unless sprockets
|
13
|
-
raise
|
16
|
+
raise 'no compatible sprockets found' unless Sprockets.respond_to? :register_compressor
|
17
|
+
|
14
18
|
Sprockets.register_compressor('text/css', :csso, Compressor)
|
15
19
|
return
|
16
20
|
end
|
@@ -23,33 +27,32 @@ module Csso
|
|
23
27
|
end
|
24
28
|
end
|
25
29
|
|
26
|
-
def self.optimize(css, maniac_mode=false, structural_optimization=true)
|
30
|
+
def self.optimize(css, maniac_mode = false, structural_optimization = true)
|
27
31
|
if maniac_mode
|
28
32
|
maniac_mode = 4 unless maniac_mode.is_a?(Integer) && maniac_mode > 0
|
29
|
-
|
33
|
+
loop do
|
30
34
|
prev_css = css
|
31
|
-
css =
|
35
|
+
css = Csso.js_api.compress(css, structural_optimization)
|
32
36
|
maniac_mode -= 1
|
33
|
-
|
37
|
+
break if maniac_mode <= 0 || prev_css == css
|
38
|
+
end
|
34
39
|
css
|
35
40
|
else
|
36
|
-
|
41
|
+
Csso.js_api.compress(css, structural_optimization)
|
37
42
|
end
|
38
43
|
end
|
39
44
|
|
40
|
-
def self.optimize_with_sourcemap
|
45
|
+
def self.optimize_with_sourcemap(css, filename, structural_optimization = true)
|
41
46
|
return nil unless css.is_a?(String)
|
42
47
|
return css if css.size <= 3
|
48
|
+
|
43
49
|
Csso.js_api.compress_with_sourcemap(css, filename, structural_optimization)
|
44
50
|
end
|
45
51
|
|
46
|
-
|
52
|
+
# deprecated
|
47
53
|
class Optimizer
|
48
|
-
def optimize(css, structural_optimization=true)
|
49
|
-
return nil unless css.is_a?(String)
|
50
|
-
return css if css.size <= 3
|
54
|
+
def optimize(css, structural_optimization = true)
|
51
55
|
Csso.js_api.compress(css, structural_optimization)
|
52
56
|
end
|
53
57
|
end
|
54
|
-
|
55
58
|
end
|