svelte-on-rails 0.0.25 → 0.0.28

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: 8263684fe285763605b75de1b9b4d4e72f6c3292742fb9eebb551a708b13f323
4
- data.tar.gz: 6f10c28aca7e69a0b3a6cf73f0900aedd667388420bda2bc80d80d531c84c2f8
3
+ metadata.gz: fd9c8ec95be856becb268359d375e01f376f5b3024d9221db30cedae9ac9a72a
4
+ data.tar.gz: faf4829d8d7578c179671c1da34c03052cf9cbb4ffecc5ae0594919a44cee197
5
5
  SHA512:
6
- metadata.gz: 518c1924296b238f4ac82606b5b9ab4d8afe83c15e78b37269ed02d0e3e029b97daf088a3b7b0ba40232792295bef45f77e5db001b5074eab0adf3db97a30800
7
- data.tar.gz: 0f7c0baf8700d6ca0c812f9537d2aa97421d04626e27e9288ba3d96425f9546e1e53bbd575b6efa77b12c27878d67d76350d0d00fd658d2b849a56643e75a1a6
6
+ metadata.gz: 160ebff8d660ff911ae53a8a6ffec3d279e1d628acd7c8d3ab8260aa4084af3b71a1d9f3ac062ae1a8db186279e5bcab713ef68b2f9b1d47c2446860f6f1d871
7
+ data.tar.gz: c03ca0029d17f5a6a2507d696fe050d58e57c3f2dd06d916fd94bc93265a3f0b788fe72b0eeba7fa584b66dc80a0cd1fdefd0dad774ab2d043eeeb65bfaf4ad5
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
  ```
@@ -2,17 +2,15 @@ module SvelteOnRails
2
2
  module Installer
3
3
  module HelloWorld
4
4
 
5
- def self.install_hello_world
5
+ def self.install_hello_world(files)
6
+
6
7
  utils_i = SvelteOnRails::Installer::Utils
7
8
 
8
9
  # write templates
9
10
 
10
- templates = %w[
11
- app/controllers/svelte_on_rails_hello_world_controller.rb
12
- app/views/svelte_on_rails_hello_world/index.haml
13
- app/frontend/javascript/components/SvelteOnRailsHelloWorld.svelte
14
- ]
15
- utils_i.write_templates(templates)
11
+
12
+ utils_i.write_templates(files)
13
+
16
14
 
17
15
  # route
18
16
 
@@ -37,16 +35,10 @@ module SvelteOnRails
37
35
 
38
36
  end
39
37
 
40
- def self.remove_hello_world
38
+ def self.remove_hello_world(files)
41
39
 
42
40
  utils = SvelteOnRails::Installer::Utils
43
41
  if utils.ask_yn('Remove the Hello World component?')
44
- files = %w[
45
- app/views/svelte_on_rails_hello_world/index.haml
46
- app/views/svelte_on_rails_hello_world
47
- app/controllers/svelte_on_rails_hello_world_controller.rb
48
- app/frontend/javascript/components/SvelteOnRailsHelloWorld.svelte
49
- ]
50
42
  utils.remove_files(files)
51
43
  utils.remove_line_from_file('config/routes.rb', 'svelte_on_rails_hello_world')
52
44
  end
@@ -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,9 @@
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'
6
+ import {nestedJavascriptFunction} from '../nestedJavascript.js'
2
7
  export let items
3
8
  let count = 0;
4
9
 
@@ -20,7 +25,19 @@
20
25
  <li>{item}</li>
21
26
  {/each}
22
27
  </ul>
23
- </span>
28
+
29
+ <hr/>
30
+ <p>Images on various ways</p>
31
+ <span class="wrap-svg">{@html svgRaw}</span>
32
+ <img alt="svg ERROR" src={svg} />
33
+ <img alt="png ERROR" src={png} />
34
+
35
+ <hr/>
36
+ <Nested />
37
+
38
+ <hr/>
39
+ <p>{nestedJavascriptFunction()}</p>
40
+ </span>
24
41
 
25
42
  <style>
26
43
  button {
@@ -41,4 +58,10 @@
41
58
  -webkit-box-shadow: 2px 3px 16px -1px rgba(0, 0, 0, 0.75);
42
59
  -moz-box-shadow: 2px 3px 16px -1px rgba(0, 0, 0, 0.75);
43
60
  }
61
+ img, .wrap-svg {
62
+ display: inline-block;
63
+ width: 30px;
64
+ height: 30px;
65
+ margin: 30px;
66
+ }
44
67
  </style>
@@ -0,0 +1,3 @@
1
+ export function nestedJavascriptFunction() {
2
+ return 'nestedJavascript!';
3
+ }
@@ -0,0 +1,3 @@
1
+ export function nestedJavascriptFunction() {
2
+ return 'nestedJavascript («toggled»)';
3
+ }
@@ -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
@@ -8,6 +8,23 @@ require 'svelte_on_rails/installer/haml'
8
8
  utils = SvelteOnRails::Installer::Utils
9
9
  npm_i = SvelteOnRails::Installer::Npm
10
10
  application_js_path = Rails.root.join("app", "frontend", "entrypoints", "application.js")
11
+ toggle_hello_world_files = %w[
12
+ app/frontend/images/svg.svg
13
+ app/frontend/images/atom.svg
14
+ app/frontend/javascript/nestedJavascript.js
15
+ app/frontend/javascript/nestedJavascriptToggled.js
16
+ ]
17
+ hello_world_files = %w[
18
+ app/controllers/svelte_on_rails_hello_world_controller.rb
19
+ app/views/svelte_on_rails_hello_world/index.haml
20
+ app/frontend/javascript/components/SvelteOnRailsHelloWorld.svelte
21
+ app/frontend/javascript/components/sub/NestedComponent.svelte
22
+ app/frontend/javascript/nestedJavascript.js
23
+ app/frontend/javascript/nestedJavascriptToggled.js
24
+ app/frontend/javascript/components/sub/NestedComponent.svelte
25
+ app/frontend/images/svg.svg
26
+ app/frontend/images/check-circle-green.png
27
+ ]
11
28
 
12
29
  namespace :svelte_on_rails do
13
30
 
@@ -59,7 +76,7 @@ namespace :svelte_on_rails do
59
76
  hello_world_path = nil
60
77
  if utils.ask_yn('Do you want to install the Hello World component?')
61
78
  hw_i = SvelteOnRails::Installer::HelloWorld
62
- hello_world_path = hw_i.install_hello_world
79
+ hello_world_path = hw_i.install_hello_world(hello_world_files)
63
80
  end
64
81
 
65
82
  # finish
@@ -91,7 +108,8 @@ namespace :svelte_on_rails do
91
108
  task :remove_hello_world do
92
109
 
93
110
  hw_i = SvelteOnRails::Installer::HelloWorld
94
- hw_i.remove_hello_world
111
+ f = hello_world_files + toggle_hello_world_files
112
+ hw_i.remove_hello_world(f.uniq)
95
113
 
96
114
  end
97
115
 
@@ -100,11 +118,43 @@ namespace :svelte_on_rails do
100
118
 
101
119
  puts '-' * 80
102
120
  hw_i = SvelteOnRails::Installer::HelloWorld
103
- hello_world_path = hw_i.install_hello_world
121
+ hello_world_path = hw_i.install_hello_world(hello_world_files)
104
122
  puts "You can now see the Hello World component on: #{hello_world_path}."
105
123
 
106
124
  end
107
125
 
126
+ desc "Toggle the svg, included in the Hello World component for checking if it is refreshed on the browser"
127
+ task :toggle_hello_world_svg do
128
+
129
+ utils_i = SvelteOnRails::Installer::Utils
130
+
131
+ # write templates
132
+
133
+ utils_i.write_templates(toggle_hello_world_files, ask_for_overwrite: false)
134
+
135
+ puts '+++'
136
+
137
+ toggler = File.expand_path('../svelte_on_rails/installer/rails_template', __dir__) + '/hello_world_toggler'
138
+ if File.exist?(toggler)
139
+ File.delete(toggler)
140
+ File.delete('app/frontend/images/svg.svg')
141
+ FileUtils.mv('app/frontend/images/atom.svg', 'app/frontend/images/svg.svg')
142
+ File.delete('app/frontend/javascript/nestedJavascript.js')
143
+ FileUtils.mv('app/frontend/javascript/nestedJavascriptToggled.js', 'app/frontend/javascript/nestedJavascript.js')
144
+ puts "toggled svg.svg and nestedJavascriptToggled.js"
145
+ else
146
+ puts "toggled svg.svg and nestedJavascriptToggled.js back to original"
147
+ FileUtils.touch(toggler)
148
+ end
149
+
150
+ puts '+++'
151
+
152
+ puts "=> The Svelte components are living within the components folder"
153
+ puts "=> The hereby toggled files are outside of the components folder, but within the frontend folder"
154
+ puts "=> this toggling should work because the whole javascript folder is watched for changes (if configured so)"
155
+
156
+ end
157
+
108
158
  desc "Compile all Svelte components"
109
159
  task :reset_and_compile_all do
110
160
  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.25
4
+ version: 0.0.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Sedlmair
@@ -40,8 +40,14 @@ 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
49
+ - lib/svelte_on_rails/installer/rails_template/app/frontend/javascript/nestedJavascript.js
50
+ - lib/svelte_on_rails/installer/rails_template/app/frontend/javascript/nestedJavascriptToggled.js
45
51
  - lib/svelte_on_rails/installer/rails_template/app/views/svelte_on_rails_hello_world/index.haml
46
52
  - lib/svelte_on_rails/installer/rails_template/config/svelte_on_rails.yml
47
53
  - lib/svelte_on_rails/installer/svelte.rb