rails_critical_css 0.4.1 → 0.5.0
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 +5 -2
- data/lib/rails_critical_css/helpers.rb +12 -6
- 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: 658b92dca4978513e56f92cdf7768e1b4734402e9ec792a412648b8ec505a08f
|
4
|
+
data.tar.gz: 1058b361421be214b40903b0fdc91548eb2873cc463e39cd4abc152899f2afdb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 361139ecf3da628c8a74836c324e61bf9c055f30091edc68dc81dcbcd3fe3748152aaa92583b2d1f6108557a088bee088915a73b16b5e7e4fc899076baf03070
|
7
|
+
data.tar.gz: db3c6924c1a873a2e14452cc35465f84908b8f9a3beb45ca48e2ca519c6993e545295945a40a45782bcae9f9f4d375a3c737e31a7d00ba82995d9cf814280ecf
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -51,11 +51,13 @@ In template:
|
|
51
51
|
```slim
|
52
52
|
# These files will be prepended to critical css generator output, it can be normal scss file from assets
|
53
53
|
# critical_css_asset outputs nothing, it will be not appended to your html in link tag
|
54
|
-
|
55
|
-
= critical_css_asset
|
54
|
+
# (optional)
|
55
|
+
= critical_css_asset 'some-file-to-be-prepended-to-criticals', critical: true
|
56
|
+
= critical_css_asset 'hide-some-js-blocks', critical: true
|
56
57
|
|
57
58
|
# depending on critical_css? flag (it returns false if critical css is being generated)
|
58
59
|
# it emits link(href="your_file" rel="stylesheet") or link(href="your_file" rel="preload" onload="this.rel = 'stylesheet'")
|
60
|
+
= critical_css_tag # emits inline critical CSS if present
|
59
61
|
= critical_css_link 'css/vendors.css'
|
60
62
|
= critical_css_link 'css/vendors.css', media: 'print'
|
61
63
|
|
@@ -63,6 +65,7 @@ In template:
|
|
63
65
|
# Generator will extract hrefs from emitted html and generate stylesheet output
|
64
66
|
# if critical css is compiled successfully it will emit critical css
|
65
67
|
# and if preserve_content: true (which is default) arg is provided it will preserve provided content
|
68
|
+
# (optional)
|
66
69
|
= critical_css_tags
|
67
70
|
= your_custom_link_helper "css/vendors.css"
|
68
71
|
= your_custom_link_helper "css/app.css"
|
@@ -13,16 +13,22 @@ module RailsCriticalCss::Helpers
|
|
13
13
|
critical_css.present? && critical_css.instance_of?(String)
|
14
14
|
end
|
15
15
|
|
16
|
-
def critical_css_asset(attrs)
|
17
|
-
append_critical_css_asset(attrs)
|
16
|
+
def critical_css_asset(file, attrs = {})
|
17
|
+
append_critical_css_asset(attrs.merge({ file: file }))
|
18
18
|
nil
|
19
19
|
end
|
20
20
|
|
21
|
+
def critical_css_tag
|
22
|
+
return nil unless critical_css?
|
23
|
+
|
24
|
+
content_tag(:style, critical_css.html_safe, type: 'text/css')
|
25
|
+
end
|
26
|
+
|
21
27
|
def critical_css_tags(preserve_content: true, &block)
|
22
28
|
content = capture(&block)
|
23
29
|
|
24
30
|
if critical_css_enabled? && critical_css?
|
25
|
-
css_tags =
|
31
|
+
css_tags = critical_css_tag
|
26
32
|
css_tags = "#{css_tags}#{content}".html_safe if preserve_content
|
27
33
|
css_tags.html_safe
|
28
34
|
else
|
@@ -33,10 +39,10 @@ module RailsCriticalCss::Helpers
|
|
33
39
|
|
34
40
|
def critical_css_link(href, media: nil)
|
35
41
|
if critical_css?
|
36
|
-
|
42
|
+
stylesheet_link_tag(href, rel: 'preload', as: 'style', media: media, onload: "this.rel = 'stylesheet'")
|
37
43
|
else
|
38
|
-
|
39
|
-
|
44
|
+
critical_css_tags do
|
45
|
+
stylesheet_link_tag(href, rel: 'stylesheet', media: media)
|
40
46
|
end
|
41
47
|
end
|
42
48
|
end
|