svelte-on-rails 0.0.25 → 0.0.27
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/README.md +6 -0
- data/lib/svelte_on_rails/installer/hello_world.rb +5 -0
- data/lib/svelte_on_rails/installer/rails_template/app/frontend/images/atom.svg +1 -0
- data/lib/svelte_on_rails/installer/rails_template/app/frontend/images/check-circle-green.png +0 -0
- data/lib/svelte_on_rails/installer/rails_template/app/frontend/images/svg.svg +3 -0
- data/lib/svelte_on_rails/installer/rails_template/app/frontend/javascript/components/SvelteOnRailsHelloWorld.svelte +20 -1
- data/lib/svelte_on_rails/installer/rails_template/app/frontend/javascript/components/sub/NestedComponent.svelte +1 -0
- data/lib/svelte_on_rails/installer/rails_template/hello_world_toggler +0 -0
- data/lib/svelte_on_rails/installer/utils.rb +2 -2
- data/lib/svelte_on_rails/render.js +33 -10
- data/lib/svelte_on_rails/render_server_side.rb +2 -2
- data/lib/tasks/svelte_on_rails_tasks.rake +26 -0
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eca3dd8708bc889d9ae91fb041e8b717fd3a01e7284826cf644dd526d7cbdffc
|
4
|
+
data.tar.gz: 1206959ce1a1c2a428faf76ab606a43acf1bdc8c8e7188e68e0c39225719510d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8399eb534ceade658383e042a25042e814935cae9f0e48580780c582b545dbbb29d4e99ac886b210873f9beb25d8f735a8f2b7a22b78f8752857614912a865ec
|
7
|
+
data.tar.gz: 0db580b51db77febbc22f3ca3a4977fc5c0350868917c8b210cbba4c390d763067f454dda591bbae47a9c89323a32420d96b45cafe51638ab7d4c8a2a90b5b9f
|
data/README.md
CHANGED
@@ -192,6 +192,12 @@ rails svelte_on_rails:add_hello_world
|
|
192
192
|
rails svelte_on_rails:remove_hello_world
|
193
193
|
```
|
194
194
|
|
195
|
+
```bash
|
196
|
+
rails svelte_on_rails:toggle_hello_world_svg
|
197
|
+
```
|
198
|
+
|
199
|
+
toggles the svg nested to the hello world component for check if thee svg is refreshed when imported image changes
|
200
|
+
|
195
201
|
```bash
|
196
202
|
rails svelte_on_rails:reset_and_compile_all
|
197
203
|
```
|
@@ -3,6 +3,7 @@ module SvelteOnRails
|
|
3
3
|
module HelloWorld
|
4
4
|
|
5
5
|
def self.install_hello_world
|
6
|
+
|
6
7
|
utils_i = SvelteOnRails::Installer::Utils
|
7
8
|
|
8
9
|
# write templates
|
@@ -11,9 +12,13 @@ module SvelteOnRails
|
|
11
12
|
app/controllers/svelte_on_rails_hello_world_controller.rb
|
12
13
|
app/views/svelte_on_rails_hello_world/index.haml
|
13
14
|
app/frontend/javascript/components/SvelteOnRailsHelloWorld.svelte
|
15
|
+
app/frontend/javascript/components/sub/NestedComponent.svelte
|
16
|
+
app/frontend/images/svg.svg
|
17
|
+
app/frontend/images/check-circle-green.png
|
14
18
|
]
|
15
19
|
utils_i.write_templates(templates)
|
16
20
|
|
21
|
+
|
17
22
|
# route
|
18
23
|
|
19
24
|
route = 'svelte_on_rails_hello_world#index'
|
@@ -0,0 +1 @@
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Pro 6.0.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. --><path d="M256 224C238.3 224 223.1 238.4 223.1 256S238.3 288 256 288c17.62 0 32-14.38 32-32C287.9 238.4 273.6 224 256 224zM471.2 128c-15.62-27.75-49.62-41.38-93.11-41.38c-9.499 .125-18.87 .75-28.25 2C327.1 34.38 293.5 0 256 0S184.9 34.38 162.1 88.62c-9.374-1.25-18.75-1.875-28.25-2C90.39 86.62 56.4 100.2 40.78 128c-18.75 33.5-6.499 80.62 27.62 128c-34.12 47.38-46.37 94.5-27.62 128c15.62 27.75 49.62 41.38 93.11 41.38c9.499-.125 18.87-.75 28.25-2C184.9 477.6 218.5 512 256 512s71.12-34.38 93.86-88.63c9.374 1.25 18.75 1.875 28.25 2c43.49 0 77.49-13.62 93.11-41.38c18.75-33.5 6.499-80.63-27.62-128C477.7 208.6 489.1 161.5 471.2 128zM256 48c14.37 0 32.12 18.12 47.12 50C287.1 102.4 271.4 107.8 256 114.1c-15.37-6.375-31.12-11.76-47.12-16.14C223.9 66.12 241.6 48 256 48zM133.9 377.4c-26.5 0-46.74-6.625-52.74-17.38c-7.124-12.75-.5-37.63 18.62-66.63C111.4 305.2 123.8 316.5 136.8 327c2.25 16.5 5.374 33 9.624 49.13C142.3 376.4 137.9 377.4 133.9 377.4zM136.8 185C123.8 195.5 111.4 206.8 99.77 218.6C80.65 189.6 74.02 164.8 81.15 152c5.999-10.75 26.25-17.38 52.74-17.38c3.1 0 8.374 1 12.5 1.25C142.1 152 139 168.5 136.8 185zM256 464c-14.37 0-32.12-18.12-47.12-49.1C224.9 409.6 240.6 404.2 256 397.9c15.37 6.375 31.12 11.76 47.12 16.14C288.1 445.9 270.4 464 256 464zM256 352c-52.99 0-95.99-43-95.99-96S203 160 256 160s95.99 43 95.99 96S308.1 352 256 352zM430.9 360c-5.999 10.75-26.25 17.38-52.74 17.38c-3.1 0-8.374-1-12.5-1.25C369.9 360 372.1 343.5 375.2 327c12.1-10.5 25.37-21.75 36.1-33.63C431.4 322.4 437.1 347.2 430.9 360zM412.2 218.6C400.6 206.8 388.2 195.5 375.2 185C372.1 168.5 369.9 152 365.6 135.9c4.125-.25 8.499-1.25 12.5-1.25c26.5 0 46.74 6.625 52.74 17.38C437.1 164.8 431.4 189.6 412.2 218.6z"/></svg>
|
Binary file
|
@@ -1,4 +1,8 @@
|
|
1
1
|
<script>
|
2
|
+
import svgRaw from '../../images/svg.svg?raw'
|
3
|
+
import svg from '../../images/svg.svg'
|
4
|
+
import png from '../../images/check-circle-green.png'
|
5
|
+
import Nested from './sub/NestedComponent.svelte'
|
2
6
|
export let items
|
3
7
|
let count = 0;
|
4
8
|
|
@@ -20,7 +24,16 @@
|
|
20
24
|
<li>{item}</li>
|
21
25
|
{/each}
|
22
26
|
</ul>
|
23
|
-
|
27
|
+
|
28
|
+
<hr/>
|
29
|
+
<p>Images on various ways</p>
|
30
|
+
<span class="wrap-svg">{@html svgRaw}</span>
|
31
|
+
<img alt="svg ERROR" src={svg} />
|
32
|
+
<img alt="png ERROR" src={png} />
|
33
|
+
|
34
|
+
<hr/>
|
35
|
+
<Nested />
|
36
|
+
</span>
|
24
37
|
|
25
38
|
<style>
|
26
39
|
button {
|
@@ -41,4 +54,10 @@
|
|
41
54
|
-webkit-box-shadow: 2px 3px 16px -1px rgba(0, 0, 0, 0.75);
|
42
55
|
-moz-box-shadow: 2px 3px 16px -1px rgba(0, 0, 0, 0.75);
|
43
56
|
}
|
57
|
+
img, .wrap-svg {
|
58
|
+
display: inline-block;
|
59
|
+
width: 30px;
|
60
|
+
height: 30px;
|
61
|
+
margin: 30px;
|
62
|
+
}
|
44
63
|
</style>
|
@@ -0,0 +1 @@
|
|
1
|
+
<p>Nested Svelte Component</p>
|
File without changes
|
@@ -171,12 +171,12 @@ module SvelteOnRails
|
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
174
|
-
def self.write_templates(template_paths)
|
174
|
+
def self.write_templates(template_paths, ask_for_overwrite: true)
|
175
175
|
|
176
176
|
existing = template_paths.select { |p| File.exist?(p) }
|
177
177
|
verb = 'Created'
|
178
178
|
|
179
|
-
if existing.present?
|
179
|
+
if existing.present? && ask_for_overwrite
|
180
180
|
begin
|
181
181
|
puts "#{'Template'.pluralize(existing.length)} already exists:\n#{existing.join("\n")}.\nOverwrite? (y/n)"
|
182
182
|
continue = STDIN.gets.chomp.downcase[0]
|
@@ -2,28 +2,51 @@ import { existsSync } from 'node:fs';
|
|
2
2
|
import { join, dirname, resolve } from 'node:path';
|
3
3
|
import { fileURLToPath } from 'node:url';
|
4
4
|
|
5
|
-
//
|
5
|
+
// Get the directory of the current script
|
6
6
|
const __filename = fileURLToPath(import.meta.url);
|
7
7
|
const __dirname = dirname(__filename);
|
8
8
|
|
9
|
-
//
|
10
|
-
const compiledFile = process.argv[2]; //
|
11
|
-
|
9
|
+
// Command line arguments
|
10
|
+
const compiledFile = process.argv[2]; // Path to the compiled JavaScript file
|
11
|
+
let args;
|
12
|
+
|
13
|
+
try {
|
14
|
+
const base64Input = process.argv[3];
|
15
|
+
if (!base64Input) {
|
16
|
+
throw new Error('No Base64-encoded argument received in process.argv[3]');
|
17
|
+
}
|
18
|
+
|
19
|
+
let decodedString;
|
20
|
+
try {
|
21
|
+
decodedString = atob(base64Input);
|
22
|
+
} catch (decodeError) {
|
23
|
+
throw new Error(`Error decoding Base64 string: ${decodeError.message}\nInput (process.argv[3]): «${base64Input}»`);
|
24
|
+
}
|
25
|
+
|
26
|
+
try {
|
27
|
+
args = JSON.parse(decodedString);
|
28
|
+
} catch (parseError) {
|
29
|
+
throw new Error(`Error parsing JSON: ${parseError.message}\nInput (process.argv[3]): «${base64Input}»\nDecoded string: «${decodedString}»`);
|
30
|
+
}
|
31
|
+
} catch (error) {
|
32
|
+
console.error('Error processing command line arguments:', error.message);
|
33
|
+
process.exit(1);
|
34
|
+
}
|
12
35
|
|
13
36
|
let MyComponent;
|
14
37
|
(async () => {
|
15
38
|
try {
|
16
|
-
//
|
39
|
+
// Convert relative path to absolute path
|
17
40
|
const absolutePath = resolve(__dirname, compiledFile);
|
18
41
|
|
19
|
-
//
|
42
|
+
// Convert absolute path to a file URL
|
20
43
|
const modulePath = `file://${absolutePath}`;
|
21
44
|
|
22
|
-
//
|
45
|
+
// Import the module
|
23
46
|
const module = await import(modulePath);
|
24
47
|
MyComponent = module.default;
|
25
48
|
} catch (error) {
|
26
|
-
console.error(`
|
49
|
+
console.error(`Error loading component from ${compiledFile}:`, error);
|
27
50
|
process.exit(1);
|
28
51
|
}
|
29
52
|
|
@@ -31,9 +54,9 @@ let MyComponent;
|
|
31
54
|
const payload = { out: '' };
|
32
55
|
|
33
56
|
try {
|
34
|
-
MyComponent(payload, props); //
|
57
|
+
MyComponent(payload, props); // Writes directly to payload.out
|
35
58
|
} catch (error) {
|
36
|
-
console.error('
|
59
|
+
console.error('Error rendering component:', error);
|
37
60
|
process.exit(1);
|
38
61
|
}
|
39
62
|
|
@@ -54,7 +54,7 @@ module SvelteOnRails
|
|
54
54
|
def render_compiled_file(props = {})
|
55
55
|
require 'base64'
|
56
56
|
require 'json'
|
57
|
-
props_enc = Base64.
|
57
|
+
props_enc = Base64.strict_encode64(props.to_json).strip
|
58
58
|
cmd = [
|
59
59
|
'node',
|
60
60
|
'/Users/christian/projects-gmbh/gems/svelte-on-rails/svelte-on-rails-gem/lib/svelte_on_rails/render.js',
|
@@ -65,7 +65,7 @@ module SvelteOnRails
|
|
65
65
|
|
66
66
|
stdout, stderr, status = Open3.capture3(cmd, chdir: self.class.gem_app_dir)
|
67
67
|
unless status.to_s.match(/^pid [0-9]+ exit 0$/)
|
68
|
-
raise "Render Svelte Server-side
|
68
|
+
raise "Render Svelte Server-side =>\n#{cmd}\n\nError output from render.js (stderr) =>\n+++\n" + stderr + "+++\n\n"
|
69
69
|
end
|
70
70
|
|
71
71
|
begin
|
@@ -105,6 +105,32 @@ namespace :svelte_on_rails do
|
|
105
105
|
|
106
106
|
end
|
107
107
|
|
108
|
+
desc "Toggle the svg, included in the Hello World component for checking if it is refreshed on the browser"
|
109
|
+
task :toggle_hello_world_svg do
|
110
|
+
|
111
|
+
utils_i = SvelteOnRails::Installer::Utils
|
112
|
+
|
113
|
+
# write templates
|
114
|
+
|
115
|
+
templates = %w[
|
116
|
+
app/frontend/images/svg.svg
|
117
|
+
app/frontend/images/atom.svg
|
118
|
+
]
|
119
|
+
utils_i.write_templates(templates, ask_for_overwrite: false)
|
120
|
+
|
121
|
+
toggler = File.expand_path('../svelte_on_rails/installer/rails_template', __dir__) + '/hello_world_toggler'
|
122
|
+
if File.exist?(toggler)
|
123
|
+
File.delete(toggler)
|
124
|
+
File.delete('app/frontend/images/svg.svg')
|
125
|
+
FileUtils.mv('app/frontend/images/atom.svg', 'app/frontend/images/svg.svg')
|
126
|
+
puts "toggled svg.svg to atom.svg"
|
127
|
+
else
|
128
|
+
puts "toggled svg.svg to itself"
|
129
|
+
FileUtils.touch(toggler)
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
108
134
|
desc "Compile all Svelte components"
|
109
135
|
task :reset_and_compile_all do
|
110
136
|
SvelteOnRails::RenderServerSide.reset_and_compile_all
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: svelte-on-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.27
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Sedlmair
|
@@ -40,10 +40,15 @@ files:
|
|
40
40
|
- lib/svelte_on_rails/installer/javascript.rb
|
41
41
|
- lib/svelte_on_rails/installer/npm.rb
|
42
42
|
- lib/svelte_on_rails/installer/rails_template/app/controllers/svelte_on_rails_hello_world_controller.rb
|
43
|
+
- lib/svelte_on_rails/installer/rails_template/app/frontend/images/atom.svg
|
44
|
+
- lib/svelte_on_rails/installer/rails_template/app/frontend/images/check-circle-green.png
|
45
|
+
- lib/svelte_on_rails/installer/rails_template/app/frontend/images/svg.svg
|
43
46
|
- lib/svelte_on_rails/installer/rails_template/app/frontend/initializers/svelte.js
|
44
47
|
- lib/svelte_on_rails/installer/rails_template/app/frontend/javascript/components/SvelteOnRailsHelloWorld.svelte
|
48
|
+
- lib/svelte_on_rails/installer/rails_template/app/frontend/javascript/components/sub/NestedComponent.svelte
|
45
49
|
- lib/svelte_on_rails/installer/rails_template/app/views/svelte_on_rails_hello_world/index.haml
|
46
50
|
- lib/svelte_on_rails/installer/rails_template/config/svelte_on_rails.yml
|
51
|
+
- lib/svelte_on_rails/installer/rails_template/hello_world_toggler
|
47
52
|
- lib/svelte_on_rails/installer/svelte.rb
|
48
53
|
- lib/svelte_on_rails/installer/utils.rb
|
49
54
|
- lib/svelte_on_rails/installer/vite.rb
|