svelte-on-rails 0.0.10 → 0.0.13

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: 91e3a5e36988fe3fd9aa4cbf83c5dd475dae2919dc788afd3e1c3ba399690490
4
- data.tar.gz: d9d60ad9b06e29bd1b744575f80bcd2ea9edbe60cc4a1badc6e8178867ff8b36
3
+ metadata.gz: 60ac9b6c78cf973e7bddd6802c58dc779388e97572087c084870183c773ccf04
4
+ data.tar.gz: '0529bd1129620c1e5693ca65fbf287e95b055741f5dcc05452645baa3422649d'
5
5
  SHA512:
6
- metadata.gz: 8e8fa476b10eed4dd4ef9772c60b8e66bdf87fd7627458d9ba301520be94ad7ff96de9ac72ac6cbf85312473cfec42138e94e10110a7647b5a2e412bf460bb2e
7
- data.tar.gz: 4539559ff01e47a4138f91cc7258846aa31ca4353b643a8c06dd5995e6cad991f597f2ec2a92fb48a0e4fcfff86191fdebd05354ae1d21fc6d26fc931a471ed3
6
+ metadata.gz: 109e692e90567fe73e364229dfd1f8553914a85b486f5aa6a80ef6ff43a976533bd84ab730f3cf499bc820a9699c3daf1a48e49e38d188d7c85b3c2279952700
7
+ data.tar.gz: bc18dd1cc2093a37cd3fa747c25d3ae5ff361f47b4483b5cee991804b3a6f95b2fd2dc4f64311e05cf839cff2cb6afdecfd80e8b691a0132e124debb0b1c10a1
data/README.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Seamless and robust Svelte in Rails integration.
4
4
 
5
- By default an when installed together with hotwired/turbo, it renders
5
+ By default, and when installed together with hotwired/turbo, it renders
6
6
  svelte components on first request server side («SSR») and for subsequent
7
- requests it provides a empty tag that is filled up on the frontend by svelte.
7
+ requests it provides a empty tag that will be mounted on the frontend by the associated npm package [@csedl/svelte-on-rails](https://www.npmjs.com/package/@csedl/svelte-on-rails) on the frontend.
8
8
 
9
- This way works perfectly together with turbo, you will never notice
9
+ This way svelte works perfectly together with turbo. You will never notice
10
10
  this unpleasant «blink» on the frontend and it is maximum performance
11
11
  optimized. SSR compilation is handled by rollup.
12
12
 
@@ -14,15 +14,19 @@ Server-side rendering is the bottleneck on such a pipeline.
14
14
  Although rollup is powerful, this gem is in an early state
15
15
  and there may be limitations.
16
16
 
17
- I have written everything in ESM syntax, orientated by the functionality of vite.
18
- Although the common-js plugin is installed, I have not tested it,
17
+ Javascript is written in ESM syntax, orientated by the functionality of vite.
18
+ Although the common-js plugin is installed, I have not tested it,
19
19
  so for example `require` may not work in Svelte components.
20
20
 
21
+ But we have done everything we can to make your setup work smoothly.
22
+
21
23
  This all is developed on Rails-7 together with `vite_rails`.
22
24
 
23
25
  Thanks to [shakacode](https://github.com/shakacode/react_on_rails)
24
26
  and [ElMassimo](https://github.com/ElMassimo) because they all helped me with theyr gems.
25
27
 
28
+ If you have issues, please open one and contributors are welcome!
29
+
26
30
  ## Requirements
27
31
 
28
32
  - actual node installed on the server
@@ -58,16 +62,22 @@ On the view
58
62
  = svelte_component("myComponent", items: ['item1', 'item2'])
59
63
  ```
60
64
 
61
- Within the `components_folder` (configs above) a component like `myComponent.svelte`
65
+ Test: Within the `components_folder` (configs above), create a component like `myComponent.svelte`
62
66
 
63
67
  ```sveltehtml
64
68
  <script>
65
69
  export let items
70
+ let count = 0;
71
+
72
+ function increment() {
73
+ count += 1;
74
+ }
66
75
  </script>
67
76
 
68
77
  <h1>Greetings from svelte</h1>
69
78
 
70
79
  <ul>
80
+ <button on:click={increment}>Increment: {count}</button>
71
81
  {#each items as item}
72
82
  <li>{item}</li>
73
83
  {/each}
@@ -82,6 +92,8 @@ Within the `components_folder` (configs above) a component like `myComponent.sve
82
92
 
83
93
  And you should see «Greetings from svelte» on the browser.
84
94
 
95
+ Click the counter button and check if the component is alive.
96
+
85
97
  I inserted very detailed error messages on rails and on the
86
98
  npm package, so please check the logs on your browser.
87
99
 
@@ -154,14 +166,16 @@ Example from the rails console for a medium complex component
154
166
  - Compiled MyComponent.svelte.js: 0.411ms
155
167
  - => happens only once
156
168
  - Rendered MyComponent.svelte server-side: 0.518ms
157
- - => happens on every request
169
+ - => happens on every SSR request
170
+ - Rendered MyComponent.svelte as empty element that will be mounted on the client side
171
+ - => subsequent calls
158
172
  - Completed 200 OK in 521ms (Views: 520.2ms | ActiveRecord: 0.0ms (0 queries, 0 cached) | GC: 0.3ms)
159
173
 
160
- Best is to work with the `render_server_side: :auto` option, which you can
161
- set as default on the config file. Then, the server does the SSR only on
162
- initial request and the rest happens on the frontend.
163
-
164
174
  ## Testing
165
175
 
166
176
  Testings are within the gem by `rspec`. And there is a [rails project](https://gitlab.com/users/sedl/projects) with
167
- testings (based on playwright) where the npm package and this gem is tested together.
177
+ testings (based on playwright) where the npm package and this gem is tested together.
178
+
179
+ ## Licence
180
+
181
+ License is MIT
@@ -121,8 +121,11 @@ module SvelteOnRails
121
121
  end
122
122
 
123
123
  def self.file_exist_case_sensitive?(containing_dir, filename)
124
- # because some filesystems are case insensitive we test case sensitive
125
- Dir[File.join(containing_dir, "*")].select {|f| File.basename(f) == filename}.any?
124
+ # Combine the directory path and filename
125
+ full_path = File.join(containing_dir, filename)
126
+
127
+ # Check if the file exists and the path matches case-sensitively
128
+ File.exist?(full_path) && Dir[File.join(containing_dir, "*")].any? { |f| f == full_path }
126
129
  end
127
130
 
128
131
 
@@ -68,7 +68,7 @@ module SvelteOnRails
68
68
  else
69
69
 
70
70
  # render empty element
71
-
71
+ Rails.logger.info " Rendered #{filename}.svelte as empty element that will be mounted on the client side"
72
72
  content_tag(:div, options) {}
73
73
 
74
74
  end
@@ -30,12 +30,16 @@ namespace :svelte_on_rails do
30
30
 
31
31
  development:
32
32
  watch_changes: true
33
- # check on every request if any file within the svelte components folder have changed
33
+ # Check on every request if any file within the svelte components folder have changed, for recompiling
34
+ # Case sensitive path checking, even the file system is case insensitive
35
+ # Make sure this ist set to tue for development and test, but not for production
34
36
 
35
37
  test:
38
+ watch_changes: true
39
+
36
40
  production:
37
41
  YAML
38
- puts "Created configuration file at #{config_path}"
42
+ puts "Created configuration file at file://#{config_path}"
39
43
  end
40
44
  end
41
45
  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.10
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Sedlmair