svelte-on-rails 0.0.24 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97f95713831cb35b5ba7ff76b63f320be3a5f7ef682844c65523728f78455c90
4
- data.tar.gz: 9501a5d850b4d5451dbc98055fbf4c21fd2b617dfdc2cc971c26cf02cbe6738e
3
+ metadata.gz: eca3dd8708bc889d9ae91fb041e8b717fd3a01e7284826cf644dd526d7cbdffc
4
+ data.tar.gz: 1206959ce1a1c2a428faf76ab606a43acf1bdc8c8e7188e68e0c39225719510d
5
5
  SHA512:
6
- metadata.gz: bc4a71238b2d358d38f616081ed56d1143f8745729d7fc80dfc4b1ceba85f70b0be542c760fdbc16095833eb88dfc7485ce22c73a76f940254de97e3c3af463c
7
- data.tar.gz: 16870d9e12978fc0e111b2fa380b09bb65b7d824f34b1a7e715d60b4e32414a7f07de824b92c6d0d5be3ef1888f492235d1a3dc231ba46dfae265bf1242ab741
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>
@@ -0,0 +1,3 @@
1
+ <svg width="100" height="50" xmlns="http://www.w3.org/2000/svg">
2
+ <text x="10" y="30" font-family="Arial, sans-serif" font-size="24" fill="black">svg</text>
3
+ </svg>
@@ -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
 
@@ -8,15 +12,28 @@
8
12
  </script>
9
13
 
10
14
  <span class="svelte-component-wrapper">
11
- <h1>Greetings from svelte!</h1>
15
+ <h1>Svelte is here!</h1>
16
+
17
+ <hr/>
18
+ <p>click the button and check if the component is alive</p>
12
19
  <button on:click={increment}>Increment: {count}</button>
13
20
 
21
+ <hr/>
14
22
  <ul>
15
23
  {#each items as item}
16
24
  <li>{item}</li>
17
25
  {/each}
18
26
  </ul>
19
- </span>
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>
20
37
 
21
38
  <style>
22
39
  button {
@@ -26,14 +43,21 @@
26
43
  border: none;
27
44
  cursor: pointer;
28
45
  }
46
+
29
47
  .svelte-component-wrapper {
30
48
  border: 1px solid black;
31
49
  padding: 10px;
32
50
  margin: 10px;
33
51
  background-color: #efefef;
34
52
  display: inline-block;
35
- box-shadow: 2px 3px 16px -1px rgba(0,0,0,0.75);
36
- -webkit-box-shadow: 2px 3px 16px -1px rgba(0,0,0,0.75);
37
- -moz-box-shadow: 2px 3px 16px -1px rgba(0,0,0,0.75);
53
+ box-shadow: 2px 3px 16px -1px rgba(0, 0, 0, 0.75);
54
+ -webkit-box-shadow: 2px 3px 16px -1px rgba(0, 0, 0, 0.75);
55
+ -moz-box-shadow: 2px 3px 16px -1px rgba(0, 0, 0, 0.75);
56
+ }
57
+ img, .wrap-svg {
58
+ display: inline-block;
59
+ width: 30px;
60
+ height: 30px;
61
+ margin: 30px;
38
62
  }
39
63
  </style>
@@ -1,3 +1,3 @@
1
1
  %p Example view
2
2
 
3
- = svelte_component "SvelteOnRailsHelloWorld", items: ['item-1', 'item-2', 'item-3']
3
+ = svelte_component "SvelteOnRailsHelloWorld", items: ['attributes', 'are', 'parsed']
@@ -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
- // Hole das Verzeichnis des aktuellen Skripts
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
- // Argumente aus der Kommandozeile
10
- const compiledFile = process.argv[2]; // Pfad zur kompilierten JavaScript-Datei
11
- const args = JSON.parse(atob(process.argv[3]));
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
- // Konvertiere den relativen Pfad in einen absoluten Pfad
39
+ // Convert relative path to absolute path
17
40
  const absolutePath = resolve(__dirname, compiledFile);
18
41
 
19
- // Konvertiere den absoluten Pfad in eine File-URL
42
+ // Convert absolute path to a file URL
20
43
  const modulePath = `file://${absolutePath}`;
21
44
 
22
- // Importiere das Modul
45
+ // Import the module
23
46
  const module = await import(modulePath);
24
47
  MyComponent = module.default;
25
48
  } catch (error) {
26
- console.error(`Fehler beim Laden der Komponente aus ${compiledFile}:`, 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); // Schreibt direkt in payload.out
57
+ MyComponent(payload, props); // Writes directly to payload.out
35
58
  } catch (error) {
36
- console.error('Fehler beim Rendern der Komponente:', 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.encode64(props.to_json).strip
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:\nrender.js => #{compiled_js_file}\n" + stderr
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
@@ -17,7 +17,6 @@ namespace :svelte_on_rails do
17
17
  puts '-' * 80
18
18
  puts 'STARTING SVELTE-ON-RAILS INSTALLATION'
19
19
 
20
-
21
20
  # vite
22
21
 
23
22
  vite_i = SvelteOnRails::Installer::Vite
@@ -45,7 +44,7 @@ namespace :svelte_on_rails do
45
44
  tr_pkg = '@hotwired/turbo-rails'
46
45
 
47
46
  npm_i.install_or_update_package(tr_pkg)
48
-
47
+
49
48
  js_i = SvelteOnRails::Installer::Javascript
50
49
  js_i.append_import_statement(application_js_path, tr_pkg, "import '#{tr_pkg}';")
51
50
 
@@ -91,8 +90,8 @@ namespace :svelte_on_rails do
91
90
  desc "Removes the Hello World component"
92
91
  task :remove_hello_world do
93
92
 
94
- hw_i = SvelteOnRails::Installer::HelloWorld
95
- hw_i.remove_hello_world
93
+ hw_i = SvelteOnRails::Installer::HelloWorld
94
+ hw_i.remove_hello_world
96
95
 
97
96
  end
98
97
 
@@ -100,10 +99,34 @@ namespace :svelte_on_rails do
100
99
  task :add_hello_world do
101
100
 
102
101
  puts '-' * 80
103
- if utils.ask_yn('Do you want to install the Hello World component?')
104
- hw_i = SvelteOnRails::Installer::HelloWorld
105
- hello_world_path = hw_i.install_hello_world
106
- puts "You can now see the Hello World component on: #{hello_world_path}."
102
+ hw_i = SvelteOnRails::Installer::HelloWorld
103
+ hello_world_path = hw_i.install_hello_world
104
+ puts "You can now see the Hello World component on: #{hello_world_path}."
105
+
106
+ end
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)
107
130
  end
108
131
 
109
132
  end
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.24
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