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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1fce5ce61aaba300ef0817a1cf6f33d66f97be54a59d863aa2626363abcd0618
4
- data.tar.gz: 605b23b501b0a1f5ef199b34fc4a6e736fd44f9b9aecb712c9e9bbcfd8d6e97a
3
+ metadata.gz: dc8c82d272fd18cf5d8d69e8699031b3464e1f636613e6d8c88d50367e81132d
4
+ data.tar.gz: 45008420d5d5e7ec6f1b98a4312ac81fddd3f84f9c95299b1e67ae3eb6ad6dc6
5
5
  SHA512:
6
- metadata.gz: a56bad87de70bbf0d7516a9335b5f6a736a8bdb333a9bc644a0c4b68c2ddd773e7eb51106b57b5a992f336255629f5dadd9621dfd43ab7b680d22e77ad5bd9d5
7
- data.tar.gz: 190044c5b832af0b9ecf86e4528ab423694a6433bd4f7a9100369dd4941470c5887e0377b558236bc3874e0b5c189aaf75e378a275c00c491fbce4e66cca5539
6
+ metadata.gz: 12559caad04aa7e5924740612cb31871811193c09f315be4186c91ba58aeeaab07c93d664bdd0871ad57f61af9bfb9b118b8df3a8d53e2cbf85ac9b246f14a17
7
+ data.tar.gz: b03dd88b0433f1a16da1b1310614ca32b07aa02aa4545a68f756522eda045388c922b8537090e43965fdd49d20f32febd8e51eafe7bb1621a967b6e7880515b5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_critical_css (0.3.9)
4
+ rails_critical_css (0.5.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
- = critical_css_asset file: 'some-file-to-be-prepended-to-criticals', critical: true
55
- = critical_css_asset file: 'hide-some-js-blocks', critical: true
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
- = critical_css_link href: 'css/vendors.css'
60
- = critical_css_link href: 'css/vendors.css', media: 'print'
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 = content_tag(:style, critical_css.html_safe, type: 'text/css')
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:, media: nil)
40
+ def critical_css_link(href, media: nil)
35
41
  if critical_css?
36
- link_to(href: href, rel: 'preload', as: 'style', media: media, onload: "this.rel = 'stylesheet'")
42
+ stylesheet_link_tag(href, rel: 'preload', as: 'style', media: media, onload: "this.rel = 'stylesheet'")
37
43
  else
38
- append_css_tags_assets(content) do
39
- link_to(href: href, rel: 'stylesheet', media: media)
44
+ critical_css_tags do
45
+ stylesheet_link_tag(href, rel: 'stylesheet', media: media)
40
46
  end
41
47
  end
42
48
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsCriticalCss
4
- VERSION = '0.3.9'
4
+ VERSION = '0.5.1'
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.9
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateusz Bagiński