rails_critical_css 0.3.5 → 0.3.9

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: 11feb85d447a9732e9a7b6d03ef4509a70cfdbdb719ed836587131832328ff07
4
- data.tar.gz: 8661b57610c41a134f4faf8348556c9675d951185d78a4a289f8b4bb7347d91a
3
+ metadata.gz: 1fce5ce61aaba300ef0817a1cf6f33d66f97be54a59d863aa2626363abcd0618
4
+ data.tar.gz: 605b23b501b0a1f5ef199b34fc4a6e736fd44f9b9aecb712c9e9bbcfd8d6e97a
5
5
  SHA512:
6
- metadata.gz: 5da5032045838a0443b19cabc1d95126ac8a3f8f5db0c28d17f766f4f3f978448be1514328b8bbcfc1827c0d288b6e7628133b398b9457f81c7b0be188285385
7
- data.tar.gz: 99f0a59695556344dd2948f99f774dd1745e698ca3bc72518bb6e2b428607caa56781e50cc696103099c5adbecae0fbf2239b23863bd6a77f1faa8825b60b13d
6
+ metadata.gz: a56bad87de70bbf0d7516a9335b5f6a736a8bdb333a9bc644a0c4b68c2ddd773e7eb51106b57b5a992f336255629f5dadd9621dfd43ab7b680d22e77ad5bd9d5
7
+ data.tar.gz: 190044c5b832af0b9ecf86e4528ab423694a6433bd4f7a9100369dd4941470c5887e0377b558236bc3874e0b5c189aaf75e378a275c00c491fbce4e66cca5539
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_critical_css (0.3.5)
4
+ rails_critical_css (0.3.9)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -5,10 +5,12 @@
5
5
  ![GitHub issues](https://img.shields.io/github/issues/mati365/rails-critical-css?style=flat-square)
6
6
  [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
7
7
 
8
- Generate on demand critical css for component actions with minimum effort. It is pretty similar to: https://github.com/mudbugmedia/critical-path-css-rails but instead of pregenerating critical css this gem generates them in fly and dynamically.
8
+ Generate on demand critical css for component actions with minimum effort. It is pretty similar to other rails critical css gems but instead of pregenerating critical css in job this gem generates them in fly, dynamically and allows to prepend custom SCSS files to generated critical bundle.
9
9
 
10
10
  ## Installation
11
11
 
12
+ Be sure that NPM and Node is installed in your system and add to Gemfile:
13
+
12
14
  ```bash
13
15
  gem 'rails_critical_css'
14
16
  ```
@@ -47,10 +49,26 @@ In controller:
47
49
  In template:
48
50
 
49
51
  ```slim
52
+ # These files will be prepended to critical css generator output, it can be normal scss file from assets
53
+ # critical_css_asset outputs nothing, it will be not appended to your html in link tag
50
54
  = critical_css_asset file: 'some-file-to-be-prepended-to-criticals', critical: true
55
+ = critical_css_asset file: 'hide-some-js-blocks', critical: true
56
+
57
+ # depending on critical_css? flag (it returns false if critical css is being generated)
58
+ # it emits link(href="your_file" rel="stylesheet") or link(href="your_file" rel="preload" onload="this.rel = 'stylesheet'")
59
+ = critical_css_link href: 'css/vendors.css'
60
+ = critical_css_link href: 'css/vendors.css', media: 'print'
61
+
62
+ # If you have custom link helper (which for example loads css tag after GDPR accept) you can use helper below
63
+ # Generator will extract hrefs from emitted html and generate stylesheet output
64
+ # if critical css is compiled successfully it will emit critical css
65
+ # and if preserve_content: true (which is default) arg is provided it will preserve provided content
51
66
  = critical_css_tags
52
- link rel="stylesheet" href="css/vendors.css" rel='stylesheet' type='text/css'
53
- link rel="stylesheet" href="css/app.css" rel='stylesheet' type='text/css'
67
+ = your_custom_link_helper "css/vendors.css"
68
+ = your_custom_link_helper "css/app.css"
69
+
70
+ - unless crticial_css?
71
+ div Critical css is being generated...
54
72
  ```
55
73
 
56
74
  ## Testing
data/lib/npm_commands.rb CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  class NpmCommands
4
4
  def install(*args)
5
- return false unless check_nodejs_installed
6
5
  STDERR.puts 'Installing npm dependencies...'
7
6
 
8
7
  install_status = Dir.chdir File.expand_path('..', File.dirname(__FILE__)) do
@@ -30,4 +30,14 @@ module RailsCriticalCss::Helpers
30
30
  content
31
31
  end
32
32
  end
33
+
34
+ def critical_css_link(href:, media: nil)
35
+ if critical_css?
36
+ link_to(href: href, rel: 'preload', as: 'style', media: media, onload: "this.rel = 'stylesheet'")
37
+ else
38
+ append_css_tags_assets(content) do
39
+ link_to(href: href, rel: 'stylesheet', media: media)
40
+ end
41
+ end
42
+ end
33
43
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsCriticalCss
4
- VERSION = '0.3.5'
4
+ VERSION = '0.3.9'
5
5
  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.3.5
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateusz Bagiński