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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: feb62b27929733fec99af5554d08ae804025ed6375daed30d29f1dd5eafc6780
4
- data.tar.gz: 7e8d54687c2580ded02b522c91fd6112706cfeefc01e0ed9a025ab39971e4fdf
3
+ metadata.gz: 1e7e0ec19475e3c63ca1b45cd4aafb8a044ab6a0ad67b4fd70dc409f85d01f98
4
+ data.tar.gz: ab4d681805cb069fb8e0e0fff552b0f24a8dfcee747ccb1814767960bf4b0fe8
5
5
  SHA512:
6
- metadata.gz: 21e5e2ea8b9b820aa9866825fdbf48b2c6e0418ac2fd2451b58848f9912d24b9c549280b78b490b92a32e270bf7070bc23f2ad628c57aa6efa3e93625ab350ff
7
- data.tar.gz: 2dd47899c8f7a8ea462cde17b0537355f168f096cf2673dfa0a2532e539b26bae0e9f96148e5fafa29874af0f74f7d6062ff1c00627a58e1d0e4984a80aa3c73
6
+ metadata.gz: 2e2afc24d78261da1b0a307dac89e8a0571a2db5b6ae0195ac6e26c15f0ec5e77da8b70ee2d471f85a2f3e8111b67683aeaf9013fe41707af0fa305b760672d6
7
+ data.tar.gz: b9e006821e34c9156d368a876785fafe21fa66ded5974ad25f52b2be63e09b73360a5de35d15cb01d694733d5cafd34d1ae63dfa17ad177af09433be1aedd493
data/Gemfile CHANGED
@@ -1 +1,5 @@
1
1
  source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'open3'
data/Gemfile.lock CHANGED
@@ -1,11 +1,19 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rails_critical_css (0.3.4)
5
+
1
6
  GEM
2
7
  remote: https://rubygems.org/
3
8
  specs:
9
+ open3 (0.1.0)
4
10
 
5
11
  PLATFORMS
6
12
  x86_64-linux
7
13
 
8
14
  DEPENDENCIES
15
+ open3
16
+ rails_critical_css!
9
17
 
10
18
  BUNDLED WITH
11
19
  2.2.21
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
- CriticalCssGenerator.config do |c|
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
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module CriticalCssGenerator::Actions
3
+ module RailsCriticalCss::Actions
4
4
  class AfterRender
5
- include CriticalCssGenerator::Actions::Helpers
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
- CriticalCssGenerator::Jobs::Extractor.perform_if_semaphore_is_released(
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 CriticalCssGenerator::Actions
3
+ module RailsCriticalCss::Actions
4
4
  class BeforeRender
5
- include CriticalCssGenerator::Actions::Helpers
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,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module CriticalCssGenerator::Actions::Helpers
3
+ module RailsCriticalCss::Actions::Helpers
4
4
  def group_assets_by_type(assets)
5
5
  return [] unless assets.present?
6
6
 
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module CriticalCssGenerator::Actions
3
+ module RailsCriticalCss::Actions
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- include CriticalCssGenerator::Helpers
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 CriticalCssGenerator::Actions::BeforeRender.new(options), filter_options
54
- after_action CriticalCssGenerator::Actions::AfterRender.new(options), filter_options
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,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module CriticalCssGenerator
3
+ module RailsCriticalCss
4
4
  class Config
5
5
  class << self
6
6
  attr_writer :width, :height, :keep_larger_media_queries,
@@ -1,8 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module CriticalCssGenerator
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 CriticalCssGenerator::Actions::Helpers
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 = Open3.capture2e(
17
- 'node lib/critical_css_generator/js/css-extractor.js',
18
- stdin_data: Extractor.extractor_process_input(
19
- html_path: tmp_html_file.path,
20
- css_path: tmp_css_file.path,
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 = ::CriticalCssGenerator::Config.as_json_config({
47
+ config = ::RailsCriticalCss::Config.as_json_config({
41
48
  url: "file://#{html_path}",
42
49
  css: css_path,
43
50
  })
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module CriticalCssGenerator::Helpers
3
+ module RailsCriticalCss::Helpers
4
4
  def critical_css
5
5
  @critical_css_cache.try(:[], :css)
6
6
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module CriticalCssGenerator::Jobs
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 = ::CriticalCssGenerator::Extractor.new(css: css, html: html).try_extract
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,8 @@
1
+ # frozen_string_literal: true
2
+ require 'rails/railtie'
3
+
4
+ module RailsCriticalCss
5
+ class Railtie < Rails::Railtie
6
+ config.eager_load_namespaces << RailsCriticalCss
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsCriticalCss
4
+ VERSION = '0.3.4'
5
+ end
@@ -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)
@@ -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 = '0.2.0'
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 << 'lib'
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.2.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/critical_css_generator/critical_css_generator.rb
26
- - lib/critical_css_generator/critical_css_generator/actions.rb
27
- - lib/critical_css_generator/critical_css_generator/actions/after_render.rb
28
- - lib/critical_css_generator/critical_css_generator/actions/before_render.rb
29
- - lib/critical_css_generator/critical_css_generator/actions/helpers.rb
30
- - lib/critical_css_generator/critical_css_generator/config.rb
31
- - lib/critical_css_generator/critical_css_generator/extractor.rb
32
- - lib/critical_css_generator/critical_css_generator/helpers.rb
33
- - lib/critical_css_generator/critical_css_generator/jobs/extractor.rb
34
- - lib/critical_css_generator/js/css-extractor.js
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)