izi_lightup 1.0.1 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5108172541e60f3a8b2eaed8efc03115e2d3eb0c14879e480907fe30a3585536
4
- data.tar.gz: 7c4ab5678444f8cc461d514c2cb00d4211b227d26544061a8a684d6d8788bf15
3
+ metadata.gz: d011babd1a4cfbeea73964467576025f53ef3e3a24dd14a90693078ab245859a
4
+ data.tar.gz: 720708d4116d9e985f45ad1c5c5e658b0bf315ad9195560a46166585e7b2c199
5
5
  SHA512:
6
- metadata.gz: 1deb1629850ba7668d77b6037ec3c6c1aba160a3092cae084cc83941bc52f5326a8a9f25b4f9d9387a5cee8bd2479116575e572caea7cd049442ad21679d43a9
7
- data.tar.gz: b1d013a65d6a6fdef8eeacb0a282a23b68cd74d61f31aa1702cb28fb5ceda8c1552663f935a432229fc6bb32455f55d31f9a21588fb8530af250cd13fd6edaf9
6
+ metadata.gz: 6e54a7446886a376f41cfa00fb94786f347413a03d00e070875baf00c6483e131c7b19afa6c745faf9e9be1ca4cea4085fdf454ec5c1e845750298362708937c
7
+ data.tar.gz: 6d99793e586bff9041a8e3e8cfdfcc207e01ea9a8fe5dae56840f623841001e898edb091c6e60da9448cdde6ee7670576d65c0bfa996d3232ebaa165ff0e845b
@@ -1,2 +1,3 @@
1
- //= require cssrelpreload.js
1
+ // loadCSS should be always BEFORE cssrelpreload
2
2
  //= require loadCSS.js
3
+ //= require cssrelpreload.js
@@ -16,6 +16,7 @@
16
16
  data = __required[id]
17
17
  return if data.loaded
18
18
  data.callbacks ||= []
19
+ data.started = true
19
20
 
20
21
  callback = node.onload
21
22
  node.onload = -> _onload(id)
@@ -35,8 +36,8 @@
35
36
  window.miniRequire ||= (key, source_url, callback = undefined) ->
36
37
  id = "source_#{key.replace(/[^a-z0-9_\-]+/ig, '_')}"
37
38
 
38
- # subscribe only if already attached
39
- return _subscribe(id, callback) if __required[id]?
39
+ # subscribe only if already attached & started
40
+ return _subscribe(id, callback) if __required[id]?.started?
40
41
 
41
42
  __required[id] = {loaded: false, callbacks: []}
42
43
  # subscribe only if no source
@@ -1,10 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CriticalHelper
4
- def css_preload(name)
5
- link = content_tag :link, '', rel: 'preload', href: stylesheet_path(name), as: 'style', onload: 'this.rel="stylesheet"'
4
+ def css_preload(names)
5
+ return '' if names.blank?
6
+ names = Array.wrap(names)
7
+
8
+ link = stylesheet_link_tag(*names, rel: 'preload', as: 'style', onload: 'this.rel="stylesheet"')
6
9
  noscript = content_tag :noscript do
7
- content_tag :link, '', rel: 'stylesheet', href: stylesheet_path(name)
10
+ stylesheet_link_tag(*names)
8
11
  end
9
12
 
10
13
  link + noscript
@@ -24,14 +27,22 @@ module CriticalHelper
24
27
  inline_js('crit-utils/bundle.js').presence || '<!-- CRIT JS NOT FOUND! -->'.html_safe
25
28
  end
26
29
 
27
- def critical_css
30
+ def critical_css(params = {})
28
31
  name = find_scoped_css('critical')
29
- return '<!-- CRIT CSS NOT FOUND! -->'.html_safe if name.blank?
32
+ stylesheets = Array.wrap(params.fetch(:stylesheets, []))
33
+ data = StringIO.new
30
34
 
31
- return inline_css(name) if Rails.env.production?
35
+ if name.blank?
36
+ # insert stylesheets directly if not crit css
37
+ data << '<!-- CRIT CSS NOT FOUND! -->'
38
+ data << stylesheet_link_tag(*stylesheets) if stylesheets.present?
39
+ else
40
+ data << inline_css(name)
41
+ data << css_preload(stylesheets) if stylesheets.present?
42
+ data << inline_js('crit-utils/measure.js') if Rails.env.development?
43
+ end
32
44
 
33
- # inject measure js for development
34
- inline_css(name) + inline_js('crit-utils/measure.js')
45
+ data.string.html_safe
35
46
  end
36
47
 
37
48
  def smart_picture(object, *args, **xargs, &block)
@@ -33,12 +33,22 @@ module IziLightup
33
33
  end
34
34
 
35
35
  def raw_source(asset_path)
36
+ return find_sources_fallback(asset_path) if old_manifest?
37
+
36
38
  manifest.find_sources(asset_path).first&.html_safe
37
39
  end
38
40
 
41
+ def old_manifest?
42
+ !manifest.respond_to?(:find_sources)
43
+ end
44
+
39
45
  def manifest
40
46
  @manifest ||= Rails.application.assets_manifest
41
47
  end
48
+
49
+ def find_sources_fallback(asset_path)
50
+ Rails.application.assets.find_asset(asset_path)&.source&.html_safe
51
+ end
42
52
  end
43
53
  end
44
54
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IziLightup
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.6'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: izi_lightup
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - IzikAJ
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-01 00:00:00.000000000 Z
11
+ date: 2020-10-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  Utils to speed up page load by using critical css &
@@ -36,7 +36,8 @@ files:
36
36
  - vendor/assets/javascripts/cssrelpreload.js
37
37
  - vendor/assets/javascripts/loadCSS.js
38
38
  homepage: https://bitbucket.org/netfixllc/izi_lightup
39
- licenses: []
39
+ licenses:
40
+ - MIT
40
41
  metadata: {}
41
42
  post_install_message:
42
43
  rdoc_options: []
@@ -53,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
54
  - !ruby/object:Gem::Version
54
55
  version: '0'
55
56
  requirements: []
56
- rubygems_version: 3.0.3
57
+ rubygems_version: 3.1.2
57
58
  signing_key:
58
59
  specification_version: 4
59
60
  summary: Izi Lightup