svelte-on-rails 4.0.0 → 4.0.2
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 +4 -4
- data/lib/svelte_on_rails/lib/view_helper_support.rb +44 -35
- data/lib/svelte_on_rails/view_helpers.rb +20 -6
- 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: a04f321576291cd2c8663dd72fb181438a64e678151a48cce151fab567cb63be
|
4
|
+
data.tar.gz: 896d0ca8348e9ef37cfd5ba61fef9ea51a9c315e14afb0fd6a4f2c6472737ae1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eed1857d6d317005ba1f87afe6ec79f1a003823f6a84351fa14abb8fa29c46454ab71ed8496e387ee8faec48235f71203b0562f0b24b560236701c4afbe2e90e
|
7
|
+
data.tar.gz: aedb4fb0928a82b0d53426603d15604b64fc664c61e93b28040b9f8b52d5f1e319a14bbb81b2c6d1cce8da1292e46632ce038f24f6f098a71637ebb1d7ef2f4b
|
@@ -10,6 +10,7 @@ module SvelteOnRails
|
|
10
10
|
@start_time = Time.now
|
11
11
|
@filename = (file.match(/\.svelte$/) ? file[0..-8] : file)
|
12
12
|
@conf = SvelteOnRails::Configuration.instance
|
13
|
+
@all_arguments = props
|
13
14
|
@helper_options, @html_options, @props, @props_json = split_props(
|
14
15
|
props,
|
15
16
|
%i[class id style],
|
@@ -46,36 +47,7 @@ module SvelteOnRails
|
|
46
47
|
end
|
47
48
|
|
48
49
|
def redis_expiration_seconds
|
49
|
-
(conf.redis_cache_store[:expires_in] || 1.hour).to_i
|
50
|
-
end
|
51
|
-
|
52
|
-
def split_props(props, html_options, helper_options)
|
53
|
-
prp = {}
|
54
|
-
hlp_opts = {}
|
55
|
-
ht_opts = {
|
56
|
-
data: {
|
57
|
-
svelte_component: "/#{conf.components_folder + filename}",
|
58
|
-
controller: 'svelte-on-rails',
|
59
|
-
}
|
60
|
-
}
|
61
|
-
|
62
|
-
props.each do |k, v|
|
63
|
-
_k = k.to_sym
|
64
|
-
if helper_options.include?(_k)
|
65
|
-
hlp_opts[_k] = v
|
66
|
-
elsif html_options.include?(_k)
|
67
|
-
ht_opts[_k] = v
|
68
|
-
else
|
69
|
-
prp[_k] = v
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
ht_opts[:class] = "#{ht_opts[:class]} svelte-component".strip
|
74
|
-
prp_js = prp.to_json
|
75
|
-
ht_opts[:data][:props] = prp_js
|
76
|
-
ht_opts[:data][:svelte_status] = 'do-not-hydrate-me' if hlp_opts[:hydrate] == false
|
77
|
-
|
78
|
-
[hlp_opts, ht_opts, prp, prp_js]
|
50
|
+
(conf.redis_cache_store[:expires_in] || @helper_options[:expires_in] || 1.hour).to_i
|
79
51
|
end
|
80
52
|
|
81
53
|
def elapsed_milliseconds
|
@@ -155,8 +127,6 @@ module SvelteOnRails
|
|
155
127
|
_ssr == :auto ? request.headers[conf.non_ssr_request_header].blank? : _ssr
|
156
128
|
end
|
157
129
|
|
158
|
-
private
|
159
|
-
|
160
130
|
def generate_cache_key
|
161
131
|
|
162
132
|
mtime_file = @conf.ssr_dist_folder.join('last_mtime')
|
@@ -165,14 +135,24 @@ module SvelteOnRails
|
|
165
135
|
key2 = if @helper_options[:cache_key]
|
166
136
|
k2 = (@helper_options[:cache_key])
|
167
137
|
keys = k2.is_a?(Array) ? k2 : [k2]
|
168
|
-
keys.map
|
138
|
+
keys.map do |k|
|
139
|
+
if k.is_a?(ActiveRecord::Base)
|
140
|
+
"#{k.class.name}#{k.id}"
|
141
|
+
elsif k == nil
|
142
|
+
'nil'
|
143
|
+
elsif k.present?
|
144
|
+
k.to_s
|
145
|
+
else
|
146
|
+
"empty-#{k.class}"
|
147
|
+
end.join('-')
|
148
|
+
end
|
169
149
|
end
|
170
150
|
|
171
151
|
filename_part = [
|
172
152
|
"#{filename.split('/').last}.svelte",
|
173
153
|
Zlib.crc32(filename).to_s(36),
|
174
154
|
key2
|
175
|
-
].join('-')
|
155
|
+
].compact.join('-')
|
176
156
|
|
177
157
|
@cache_key_primary = [
|
178
158
|
conf.redis_cache_store[:namespace] ? conf.redis_cache_store[:namespace] : "svelte-on-rails:#{Rails.env}",
|
@@ -181,13 +161,42 @@ module SvelteOnRails
|
|
181
161
|
|
182
162
|
last_part = [
|
183
163
|
(@conf.watch_changes? ? Zlib.crc32(mtime).to_s(36) : nil),
|
184
|
-
Zlib.crc32(@
|
164
|
+
Zlib.crc32(@all_arguments.to_json).to_s(36)
|
185
165
|
].compact.join('-')
|
186
166
|
|
187
167
|
@cache_key = [@cache_key_primary, last_part].join(':')
|
188
168
|
|
189
169
|
end
|
190
170
|
|
171
|
+
def split_props(props, html_options, helper_options)
|
172
|
+
prp = {}
|
173
|
+
hlp_opts = {}
|
174
|
+
ht_opts = {
|
175
|
+
data: {
|
176
|
+
svelte_component: "/#{conf.components_folder + filename}",
|
177
|
+
controller: 'svelte-on-rails',
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
181
|
+
props.each do |k, v|
|
182
|
+
_k = k.to_sym
|
183
|
+
if helper_options.include?(_k)
|
184
|
+
hlp_opts[_k] = v
|
185
|
+
elsif html_options.include?(_k)
|
186
|
+
ht_opts[_k] = v
|
187
|
+
else
|
188
|
+
prp[_k] = v
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
ht_opts[:class] = "#{ht_opts[:class]} svelte-component".strip
|
193
|
+
prp_js = prp.to_json
|
194
|
+
ht_opts[:data][:props] = prp_js
|
195
|
+
ht_opts[:data][:svelte_status] = 'do-not-hydrate-me' if hlp_opts[:hydrate] == false
|
196
|
+
|
197
|
+
[hlp_opts, ht_opts, prp, prp_js]
|
198
|
+
end
|
199
|
+
|
191
200
|
end
|
192
201
|
end
|
193
202
|
end
|
@@ -22,20 +22,34 @@ module SvelteOnRails
|
|
22
22
|
|
23
23
|
support = SvelteOnRails::Lib::ViewHelperSupport.new(filename, props, request, true)
|
24
24
|
|
25
|
-
support.debug_log("Rendering component: #{filename}")
|
26
25
|
log_message = '?'
|
27
26
|
redis = support.conf.redis_instance
|
28
|
-
|
29
|
-
support.debug_log("Redis configuration: #{support.conf.redis_cache_store}")
|
27
|
+
cached_content = redis.get(support.cache_key)
|
30
28
|
|
31
29
|
# TTL
|
32
30
|
if support.debug?
|
31
|
+
|
32
|
+
support.debug_log("Rendering component: #{filename}")
|
33
|
+
support.debug_log("Redis configuration: #{support.conf.redis_cache_store}")
|
33
34
|
ttl = redis.ttl(support.cache_key)
|
34
|
-
|
35
|
+
|
36
|
+
key_stat = if cached_content.present?
|
37
|
+
'has content'
|
38
|
+
elsif redis.exists(support.cache_key)
|
39
|
+
'exists but no content'
|
40
|
+
else
|
41
|
+
'not exists'
|
42
|
+
end
|
43
|
+
|
44
|
+
ttl_stat = if redis.exists(support.cache_key)
|
45
|
+
", ttl was: #{ttl} seconds, now set to: #{support.redis_expiration_seconds} seconds"
|
46
|
+
end
|
47
|
+
|
48
|
+
support.debug_log("Cache key: «#{support.cache_key}» (#{key_stat}#{ttl_stat})")
|
49
|
+
|
35
50
|
end
|
36
|
-
redis.expire(support.cache_key, support.redis_expiration_seconds)
|
37
51
|
|
38
|
-
|
52
|
+
redis.expire(support.cache_key, support.redis_expiration_seconds)
|
39
53
|
|
40
54
|
res = if cached_content
|
41
55
|
log_message = "Returned #{support.filename}.svelte from cache"
|