izi_json_ld 1.0.0 → 1.0.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: 829963d96abb460e0ea484d424bfe2d1c788bb73817f43f71c3c272a1dd8fe8e
4
- data.tar.gz: 310de3da62be69677e36359a3aa8aa625e5ba2ea4c5208f616ad6821d53b9402
3
+ metadata.gz: 462c25154b95f635c1a151da7195f00a3138b335e13dfdfae4509d81c89907bb
4
+ data.tar.gz: 180413fdbb50822e3d28d7d06dd3a451bfcf79d726bfa5183165bed8f288c6b8
5
5
  SHA512:
6
- metadata.gz: 2c00cd328bb712e104d28644f6f10340cfd15e2c35493f40330d78df20e6004ef481c7e9eb3b9fd10b32b24c3abee9893941c065585411f8ffdc512fe76b23c0
7
- data.tar.gz: ea23f754afc1bf8ac65f3bdbba4754569fd803a7846689ff38840738322292c97727e222ebbc4d6d62b96e73d3981993c56f665b0c685b4dca819cdfe606cd3b
6
+ metadata.gz: fd1fd86276cd1bf2a2389033348e607cd4d51e59a548ea3ef4ef06cdcbc5a7631258b4976e7dcb9ab00baa218d7b276d356bbc8b423054a2ebe6c13ab1107508
7
+ data.tar.gz: ccb1f46a00dfeb136e8f7fb2304c99ad0949ca92abd8fe51986ca04bc7ee29ce36c353ff243472c95371265ce6248fef77b3dcd3d7e842ecae8134de1768c9a9
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JsonLdHelper
4
+ def json_ld_tag(entity = nil)
5
+ content_tag(:script, entity.to_json, type: 'application/ld+json')
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IziJsonLd
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: izi_json_ld
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - IzikAJ
@@ -54,7 +54,7 @@ files:
54
54
  - app/entities/rating_entity.rb
55
55
  - app/entities/review_entity.rb
56
56
  - app/entities/service_entity.rb
57
- - app/helpers/critical_helper.rb
57
+ - app/helpers/json_ld_helper.rb
58
58
  - lib/izi_json_ld.rb
59
59
  - lib/izi_json_ld/engine.rb
60
60
  - lib/izi_json_ld/extentions/autoload_paths.rb
@@ -1,118 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module CriticalHelper
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"')
9
- noscript = content_tag :noscript do
10
- stylesheet_link_tag(*names)
11
- end
12
-
13
- link + noscript
14
- end
15
-
16
- def inline_js(name)
17
- IziJsonLd::InlineAsset.inline_js(name).html_safe
18
- end
19
-
20
- def inline_css(name)
21
- raw = IziJsonLd::InlineAsset.inline_css(name).html_safe
22
- raw = "<!-- CRIT CSS: #{name} -->".html_safe + raw if Rails.env.development?
23
- raw
24
- end
25
-
26
- def critical_js
27
- inline_js('crit-utils/bundle.js').presence || '<!-- CRIT JS NOT FOUND! -->'.html_safe
28
- end
29
-
30
- def critical_css(params = {})
31
- scope = params.fetch(:scope, 'critical')
32
- name = find_scoped_css(scope)
33
- stylesheets = Array.wrap(params.fetch(:stylesheets, []))
34
- data = StringIO.new
35
-
36
- if name.blank?
37
- # insert stylesheets directly if not crit css
38
- data << '<!-- CRIT CSS NOT FOUND! -->'
39
- data << stylesheet_link_tag(*stylesheets) if stylesheets.present?
40
- else
41
- data << inline_css(name)
42
- data << css_preload(stylesheets) if stylesheets.present?
43
- data << inline_js('crit-utils/measure.js') if Rails.env.development?
44
- end
45
-
46
- data.string.html_safe
47
- end
48
-
49
- def smart_picture(object, *args, **xargs, &block)
50
- return '' if object.blank?
51
-
52
- IziJsonLd::SmartPicture.render(object, *args, **xargs, &block)
53
- end
54
-
55
- def debug_critical_css(scope_name = 'critical')
56
- {
57
- lookup: scoped_css_files(scope_name),
58
- found: find_scoped_css(scope_name)
59
- }.to_json.html_safe
60
- end
61
-
62
- private
63
-
64
- def scoped_css_files(scope_name)
65
- [
66
- "#{controller_path}_#{action_name}",
67
- controller_path,
68
- *scoped_namespace_file(scope_name),
69
- "#{controller_name}_#{action_name}",
70
- controller_name,
71
- scope_name
72
- ].compact.uniq.map { |l| File.join(scope_name, "#{l}.css") }
73
- end
74
-
75
- def scoped_namespace_file(scope_name)
76
- scopes = []
77
- return scopes if controller_path == controller_name
78
-
79
- parts = controller_path.gsub(/\/#{controller_name}$/, '').split('/').reject(&:blank?)
80
- parts.each { |p| scopes.unshift(File.join([scopes.first, p].compact)) }
81
-
82
- scopes.uniq
83
- end
84
-
85
- def find_scoped_css(scope_name)
86
- scoped_css_files(scope_name).detect { |n| asset_exist?(n) }
87
- end
88
-
89
- def fetch_items(object, fields)
90
- Array.wrap(fields).map do |name|
91
- object.respond_to?(name) ? object.public_send(name) : nil
92
- end.compact
93
- end
94
-
95
- def asset_exist?(name)
96
- return find_asset_source(name)&.present? if Rails.env.development?
97
-
98
- manifest.assets.key?(name)
99
- end
100
-
101
- def find_asset_source(name)
102
- return find_sources_fallback(name) if old_manifest?
103
-
104
- manifest.find_sources(name)&.first
105
- end
106
-
107
- def find_sources_fallback(asset_path)
108
- Rails.application.assets.find_asset(asset_path)
109
- end
110
-
111
- def old_manifest?
112
- !manifest.respond_to?(:find_sources)
113
- end
114
-
115
- def manifest
116
- @manifest ||= Rails.application.assets_manifest
117
- end
118
- end