rails_critical_css 0.1.1 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +6 -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 +4 -4
- 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: a63c607b947a35a265392779b333a367e119d574130f8b7f0b1f745df9535554
|
4
|
+
data.tar.gz: 48187a28c02aff8e0aa0877484fe39ea6f4bfbf577b6f38581922d9a433ef24a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c24f929a7f0d865307a15007e7a250506e4e7876c4e76c4711a8651ab99b497f6b81b173ba86e10308bb637d8a6f24985d5ed1cddee548f565beec6dc06749df
|
7
|
+
data.tar.gz: 6da026a319d05b614c0ea0f346f1c62df9fcc65dd265eb6e23df7c7965c619e0e798afd63d3fe3d4679abe75ce87bbc071e71dce6a34064a7ac7758e0090bd7b
|
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,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module RailsCriticalCss
|
4
4
|
class Extractor
|
5
|
-
include
|
5
|
+
include RailsCriticalCss::Actions::Helpers
|
6
6
|
|
7
7
|
def initialize(options)
|
8
8
|
@html, @css = options.values_at(:html, :css)
|
@@ -14,7 +14,7 @@ module CriticalCssGenerator
|
|
14
14
|
return nil unless tmp_html_file.present? && tmp_css_file.present?
|
15
15
|
|
16
16
|
stdout, stderr = Open3.capture2e(
|
17
|
-
'node lib/
|
17
|
+
'node lib/rails_critical_css/js/css-extractor.js',
|
18
18
|
stdin_data: Extractor.extractor_process_input(
|
19
19
|
html_path: tmp_html_file.path,
|
20
20
|
css_path: tmp_css_file.path,
|
@@ -37,7 +37,7 @@ module CriticalCssGenerator
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def self.extractor_process_input(html_path:, css_path:)
|
40
|
-
config = ::
|
40
|
+
config = ::RailsCriticalCss::Config.as_json_config({
|
41
41
|
url: "file://#{html_path}",
|
42
42
|
css: css_path,
|
43
43
|
})
|
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.3
|
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)
|