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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +21 -3
- data/lib/npm_commands.rb +0 -1
- data/lib/rails_critical_css/helpers.rb +10 -0
- data/lib/rails_critical_css/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fce5ce61aaba300ef0817a1cf6f33d66f97be54a59d863aa2626363abcd0618
|
4
|
+
data.tar.gz: 605b23b501b0a1f5ef199b34fc4a6e736fd44f9b9aecb712c9e9bbcfd8d6e97a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a56bad87de70bbf0d7516a9335b5f6a736a8bdb333a9bc644a0c4b68c2ddd773e7eb51106b57b5a992f336255629f5dadd9621dfd43ab7b680d22e77ad5bd9d5
|
7
|
+
data.tar.gz: 190044c5b832af0b9ecf86e4528ab423694a6433bd4f7a9100369dd4941470c5887e0377b558236bc3874e0b5c189aaf75e378a275c00c491fbce4e66cca5539
|
data/Gemfile.lock
CHANGED
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
|
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
|
-
|
53
|
-
|
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
@@ -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
|