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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b902dbb2b3ca06974db14a817c930c9af0a4e2dbd951a6095fe5f7ce1596ac12
4
- data.tar.gz: 5a74b6a9939adbe53b6eec1a16a074dfffb1e3a301bc00f13f17afa3cd469dd1
3
+ metadata.gz: a63c607b947a35a265392779b333a367e119d574130f8b7f0b1f745df9535554
4
+ data.tar.gz: 48187a28c02aff8e0aa0877484fe39ea6f4bfbf577b6f38581922d9a433ef24a
5
5
  SHA512:
6
- metadata.gz: b7d301e9466a914a77a4112ef0cdeea7faa8a69e857c184e860b750cd26d4866347224e0fe7bde54d1f83b3b7fa2835c6607c263c505a7902d85391b91830f32
7
- data.tar.gz: 2ced43adb83173dc656801e3e8d396ccd3375c53fcce3ccf7c992ca897ad890fa35b525f7ed80dfb929acae1522b5580909dc601aa09d5e760452a18654323f4
6
+ metadata.gz: c24f929a7f0d865307a15007e7a250506e4e7876c4e76c4711a8651ab99b497f6b81b173ba86e10308bb637d8a6f24985d5ed1cddee548f565beec6dc06749df
7
+ data.tar.gz: 6da026a319d05b614c0ea0f346f1c62df9fcc65dd265eb6e23df7c7965c619e0e798afd63d3fe3d4679abe75ce87bbc071e71dce6a34064a7ac7758e0090bd7b
data/Gemfile CHANGED
@@ -1 +1,3 @@
1
1
  source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,3 +1,8 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rails_critical_css (0.3.3)
5
+
1
6
  GEM
2
7
  remote: https://rubygems.org/
3
8
  specs:
@@ -6,6 +11,7 @@ PLATFORMS
6
11
  x86_64-linux
7
12
 
8
13
  DEPENDENCIES
14
+ rails_critical_css!
9
15
 
10
16
  BUNDLED WITH
11
17
  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,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module CriticalCssGenerator
3
+ module RailsCriticalCss
4
4
  class Extractor
5
- include CriticalCssGenerator::Actions::Helpers
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/critical_css_generator/js/css-extractor.js',
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 = ::CriticalCssGenerator::Config.as_json_config({
40
+ config = ::RailsCriticalCss::Config.as_json_config({
41
41
  url: "file://#{html_path}",
42
42
  css: css_path,
43
43
  })
@@ -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.3'
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.1.1'
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.1.1
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/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)