rails_critical_css 0.2.0 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/Gemfile.lock +8 -0
- data/README.md +1 -1
- data/lib/{critical_css_generator/js → js}/css-extractor.js +0 -0
- data/lib/{critical_css_generator/critical_css_generator → rails_critical_css}/actions/after_render.rb +3 -3
- data/lib/{critical_css_generator/critical_css_generator → rails_critical_css}/actions/before_render.rb +2 -2
- data/lib/{critical_css_generator/critical_css_generator → rails_critical_css}/actions/helpers.rb +1 -1
- data/lib/{critical_css_generator/critical_css_generator → rails_critical_css}/actions.rb +4 -4
- data/lib/{critical_css_generator/critical_css_generator → rails_critical_css}/config.rb +1 -1
- data/lib/{critical_css_generator/critical_css_generator → rails_critical_css}/extractor.rb +16 -9
- data/lib/{critical_css_generator/critical_css_generator → rails_critical_css}/helpers.rb +1 -1
- data/lib/{critical_css_generator/critical_css_generator → rails_critical_css}/jobs/extractor.rb +2 -2
- data/lib/rails_critical_css/railtie.rb +8 -0
- data/lib/rails_critical_css/version.rb +5 -0
- data/lib/rails_critical_css.rb +21 -0
- data/rails_critical_css.gemspec +7 -2
- metadata +13 -12
- data/lib/critical_css_generator/critical_css_generator.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e7e0ec19475e3c63ca1b45cd4aafb8a044ab6a0ad67b4fd70dc409f85d01f98
|
4
|
+
data.tar.gz: ab4d681805cb069fb8e0e0fff552b0f24a8dfcee747ccb1814767960bf4b0fe8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e2afc24d78261da1b0a307dac89e8a0571a2db5b6ae0195ac6e26c15f0ec5e77da8b70ee2d471f85a2f3e8111b67683aeaf9013fe41707af0fa305b760672d6
|
7
|
+
data.tar.gz: b9e006821e34c9156d368a876785fafe21fa66ded5974ad25f52b2be63e09b73360a5de35d15cb01d694733d5cafd34d1ae63dfa17ad177af09433be1aedd493
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -20,7 +20,7 @@ Install `penthouse` NPM package in your project. Be sure that node_modules/ dire
|
|
20
20
|
In initializer:
|
21
21
|
|
22
22
|
```ruby
|
23
|
-
|
23
|
+
RailsCriticalCss.config do |c|
|
24
24
|
c.keep_larger_media_queries = true
|
25
25
|
c.height = 19999 # prevent CLS on for example footer
|
26
26
|
end
|
File without changes
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module RailsCriticalCss::Actions
|
4
4
|
class AfterRender
|
5
|
-
include
|
5
|
+
include RailsCriticalCss::Actions::Helpers
|
6
6
|
|
7
7
|
def initialize(filter_options)
|
8
8
|
@packed_options = filter_options.slice(
|
@@ -19,7 +19,7 @@ module CriticalCssGenerator::Actions
|
|
19
19
|
|
20
20
|
return if cache_path == false
|
21
21
|
|
22
|
-
|
22
|
+
RailsCriticalCss::Jobs::Extractor.perform_if_semaphore_is_released(
|
23
23
|
html: controller.full_html_response,
|
24
24
|
cache: {
|
25
25
|
path: cache_path,
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module RailsCriticalCss::Actions
|
4
4
|
class BeforeRender
|
5
|
-
include
|
5
|
+
include RailsCriticalCss::Actions::Helpers
|
6
6
|
|
7
7
|
def initialize(filter_options)
|
8
8
|
@packed_options = filter_options.slice(:css, :cache_key, :cache_prefix)
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module RailsCriticalCss::Actions
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
include
|
7
|
+
include RailsCriticalCss::Helpers
|
8
8
|
|
9
9
|
attr_accessor :lazy_css_blocks,
|
10
10
|
:critical_css_assets,
|
@@ -50,8 +50,8 @@ module CriticalCssGenerator::Actions
|
|
50
50
|
options[:cache_prefix] ||= 'critical-css'
|
51
51
|
|
52
52
|
filter_options = options.extract!(:if, :unless).merge(only: actions)
|
53
|
-
around_action
|
54
|
-
after_action
|
53
|
+
around_action RailsCriticalCss::Actions::BeforeRender.new(options), filter_options
|
54
|
+
after_action RailsCriticalCss::Actions::AfterRender.new(options), filter_options
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -1,8 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'open3'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module RailsCriticalCss
|
7
|
+
LIB_ROOT = File.expand_path(File.join('..'), File.dirname(__FILE__))
|
8
|
+
|
4
9
|
class Extractor
|
5
|
-
include
|
10
|
+
include RailsCriticalCss::Actions::Helpers
|
6
11
|
|
7
12
|
def initialize(options)
|
8
13
|
@html, @css = options.values_at(:html, :css)
|
@@ -13,13 +18,15 @@ module CriticalCssGenerator
|
|
13
18
|
tmp_css_file = tmp_concat_assets_array(@css[:assets], extension: 'css')
|
14
19
|
return nil unless tmp_html_file.present? && tmp_css_file.present?
|
15
20
|
|
16
|
-
stdout, stderr =
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
+
stdout, stderr = Dir.chdir(LIB_ROOT) do
|
22
|
+
Open3.capture2e(
|
23
|
+
'node js/css-extractor.js',
|
24
|
+
stdin_data: Extractor.extractor_process_input(
|
25
|
+
html_path: tmp_html_file.path,
|
26
|
+
css_path: tmp_css_file.path,
|
27
|
+
)
|
21
28
|
)
|
22
|
-
|
29
|
+
end
|
23
30
|
|
24
31
|
if stderr.try(:success?) && !stdout.try(:include?, 'UnhandledPromiseRejectionWarning')
|
25
32
|
[
|
@@ -37,7 +44,7 @@ module CriticalCssGenerator
|
|
37
44
|
end
|
38
45
|
|
39
46
|
def self.extractor_process_input(html_path:, css_path:)
|
40
|
-
config = ::
|
47
|
+
config = ::RailsCriticalCss::Config.as_json_config({
|
41
48
|
url: "file://#{html_path}",
|
42
49
|
css: css_path,
|
43
50
|
})
|
data/lib/{critical_css_generator/critical_css_generator → rails_critical_css}/jobs/extractor.rb
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module RailsCriticalCss::Jobs
|
4
4
|
class Extractor < ActiveJob::Base
|
5
5
|
class << self
|
6
6
|
def semaphore_key(cache_path)
|
@@ -18,7 +18,7 @@ module CriticalCssGenerator::Jobs
|
|
18
18
|
|
19
19
|
def perform(cache:, css:, html:)
|
20
20
|
semaphore = self.class.semaphore_key(cache[:path])
|
21
|
-
critical_css = ::
|
21
|
+
critical_css = ::RailsCriticalCss::Extractor.new(css: css, html: html).try_extract
|
22
22
|
|
23
23
|
# store it as wrapped css, do not regenerate for
|
24
24
|
# each request critical_css if something go wrong
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'open3'
|
4
|
+
require 'rails_critical_css/version'
|
5
|
+
require 'rails_critical_css/config'
|
6
|
+
require 'rails_critical_css/actions'
|
7
|
+
require 'rails_critical_css/actions/helpers'
|
8
|
+
require 'rails_critical_css/extractor'
|
9
|
+
require 'rails_critical_css/jobs/extractor'
|
10
|
+
require 'rails_critical_css/actions/after_render'
|
11
|
+
require 'rails_critical_css/actions/before_render'
|
12
|
+
require 'rails_critical_css/helpers'
|
13
|
+
|
14
|
+
module RailsCriticalCss
|
15
|
+
def self.config
|
16
|
+
yield RailsCriticalCss::Config
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
ActionController::Base.send(:include, RailsCriticalCss::Actions)
|
21
|
+
ActionView::Base.send(:include, RailsCriticalCss::Helpers)
|
data/rails_critical_css.gemspec
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'rails_critical_css/version'
|
5
|
+
|
1
6
|
Gem::Specification.new do |s|
|
2
7
|
s.name = 'rails_critical_css'
|
3
|
-
s.version =
|
8
|
+
s.version = RailsCriticalCss::VERSION
|
4
9
|
s.summary = 'Critical CSS rails generator'
|
5
10
|
s.authors = ['Mateusz Bagiński']
|
6
11
|
|
@@ -9,6 +14,6 @@ Gem::Specification.new do |s|
|
|
9
14
|
s.homepage = 'https://github.com/Mati365/rails-critical-css'
|
10
15
|
s.files = `git ls-files`.split($/)
|
11
16
|
|
12
|
-
s.require_paths
|
17
|
+
s.require_paths = ['lib']
|
13
18
|
s.required_ruby_version = '>= 2.4.0'
|
14
19
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_critical_css
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mateusz Bagiński
|
@@ -22,16 +22,18 @@ files:
|
|
22
22
|
- LICENSE
|
23
23
|
- README.md
|
24
24
|
- Rakefile
|
25
|
-
- lib/
|
26
|
-
- lib/
|
27
|
-
- lib/
|
28
|
-
- lib/
|
29
|
-
- lib/
|
30
|
-
- lib/
|
31
|
-
- lib/
|
32
|
-
- lib/
|
33
|
-
- lib/
|
34
|
-
- lib/
|
25
|
+
- lib/js/css-extractor.js
|
26
|
+
- lib/rails_critical_css.rb
|
27
|
+
- lib/rails_critical_css/actions.rb
|
28
|
+
- lib/rails_critical_css/actions/after_render.rb
|
29
|
+
- lib/rails_critical_css/actions/before_render.rb
|
30
|
+
- lib/rails_critical_css/actions/helpers.rb
|
31
|
+
- lib/rails_critical_css/config.rb
|
32
|
+
- lib/rails_critical_css/extractor.rb
|
33
|
+
- lib/rails_critical_css/helpers.rb
|
34
|
+
- lib/rails_critical_css/jobs/extractor.rb
|
35
|
+
- lib/rails_critical_css/railtie.rb
|
36
|
+
- lib/rails_critical_css/version.rb
|
35
37
|
- rails_critical_css.gemspec
|
36
38
|
homepage: https://github.com/Mati365/rails-critical-css
|
37
39
|
licenses:
|
@@ -41,7 +43,6 @@ post_install_message:
|
|
41
43
|
rdoc_options: []
|
42
44
|
require_paths:
|
43
45
|
- lib
|
44
|
-
- lib
|
45
46
|
required_ruby_version: !ruby/object:Gem::Requirement
|
46
47
|
requirements:
|
47
48
|
- - ">="
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'open3'
|
4
|
-
require 'critical_css_generator/config'
|
5
|
-
require 'critical_css_generator/actions'
|
6
|
-
require 'critical_css_generator/actions/helpers'
|
7
|
-
require 'critical_css_generator/extractor'
|
8
|
-
require 'critical_css_generator/jobs/extractor'
|
9
|
-
require 'critical_css_generator/actions/after_render'
|
10
|
-
require 'critical_css_generator/actions/before_render'
|
11
|
-
require 'critical_css_generator/helpers'
|
12
|
-
|
13
|
-
module CriticalCssGenerator
|
14
|
-
def self.config
|
15
|
-
yield CriticalCssGenerator::Config
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
ActionController::Base.send(:include, CriticalCssGenerator::Actions)
|
20
|
-
ActionView::Base.send(:include, CriticalCssGenerator::Helpers)
|