jekyll-svelte-slabs 0.0.8 → 0.1.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: 8c90f7d3bc05e345860facc1989f6d6bbd697f388e6fa07102a0ca70ddda5328
4
- data.tar.gz: a0acc05af349357aee9c6cfe29f75d72e1b265041e3e0539c1b5882a967ad76e
3
+ metadata.gz: dc99c43ede6406e77e79fb8159094ca8e48d5db1b0e49af08d154a6a2bb5f546
4
+ data.tar.gz: 4e3669bfde07c63595eb24690aa62a0f7dcd21ebe5a153a84e05005ca7462def
5
5
  SHA512:
6
- metadata.gz: 2801003756544cc7cc9523201af9f30a3aea9dd8b87caae249c6e2253a6b019e90969708c18807bdd41defb7341e8450ca2c137b5872fe288a70545e870d4dcd
7
- data.tar.gz: d1f811cf822a92b49151fe8fa7bd9383ea5a229d0b2ecb2dfadbce54012b3bb42fb65f3b98d14e42cbdbf1c90bf5de516a4cb183412c6202f99cb375af1506f7
6
+ metadata.gz: c1b87f25bf1e733b92b2ec580dc42a96c702a5a07ff74c5753cde4f46cb204b88cc8cae284ab9b843dc63021a285fc5d34e6004145f1330d0f48de40943510d1
7
+ data.tar.gz: 88a4f274b4caff4571694ce74437e8d0423e4a4afd7c6f3230675cf4891572321448e4a6650003b37bb1a49a75a6327d669537f972d26f5a14d1f6ce6bf895d1
@@ -1,3 +1,3 @@
1
1
  module JekyllSvelteSlabs
2
- VERSION = "0.0.8"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -1,6 +1,7 @@
1
1
  require "base64"
2
2
  require 'json'
3
3
  require 'digest'
4
+ require_relative "./output-data"
4
5
 
5
6
  module JekyllSvelteSlabs
6
7
 
@@ -130,30 +131,42 @@ module JekyllSvelteSlabs
130
131
 
131
132
  def render(context)
132
133
  text = super
133
- # puts Base64.encode64(context[@data].to_json)
134
+ site = context['site']
134
135
 
135
- # site = context.registers[:site]
136
- # puts site
137
-
138
- slab_config = context['site']['svelte_slabs'] || {}
136
+ slab_config = site['svelte_slabs'] || {}
139
137
  method = slab_config['method'] || "window"
140
138
 
141
139
  file = render_variable(context) || @file
142
140
  validate_file_name(file)
143
141
 
144
142
  svelte_data = @params ? parse_params(context).to_json : "{}"
145
- svelte_data = "\"#{Base64.strict_encode64(svelte_data)}\"" if method == "window_b"
143
+
144
+ svelte_data = case method
145
+ when 'window_b' then "\"#{Base64.strict_encode64(svelte_data)}\""
146
+ when 'window_e' then "`#{svelte_data.gsub("<", "&rawlt;").gsub("`", "\`")}`"
147
+ else svelte_data
148
+ end
149
+
146
150
  endpoint = Digest::MD5.hexdigest(svelte_data)
147
151
 
148
- <<~MSG
149
- <script>
150
- window.svelteSlabs = window.svelteSlabs || {};
151
- window.svelteSlabs["#{endpoint}"] = #{svelte_data};
152
- </script>
153
- <div data-svelte-slab="#{file}" data-svelte-slab-props="#{method}:#{endpoint}">
154
- #{text}
155
- </div>
156
- MSG
152
+ if method == 'endpoint'
153
+ JekyllSvelteSlabs::SiteData.output(context.registers[:site], svelte_data, endpoint);
154
+ <<~MSG
155
+ <div data-svelte-slab="#{file}" data-svelte-slab-props="#{method}:#{endpoint}">
156
+ #{text}
157
+ </div>
158
+ MSG
159
+ else
160
+ <<~MSG
161
+ <script>
162
+ window.svelteSlabs = window.svelteSlabs || {};
163
+ window.svelteSlabs["#{endpoint}"] = #{svelte_data};
164
+ </script>
165
+ <div data-svelte-slab="#{file}" data-svelte-slab-props="#{method}:#{endpoint}">
166
+ #{text}
167
+ </div>
168
+ MSG
169
+ end
157
170
  end
158
171
 
159
172
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json/ext"
4
+ require_relative "./page-without-a-file"
5
+
6
+ module JekyllSvelteSlabs
7
+ class SiteData
8
+ def self.output(site, data, filename)
9
+ @site = site
10
+
11
+ generate_file(filename, data)
12
+ end
13
+
14
+ def self.generate_file(filename, content)
15
+ dest = destination_json_path(filename)
16
+ FileUtils.mkdir_p(File.dirname(dest))
17
+ File.open(dest, "w") { |file| file.write(content) }
18
+ @site.keep_files ||= []
19
+ @site.keep_files << json_path(filename)
20
+ end
21
+
22
+ def self.destination_json_path(filename)
23
+ Jekyll.sanitized_path(@site.dest, json_path(filename))
24
+ end
25
+
26
+ def self.json_path(filename)
27
+ "_slabs/#{filename}.json"
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllSvelteSlabs
4
+ # Utility class to help generate files with no source file
5
+ class PageWithoutAFile < Jekyll::Page
6
+ def read_yaml(*)
7
+ @data ||= {}
8
+ end
9
+ end
10
+ end
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.8
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liam Bigelow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-08 00:00:00.000000000 Z
11
+ date: 2021-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -39,6 +39,8 @@ extra_rdoc_files: []
39
39
  files:
40
40
  - lib/jekyll-svelte-slabs.rb
41
41
  - lib/jekyll-svelte-slabs/version.rb
42
+ - lib/output-data.rb
43
+ - lib/page-without-a-file.rb
42
44
  homepage: https://github.com/cloudcannon/svelte-slabs
43
45
  licenses:
44
46
  - MIT