svelte-on-rails 0.0.12 → 0.0.14

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: 202f1fbacaa78ff38947e7665f87e21a904f6cb25fdab0e2c3280f8cd8d47c8c
4
- data.tar.gz: 18024b88f324f8e6a2e95832b6bec156154ff00692ad849952dc5739d6875634
3
+ metadata.gz: 8b31efba828e0d1f3416c684638903a5d80e42978b1ebe30a67fd447ae8d2bad
4
+ data.tar.gz: 45dbe8cd7110c0e36401ab1816c5186265850f79337783cd7a034a1677a6697e
5
5
  SHA512:
6
- metadata.gz: dc2bd126266183b839b66a9f42febc0f72b1a75f9d104b3b00cd8f15d80aa92345aa47060444cca49190fd9d6317517560e2d648d5680f6f732aee1ecafe950a
7
- data.tar.gz: 405093ef539c984afe97a78dca95e70c43c920da0cce9b01c12e1c5e3a75bb91139a74cb8fb6df9384d506eeecb36a510cda8014a2fca700d1a06d487ab3805e
6
+ metadata.gz: 9a73256d665867beb93c8221ecbdda94c4f8a5fab1cad3e226c4345804bd13a101b0da58177a6b9e58eeb822ca5bed99cd124eba01e939da348f5ec15ab2ca35
7
+ data.tar.gz: e7d878a42a7b7e57db9a9c061d059b7e8afd26a46df0f1bf1eac431227e3575d44f944bed9b0362bbb42b2d8343a43c1487b87012d7d68975d7a78b0d9587002
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
@@ -50,7 +54,7 @@ This will create a little config file, please read the comments there and set th
50
54
 
51
55
  Set up the npm module [@csedl/svelte-on-rails](https://www.npmjs.com/package/@csedl/svelte-on-rails) on the client side.
52
56
 
53
- ## Usage
57
+ ## Test if it works
54
58
 
55
59
  On the view
56
60
 
@@ -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
+ 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,10 @@ 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
+
97
+ Without the npm package installed, you would see the same html, but the increment button would not work.
98
+
85
99
  I inserted very detailed error messages on rails and on the
86
100
  npm package, so please check the logs on your browser.
87
101
 
@@ -154,14 +168,16 @@ Example from the rails console for a medium complex component
154
168
  - Compiled MyComponent.svelte.js: 0.411ms
155
169
  - => happens only once
156
170
  - Rendered MyComponent.svelte server-side: 0.518ms
157
- - => happens on every request
171
+ - => happens on every SSR request
172
+ - Rendered MyComponent.svelte as empty element that will be mounted on the client side
173
+ - => subsequent calls
158
174
  - Completed 200 OK in 521ms (Views: 520.2ms | ActiveRecord: 0.0ms (0 queries, 0 cached) | GC: 0.3ms)
159
175
 
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
176
  ## Testing
165
177
 
166
178
  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.
179
+ testings (based on playwright) where the npm package and this gem is tested together.
180
+
181
+ ## Licence
182
+
183
+ License is MIT
@@ -125,7 +125,9 @@ module SvelteOnRails
125
125
  full_path = File.join(containing_dir, filename)
126
126
 
127
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 }
128
+ File.exist?(full_path) && Dir[File.join(containing_dir, "**/*")].any? do |f|
129
+ f == full_path
130
+ end
129
131
  end
130
132
 
131
133
 
@@ -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
@@ -11,7 +11,7 @@ namespace :svelte_on_rails do
11
11
  config_path = Rails.root.join("config", "svelte_on_rails.yml")
12
12
 
13
13
  if File.exist?(config_path)
14
- puts "Configuration file already exists at #{config_path}"
14
+ puts "Configuration file already exists at file://#{config_path}"
15
15
  else
16
16
  File.write(config_path, <<~YAML)
17
17
 
@@ -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.12
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Sedlmair