rails_critical_css 0.3.6 → 0.3.7

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: f20d51ee66a7c650a92c3ad6a4d56c8474fc94d449c2c1f44eb259ff480b6589
4
- data.tar.gz: ac28bdb40332507856685e68aaded39bda33dba53249a3ee7f19bd1498884714
3
+ metadata.gz: 77467407b3faaca39cea6db6b578d6cefa0635ccc221bb53087a9ac348840b62
4
+ data.tar.gz: f8e5c8caccdcefa8265d5756c2b9780aa11fd74bfc0557ae325583e4ad1eff09
5
5
  SHA512:
6
- metadata.gz: 29eb8ec3b9f7dceb2dee9e76d86405f2c46ae8cf89edab2d0c3d0bf0a97fdecffeeace70b20917e94884014c25875edc6e0cc590afdd54f2a7151783d8c890af
7
- data.tar.gz: f06af995be69c2608a661ad2e6d55fdebd3e5904c00a33f9e97f73717bf3f754b95af2acf885bc86e8fc48ad418c1c3e68d741521ecb2b4a6ae0816146aa6ff5
6
+ metadata.gz: b4c47e5b244785bdc403d2267fc198fc18040ee65cb38ea1ecebfe501b7a8d922d0706a93110d0a093a0cf6fe889be33c1b4b06d3a3edf17686620ce9bb07c26
7
+ data.tar.gz: 0a9f6cc4626c8c9bfcb3a091f0b30439bb826b35e35ca9544391b7b1c49eb4589460b6ecec7340cfe2f869caf76dc9efb8cfe6a2e3b2f53586b0148b583b6ee2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_critical_css (0.3.6)
4
+ rails_critical_css (0.3.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -5,11 +5,11 @@
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.
12
+ Be sure that NPM and Node is installed in your system and add to Gemfile:
13
13
 
14
14
  ```bash
15
15
  gem 'rails_critical_css'
@@ -49,10 +49,25 @@ In controller:
49
49
  In template:
50
50
 
51
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
52
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
+
61
+ # If you have custom link helper (which for example loads css tag after GDPR accept) you can use helper below
62
+ # Generator will extract hrefs from emitted html and generate stylesheet output
63
+ # if critical css is compiled successfully it will emit critical css
64
+ # and if preserve_content: true (which is default) arg is provided it will preserve provided content
53
65
  = critical_css_tags
54
- link rel="stylesheet" href="css/vendors.css" rel='stylesheet' type='text/css'
55
- link rel="stylesheet" href="css/app.css" rel='stylesheet' type='text/css'
66
+ = your_custom_link_helper "css/vendors.css"
67
+ = your_custom_link_helper "css/app.css"
68
+
69
+ - unless crticial_css?
70
+ div Critical css is being generated...
56
71
  ```
57
72
 
58
73
  ## Testing
@@ -30,4 +30,12 @@ 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
+ link_to href: href, rel: 'stylesheet', media: media
39
+ end
40
+ end
33
41
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsCriticalCss
4
- VERSION = '0.3.6'
4
+ VERSION = '0.3.7'
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.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateusz Bagiński