svelte-on-rails 8.0.1 → 9.0.0

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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -8
  3. data/lib/generators/showcase_generator.rb +128 -0
  4. data/lib/generators/svelte_on_rails/install/install_generator.rb +1 -111
  5. data/lib/svelte-on-rails.rb +1 -1
  6. data/lib/svelte_on_rails/active_record_extensions.rb +15 -4
  7. data/lib/svelte_on_rails/installer/hello_world.rb +7 -26
  8. data/lib/svelte_on_rails/installer/utils.rb +2 -14
  9. data/lib/svelte_on_rails/lib/development_utils.rb +0 -29
  10. data/lib/svelte_on_rails/lib/to_svelte.rb +37 -7
  11. data/lib/svelte_on_rails/lib/utils.rb +6 -0
  12. data/lib/svelte_on_rails/lib/view_helper_support.rb +2 -0
  13. data/lib/svelte_on_rails/renderer/render-backup.js +26 -0
  14. data/lib/svelte_on_rails/renderer/render.js +61 -13
  15. data/lib/svelte_on_rails/renderer/renderer.rb +7 -4
  16. data/lib/svelte_on_rails/renderer/utils.js +40 -40
  17. data/lib/svelte_on_rails/view_helpers.rb +3 -3
  18. data/lib/tasks/svelte_on_rails_tasks.rake +13 -51
  19. data/templates/config_base/config/svelte_on_rails.yml +1 -1
  20. data/templates/config_base/vite-ssr.config.ts +8 -3
  21. data/templates/showcase/app/channels/application_cable/channel.rb +4 -0
  22. data/templates/showcase/app/channels/application_cable/connection.rb +5 -0
  23. data/templates/showcase/app/controllers/svelte_on_rails_showcase_controller.rb +65 -0
  24. data/templates/showcase/app/frontend/javascript/svelte_on_rails_showcase/JavascriptImport.svelte +7 -0
  25. data/templates/showcase/app/frontend/javascript/svelte_on_rails_showcase/JpgImport.svelte +15 -0
  26. data/templates/{all_features_test/app/frontend/javascript/components → showcase/app/frontend/javascript/svelte_on_rails_showcase}/ParentWithChild.svelte +1 -1
  27. data/templates/showcase/app/frontend/javascript/svelte_on_rails_showcase/PngImport.svelte +16 -0
  28. data/templates/{all_features_test/app/frontend/javascript/components → showcase/app/frontend/javascript/svelte_on_rails_showcase}/ReceiveFromChannel.svelte +5 -3
  29. data/templates/{all_features_test/app/frontend/javascript/components → showcase/app/frontend/javascript/svelte_on_rails_showcase}/SvelteOnRailsHelloWorld.svelte +4 -4
  30. data/templates/showcase/app/frontend/javascript/svelte_on_rails_showcase/SvgRawImport.svelte +7 -0
  31. data/templates/showcase/app/views/svelte_on_rails_showcase/_nav.html.erb +13 -0
  32. data/templates/showcase/app/views/svelte_on_rails_showcase/backend_frontend_rendered.html.erb +37 -0
  33. data/templates/showcase/app/views/svelte_on_rails_showcase/index.html.erb +9 -0
  34. data/templates/{all_features_test/app/views/svelte_on_rails_hello_world → showcase/app/views/svelte_on_rails_showcase}/ssr_auto_rendered.html.erb +2 -2
  35. data/templates/{all_features_test/app/views/svelte_on_rails_hello_world → showcase/app/views/svelte_on_rails_showcase}/web_socket.html.erb +1 -1
  36. metadata +27 -24
  37. data/lib/svelte_on_rails/installer/vite.rb +0 -95
  38. data/templates/all_features_test/app/controllers/svelte_on_rails_hello_world_controller.rb +0 -62
  39. data/templates/all_features_test/app/frontend/javascript/components/JavascriptImport.svelte +0 -7
  40. data/templates/all_features_test/app/frontend/javascript/components/JpgImport.svelte +0 -7
  41. data/templates/all_features_test/app/frontend/javascript/components/PngImport.svelte +0 -7
  42. data/templates/all_features_test/app/frontend/javascript/components/SvgRawImport.svelte +0 -7
  43. data/templates/all_features_test/app/views/svelte_on_rails_hello_world/_nav.html.erb +0 -13
  44. data/templates/all_features_test/app/views/svelte_on_rails_hello_world/backend_frontend_rendered.html.erb +0 -37
  45. data/templates/all_features_test/app/views/svelte_on_rails_hello_world/index.html.erb +0 -9
  46. /data/templates/{all_features_test → showcase}/app/channels/svelte_on_rails_channel.rb +0 -0
  47. /data/templates/{all_features_test → showcase}/app/frontend/initializers/actionCable.js +0 -0
  48. /data/templates/{all_features_test/app/frontend/images/svelte-on-rails-hello-world-england.png → showcase/app/frontend/javascript/svelte_on_rails_showcase/england.png} +0 -0
  49. /data/templates/{all_features_test/app/frontend/images/svelte-on-rails-hello-world-face-smile-wink.svg → showcase/app/frontend/javascript/svelte_on_rails_showcase/face-smile-wink.svg} +0 -0
  50. /data/templates/{all_features_test/app/frontend/javascript → showcase/app/frontend/javascript/svelte_on_rails_showcase}/nestedJavascript.js +0 -0
  51. /data/templates/{all_features_test/app/frontend/javascript → showcase/app/frontend/javascript/svelte_on_rails_showcase}/nestedJavascriptToggled.js +0 -0
  52. /data/templates/{all_features_test/app/frontend/javascript/components → showcase/app/frontend/javascript/svelte_on_rails_showcase}/sub/NestedComponent.svelte +0 -0
  53. /data/templates/{all_features_test/app/frontend/images/svelte-on-rails-hello-world-switzerland.jpg → showcase/app/frontend/javascript/svelte_on_rails_showcase/switzerland.jpg} +0 -0
  54. /data/templates/{all_features_test/app/views/svelte_on_rails_hello_world → showcase/app/views/svelte_on_rails_showcase}/_styles.html.erb +0 -0
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: 8.0.1
4
+ version: 9.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Sedlmair
@@ -29,6 +29,7 @@ extensions: []
29
29
  extra_rdoc_files: []
30
30
  files:
31
31
  - README.md
32
+ - lib/generators/showcase_generator.rb
32
33
  - lib/generators/svelte_on_rails/install/install_generator.rb
33
34
  - lib/svelte-on-rails.rb
34
35
  - lib/svelte_on_rails/action_cable.rb
@@ -41,43 +42,45 @@ files:
41
42
  - lib/svelte_on_rails/installer/npm.rb
42
43
  - lib/svelte_on_rails/installer/svelte.rb
43
44
  - lib/svelte_on_rails/installer/utils.rb
44
- - lib/svelte_on_rails/installer/vite.rb
45
45
  - lib/svelte_on_rails/lib/development_utils.rb
46
46
  - lib/svelte_on_rails/lib/to_svelte.rb
47
47
  - lib/svelte_on_rails/lib/utils.rb
48
48
  - lib/svelte_on_rails/lib/view_helper_support.rb
49
49
  - lib/svelte_on_rails/railtie.rb
50
+ - lib/svelte_on_rails/renderer/render-backup.js
50
51
  - lib/svelte_on_rails/renderer/render.js
51
52
  - lib/svelte_on_rails/renderer/renderer.rb
52
53
  - lib/svelte_on_rails/renderer/utils.js
53
54
  - lib/svelte_on_rails/turbo_stream.rb
54
55
  - lib/svelte_on_rails/view_helpers.rb
55
56
  - lib/tasks/svelte_on_rails_tasks.rake
56
- - templates/all_features_test/app/channels/svelte_on_rails_channel.rb
57
- - templates/all_features_test/app/controllers/svelte_on_rails_hello_world_controller.rb
58
- - templates/all_features_test/app/frontend/images/svelte-on-rails-hello-world-england.png
59
- - templates/all_features_test/app/frontend/images/svelte-on-rails-hello-world-face-smile-wink.svg
60
- - templates/all_features_test/app/frontend/images/svelte-on-rails-hello-world-switzerland.jpg
61
- - templates/all_features_test/app/frontend/initializers/actionCable.js
62
- - templates/all_features_test/app/frontend/javascript/components/JavascriptImport.svelte
63
- - templates/all_features_test/app/frontend/javascript/components/JpgImport.svelte
64
- - templates/all_features_test/app/frontend/javascript/components/ParentWithChild.svelte
65
- - templates/all_features_test/app/frontend/javascript/components/PngImport.svelte
66
- - templates/all_features_test/app/frontend/javascript/components/ReceiveFromChannel.svelte
67
- - templates/all_features_test/app/frontend/javascript/components/SvelteOnRailsHelloWorld.svelte
68
- - templates/all_features_test/app/frontend/javascript/components/SvgRawImport.svelte
69
- - templates/all_features_test/app/frontend/javascript/components/sub/NestedComponent.svelte
70
- - templates/all_features_test/app/frontend/javascript/nestedJavascript.js
71
- - templates/all_features_test/app/frontend/javascript/nestedJavascriptToggled.js
72
- - templates/all_features_test/app/views/svelte_on_rails_hello_world/_nav.html.erb
73
- - templates/all_features_test/app/views/svelte_on_rails_hello_world/_styles.html.erb
74
- - templates/all_features_test/app/views/svelte_on_rails_hello_world/backend_frontend_rendered.html.erb
75
- - templates/all_features_test/app/views/svelte_on_rails_hello_world/index.html.erb
76
- - templates/all_features_test/app/views/svelte_on_rails_hello_world/ssr_auto_rendered.html.erb
77
- - templates/all_features_test/app/views/svelte_on_rails_hello_world/web_socket.html.erb
78
57
  - templates/config_base/app/frontend/ssr/ssr.js
79
58
  - templates/config_base/config/svelte_on_rails.yml
80
59
  - templates/config_base/vite-ssr.config.ts
60
+ - templates/showcase/app/channels/application_cable/channel.rb
61
+ - templates/showcase/app/channels/application_cable/connection.rb
62
+ - templates/showcase/app/channels/svelte_on_rails_channel.rb
63
+ - templates/showcase/app/controllers/svelte_on_rails_showcase_controller.rb
64
+ - templates/showcase/app/frontend/initializers/actionCable.js
65
+ - templates/showcase/app/frontend/javascript/svelte_on_rails_showcase/JavascriptImport.svelte
66
+ - templates/showcase/app/frontend/javascript/svelte_on_rails_showcase/JpgImport.svelte
67
+ - templates/showcase/app/frontend/javascript/svelte_on_rails_showcase/ParentWithChild.svelte
68
+ - templates/showcase/app/frontend/javascript/svelte_on_rails_showcase/PngImport.svelte
69
+ - templates/showcase/app/frontend/javascript/svelte_on_rails_showcase/ReceiveFromChannel.svelte
70
+ - templates/showcase/app/frontend/javascript/svelte_on_rails_showcase/SvelteOnRailsHelloWorld.svelte
71
+ - templates/showcase/app/frontend/javascript/svelte_on_rails_showcase/SvgRawImport.svelte
72
+ - templates/showcase/app/frontend/javascript/svelte_on_rails_showcase/england.png
73
+ - templates/showcase/app/frontend/javascript/svelte_on_rails_showcase/face-smile-wink.svg
74
+ - templates/showcase/app/frontend/javascript/svelte_on_rails_showcase/nestedJavascript.js
75
+ - templates/showcase/app/frontend/javascript/svelte_on_rails_showcase/nestedJavascriptToggled.js
76
+ - templates/showcase/app/frontend/javascript/svelte_on_rails_showcase/sub/NestedComponent.svelte
77
+ - templates/showcase/app/frontend/javascript/svelte_on_rails_showcase/switzerland.jpg
78
+ - templates/showcase/app/views/svelte_on_rails_showcase/_nav.html.erb
79
+ - templates/showcase/app/views/svelte_on_rails_showcase/_styles.html.erb
80
+ - templates/showcase/app/views/svelte_on_rails_showcase/backend_frontend_rendered.html.erb
81
+ - templates/showcase/app/views/svelte_on_rails_showcase/index.html.erb
82
+ - templates/showcase/app/views/svelte_on_rails_showcase/ssr_auto_rendered.html.erb
83
+ - templates/showcase/app/views/svelte_on_rails_showcase/web_socket.html.erb
81
84
  homepage: https://svelte-on-rails.dev
82
85
  licenses:
83
86
  - MIT
@@ -1,95 +0,0 @@
1
- module SvelteOnRails
2
-
3
- module Installer
4
-
5
- module Vite
6
-
7
- def self.install_vite(version_specifier: 'latest')
8
- iu = SvelteOnRails::Installer::Utils
9
-
10
- puts '-' * 80
11
-
12
- gu = SvelteOnRails::GemUtils
13
- if gu.check_gem_version('vite_rails')
14
- puts "vite_rails already installed, skipping this part."
15
- else
16
-
17
- # check non-existence
18
-
19
- iu.check_file_not_exists('config/vite.json')
20
- iu.check_file_not_exists('vite.config.ts')
21
- iu.check_folder_not_exists('app/frontend')
22
-
23
- # install
24
-
25
- gu.install_gem('vite_rails')
26
-
27
- Dir.chdir(Rails.root) do
28
- puts '++ running «bundle exec vite install» ++'
29
- `bundle exec vite install`
30
- puts '++ vite installer finished ++'
31
- end
32
-
33
- end
34
-
35
- # check existence
36
-
37
- iu.check_file_exists('config/vite.json')
38
- iu.check_file_exists('vite.config.ts')
39
- iu.check_file_exists('package.json')
40
- iu.check_file_exists('package-lock.json')
41
- iu.check_file_exists('app/frontend/entrypoints/application.js')
42
- iu.check_folder_exists('app/frontend')
43
-
44
- # check npm package version
45
-
46
- ni = SvelteOnRails::Installer::Npm
47
- ni.install_or_update_package('vite', version_specifier: version_specifier)
48
-
49
- end
50
-
51
- def self.configure_for_svelte(vite_plugin_svelte_version_specifier: nil)
52
-
53
- # add import statement
54
-
55
- js_i = SvelteOnRails::Installer::Javascript
56
- pkg = '@sveltejs/vite-plugin-svelte'
57
- npm_i = SvelteOnRails::Installer::Npm
58
- npm_i.install_or_update_package(pkg, version_specifier: vite_plugin_svelte_version_specifier)
59
-
60
- # add plugin
61
-
62
- file_path = 'vite.config.ts'
63
-
64
- if File.read(file_path).match?(/svelte/)
65
- puts "Svelte seams already configured in vite.config.ts, skipping here."
66
- else
67
-
68
- js_i.append_import_statement('vite.config.ts', pkg, "import {svelte} from '#{pkg}'")
69
-
70
- # Regex to match the plugins array and locate RubyPlugin()
71
- plugins_regex = /(plugins:\s*\[\s*)(\s*)RubyPlugin\(\),\s*([^\]]*?\])/m
72
-
73
- # Check if plugins array with RubyPlugin exists
74
- file_content = File.read(file_path)
75
- unless file_content.match?(plugins_regex)
76
- puts "Error: No plugins array with RubyPlugin() found in the input."
77
- return file_content
78
- end
79
-
80
- # Insert svelte({}), after RubyPlugin() with proper indentation
81
- modified_content = file_content.gsub(plugins_regex) do |match|
82
- prefix = $1 # Start of plugins array (e.g., "plugins: [")
83
- indent = ' ' # Indentation before RubyPlugin()
84
- rest = $3 # Remaining plugins and closing bracket
85
- "#{prefix}#{indent}RubyPlugin(),\n#{indent}svelte({}),\n#{indent}#{rest}"
86
- end
87
-
88
- File.write(file_path, modified_content)
89
- puts "Updated vite.config.ts with svelte() plugin."
90
- end
91
- end
92
-
93
- end
94
- end
95
- end
@@ -1,62 +0,0 @@
1
- class SvelteOnRailsHelloWorldController < ApplicationController
2
-
3
- def index
4
- end
5
-
6
- def web_socket_action
7
-
8
- comp = 'ReceiveFromChannel'
9
-
10
- case params['stream']
11
-
12
- when 'action-cable-to-component'
13
- SvelteOnRails::ActionCable.dispatch(
14
- comp,
15
- { message: "#{SecureRandom.hex(2)} Sent by <span class='transfer'>ActionCable</span>: äöü🤣🌴🌍漢字", class: 'action-cable-to-component' },
16
- event: 'stream-action'
17
- )
18
-
19
- when 'action-cable-to-element'
20
- SvelteOnRails::ActionCable.dispatch(
21
- comp,
22
- { message: "#{SecureRandom.hex(2)} <span class='transfer'>ActionCable to .my-custom-class / my-custom-event</span>", class: 'action-cable-to-element' },
23
- selector: '.my-custom-class',
24
- event: 'my-custom-event'
25
- )
26
-
27
- when 'action-cable-to-selector'
28
- SvelteOnRails::ActionCable.dispatch_by_selector(
29
- '.receive-by-selector',
30
- { message: "Sent by ActionCable/Selector: äöü🤣🌴🌍漢字", class: 'action-cable-to-selector' }
31
- )
32
-
33
- when 'turbo-stream-to-all-components'
34
- SvelteOnRails::TurboStream.dispatch(
35
- nil,
36
- { message: "Sent by TurboStream: äöü🤣🌴🌍漢字", class: 'turbo-stream-to-all-components' },
37
- )
38
-
39
- when 'turbo-stream-to-element'
40
- SvelteOnRails::TurboStream.dispatch(
41
- nil,
42
- { message: "Sent by TurboStream: äöü🤣🌴🌍漢字", class: 'turbo-stream-to-element' },
43
- selector: '.my-custom-class',
44
- event: 'my-custom-event'
45
- )
46
-
47
- when 'turbo-stream-to-selector'
48
- SvelteOnRails::TurboStream.dispatch_by_selector(
49
- '.receive-by-selector',
50
- { message: "Sent by TurboStream/Selector: äöü🤣🌴🌍漢字", class: 'turbo-stream-to-selector' }
51
- )
52
-
53
- else
54
- raise 'Unknown stream'
55
-
56
- end
57
-
58
- render plain: "dispatched: #{params['stream']}"
59
-
60
- end
61
-
62
- end
@@ -1,7 +0,0 @@
1
- <script>
2
- export let title;
3
- import {nestedJavascriptFunction} from "../nestedJavascript.js";
4
- </script>
5
-
6
- <p>{title}</p>
7
- <p>{nestedJavascriptFunction()}</p>
@@ -1,7 +0,0 @@
1
- <script>
2
- export let title;
3
- import jpg from '../../images/svelte-on-rails-hello-world-switzerland.jpg'
4
- </script>
5
-
6
- <p>{title}</p>
7
- <img alt="Jpg not loaded!" src="{jpg}" />
@@ -1,7 +0,0 @@
1
- <script>
2
- export let title;
3
- import png from '../../images/svelte-on-rails-hello-world-england.png'
4
- </script>
5
-
6
- <p>{title}</p>
7
- <img alt="Png not loaded!" src="{png}" />
@@ -1,7 +0,0 @@
1
- <script>
2
- export let title;
3
- import svgRaw from '../../images/svelte-on-rails-hello-world-face-smile-wink.svg?raw'
4
- </script>
5
-
6
- <p>{title}</p>
7
- {@html svgRaw}
@@ -1,13 +0,0 @@
1
- <div class="nav">
2
- <%= link_to 'Hello World', '/svelte_on_rails_hello_world/index' %>
3
- |
4
- <%= link_to 'Backend/Frontend Test', '/svelte_on_rails_hello_world/backend_frontend_rendered' %>
5
- |
6
- <%= link_to 'SSR-Auto rendered (default)', '/svelte_on_rails_hello_world/ssr_auto_rendered' %>
7
- |
8
- <%= link_to 'Turbo Streams', '/svelte_on_rails_hello_world/web_socket' %>
9
- </div>
10
-
11
- <% turbo_id = request.headers['X-Turbo-Request-ID'] %>
12
- <p class="<%= (turbo_id.present? ? 'turbo-request' : 'initial-request') %>"><%= (turbo_id.blank? ? 'This is a initial request' : "Turbo-Request-ID: #{turbo_id}") %></p>
13
- <p>Rails.environment: <%= Rails.env %></p>
@@ -1,37 +0,0 @@
1
- <%= render 'styles' %>
2
- <style>
3
- .svelte-component {
4
- border: 1px solid lightgray;
5
- padding: 10px;
6
- margin: 10px;
7
- width: 100px;
8
- display: inline-block;
9
- }
10
- </style>
11
-
12
- <%= render 'nav' %>
13
-
14
-
15
- <h1>SSR / Client side rendering test</h1>
16
- <p>After rendering both, client and server side rendered components, must look similar for making sure that on ssr:
17
- :auto (which is default)
18
- no unpleasant «blink» is appearing.</p>
19
- <hr>
20
-
21
- <% components = ['SvgRawImport', 'JpgImport', 'PngImport', 'JavascriptImport', 'ParentWithChild'] %>
22
-
23
- <h3>Always rendered server side</h3>
24
- <div class="ssr-only">
25
- <% components.each do |component| %>
26
- <%= svelte_component(component, {title: component}, options: {ssr: true, hydrate: false}) %>
27
- <% end %>
28
- </div>
29
-
30
- <hr>
31
- <h3>Always rendered client side</h3>
32
- <p>Here you will see a unpleasant «blink» on the initial request.</p>
33
- <div class="client-only">
34
- <% components.each do |component| %>
35
- <%= svelte_component(component, {title: component}, options: {ssr: false, hydrate: true}) %>
36
- <% end %>
37
- </div>
@@ -1,9 +0,0 @@
1
- <%= render 'styles' %>
2
-
3
-
4
- <%= render 'nav' %>
5
-
6
-
7
- <h1>Svelte is here</h1>
8
-
9
- <%= svelte_component "SvelteOnRailsHelloWorld", { items: ['attributes', 'are', 'parsed'] } %>