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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3dcc6df3b31671a12227c9b6a76dc4f9bd93de2238ad815d45fad52a585d2045
4
- data.tar.gz: a3efe8b44475688051c88350848acefdd9e084e19153b1e81cca652d769e9e1c
3
+ metadata.gz: 658b92dca4978513e56f92cdf7768e1b4734402e9ec792a412648b8ec505a08f
4
+ data.tar.gz: 1058b361421be214b40903b0fdc91548eb2873cc463e39cd4abc152899f2afdb
5
5
  SHA512:
6
- metadata.gz: 9430cb40e82adb501e48143441ec4c2be59cb6170b62124578d022e2ee2fdea79ba2ba94555f947dbb3be3cb179452932fcb2dbc4187d895cc1a7afbca34f201
7
- data.tar.gz: e0e13e590e62b1870ec0aad69b4cdd9bf1f8ee64a99f7e384ebb1d53271bca59ec7743f7ec3a8bd63e6dedda9416942ca6ba98a61d436f8bd3db4bc0ba347aba
6
+ metadata.gz: 361139ecf3da628c8a74836c324e61bf9c055f30091edc68dc81dcbcd3fe3748152aaa92583b2d1f6108557a088bee088915a73b16b5e7e4fc899076baf03070
7
+ data.tar.gz: db3c6924c1a873a2e14452cc35465f84908b8f9a3beb45ca48e2ca519c6993e545295945a40a45782bcae9f9f4d375a3c737e31a7d00ba82995d9cf814280ecf
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_critical_css (0.4.1)
4
+ rails_critical_css (0.5.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
- = 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'")
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 = 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
@@ -33,10 +39,10 @@ module RailsCriticalCss::Helpers
33
39
 
34
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 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.4.1'
4
+ VERSION = '0.5.0'
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.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateusz Bagiński