rails_critical_css 0.3.9 → 0.5.1
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 +7 -4
- data/lib/rails_critical_css/helpers.rb +13 -7
- 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: dc8c82d272fd18cf5d8d69e8699031b3464e1f636613e6d8c88d50367e81132d
|
4
|
+
data.tar.gz: 45008420d5d5e7ec6f1b98a4312ac81fddd3f84f9c95299b1e67ae3eb6ad6dc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12559caad04aa7e5924740612cb31871811193c09f315be4186c91ba58aeeaab07c93d664bdd0871ad57f61af9bfb9b118b8df3a8d53e2cbf85ac9b246f14a17
|
7
|
+
data.tar.gz: b03dd88b0433f1a16da1b1310614ca32b07aa02aa4545a68f756522eda045388c922b8537090e43965fdd49d20f32febd8e51eafe7bb1621a967b6e7880515b5
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -51,18 +51,21 @@ 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'")
|
59
|
-
=
|
60
|
-
= critical_css_link
|
60
|
+
= critical_css_tag # emits inline critical CSS if present
|
61
|
+
= critical_css_link 'css/vendors.css'
|
62
|
+
= critical_css_link 'css/vendors.css', media: 'print'
|
61
63
|
|
62
64
|
# If you have custom link helper (which for example loads css tag after GDPR accept) you can use helper below
|
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
|
@@ -31,12 +37,12 @@ module RailsCriticalCss::Helpers
|
|
31
37
|
end
|
32
38
|
end
|
33
39
|
|
34
|
-
def critical_css_link(href
|
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
|