jekyll-svelte-slabs 0.0.1 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-svelte-slabs.rb +42 -3
- data/lib/jekyll-svelte-slabs/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c90f7d3bc05e345860facc1989f6d6bbd697f388e6fa07102a0ca70ddda5328
|
4
|
+
data.tar.gz: a0acc05af349357aee9c6cfe29f75d72e1b265041e3e0539c1b5882a967ad76e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2801003756544cc7cc9523201af9f30a3aea9dd8b87caae249c6e2253a6b019e90969708c18807bdd41defb7341e8450ca2c137b5872fe288a70545e870d4dcd
|
7
|
+
data.tar.gz: d1f811cf822a92b49151fe8fa7bd9383ea5a229d0b2ecb2dfadbce54012b3bb42fb65f3b98d14e42cbdbf1c90bf5de516a4cb183412c6202f99cb375af1506f7
|
data/lib/jekyll-svelte-slabs.rb
CHANGED
@@ -37,6 +37,32 @@ module JekyllSvelteSlabs
|
|
37
37
|
false
|
38
38
|
end
|
39
39
|
|
40
|
+
# Iterate a hash (incl. arrays) to delete named keys
|
41
|
+
def purge_keys_from_hash(params, keys)
|
42
|
+
params.each do |k,v|
|
43
|
+
value = v || k
|
44
|
+
|
45
|
+
if value.is_a?(Hash) || value.is_a?(Array)
|
46
|
+
purge_keys_from_hash(value, keys)
|
47
|
+
else
|
48
|
+
params.delete(k) if keys.include?(k)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Remove a bind if specified, as well as any keys listed in the site config
|
54
|
+
def clean_params(context, params)
|
55
|
+
params.delete('bind')
|
56
|
+
|
57
|
+
slab_config = context['site']['svelte_slabs']
|
58
|
+
return unless slab_config
|
59
|
+
|
60
|
+
purge_keys = slab_config['remove_keys']
|
61
|
+
unless purge_keys.nil?
|
62
|
+
purge_keys_from_hash(params, purge_keys)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
40
66
|
def parse_params(context)
|
41
67
|
params = {}
|
42
68
|
@params.scan(VALID_SYNTAX) do |key, d_quoted, s_quoted, variable|
|
@@ -47,6 +73,12 @@ module JekyllSvelteSlabs
|
|
47
73
|
elsif variable
|
48
74
|
context[variable]
|
49
75
|
end
|
76
|
+
|
77
|
+
# Turn arrays of Documents into arrays of DocumentDrops
|
78
|
+
# so that the to_json in render pulls the hash not the content
|
79
|
+
if value.class == Array
|
80
|
+
value = value.map {|v| v.class == Jekyll::Document ? v.to_liquid : v}
|
81
|
+
end
|
50
82
|
|
51
83
|
params[key] = value
|
52
84
|
end
|
@@ -59,6 +91,8 @@ module JekyllSvelteSlabs
|
|
59
91
|
end
|
60
92
|
end
|
61
93
|
|
94
|
+
clean_params(context, params)
|
95
|
+
|
62
96
|
params
|
63
97
|
end
|
64
98
|
|
@@ -101,17 +135,22 @@ module JekyllSvelteSlabs
|
|
101
135
|
# site = context.registers[:site]
|
102
136
|
# puts site
|
103
137
|
|
138
|
+
slab_config = context['site']['svelte_slabs'] || {}
|
139
|
+
method = slab_config['method'] || "window"
|
140
|
+
|
104
141
|
file = render_variable(context) || @file
|
105
142
|
validate_file_name(file)
|
106
143
|
|
107
144
|
svelte_data = @params ? parse_params(context).to_json : "{}"
|
145
|
+
svelte_data = "\"#{Base64.strict_encode64(svelte_data)}\"" if method == "window_b"
|
108
146
|
endpoint = Digest::MD5.hexdigest(svelte_data)
|
109
147
|
|
110
148
|
<<~MSG
|
111
149
|
<script>
|
112
|
-
window
|
150
|
+
window.svelteSlabs = window.svelteSlabs || {};
|
151
|
+
window.svelteSlabs["#{endpoint}"] = #{svelte_data};
|
113
152
|
</script>
|
114
|
-
<div data-svelte-slab="#{file}" data-svelte-slab-props="
|
153
|
+
<div data-svelte-slab="#{file}" data-svelte-slab-props="#{method}:#{endpoint}">
|
115
154
|
#{text}
|
116
155
|
</div>
|
117
156
|
MSG
|
@@ -121,4 +160,4 @@ module JekyllSvelteSlabs
|
|
121
160
|
|
122
161
|
end
|
123
162
|
|
124
|
-
Liquid::Template.register_tag("svelte",
|
163
|
+
Liquid::Template.register_tag("svelte", JekyllSvelteSlabs::Tag)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-svelte-slabs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Liam Bigelow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|