svelte-on-rails 0.0.8 → 0.0.10
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 +4 -4
- data/README.md +27 -16
- data/lib/svelte_on_rails/configuration.rb +10 -2
- data/lib/svelte_on_rails/render_server_side.rb +8 -4
- data/lib/svelte_on_rails/view_helpers.rb +12 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91e3a5e36988fe3fd9aa4cbf83c5dd475dae2919dc788afd3e1c3ba399690490
|
4
|
+
data.tar.gz: d9d60ad9b06e29bd1b744575f80bcd2ea9edbe60cc4a1badc6e8178867ff8b36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e8fa476b10eed4dd4ef9772c60b8e66bdf87fd7627458d9ba301520be94ad7ff96de9ac72ac6cbf85312473cfec42138e94e10110a7647b5a2e412bf460bb2e
|
7
|
+
data.tar.gz: 4539559ff01e47a4138f91cc7258846aa31ca4353b643a8c06dd5995e6cad991f597f2ec2a92fb48a0e4fcfff86191fdebd05354ae1d21fc6d26fc931a471ed3
|
data/README.md
CHANGED
@@ -2,21 +2,21 @@
|
|
2
2
|
|
3
3
|
Seamless and robust Svelte in Rails integration.
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
By default an when installed together with hotwired/turbo, it renders
|
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.
|
8
|
+
|
9
|
+
This way works perfectly together with turbo, you will never notice
|
10
|
+
this unpleasant «blink» on the frontend and it is maximum performance
|
11
|
+
optimized. SSR compilation is handled by rollup.
|
9
12
|
|
10
13
|
Server-side rendering is the bottleneck on such a pipeline.
|
11
14
|
Although rollup is powerful, this gem is in an early state
|
12
|
-
and there
|
13
|
-
So please always test your components early if they pass ssr.
|
15
|
+
and there may be limitations.
|
14
16
|
|
15
|
-
I have written everything in ESM syntax.
|
17
|
+
I have written everything in ESM syntax, orientated by the functionality of vite.
|
16
18
|
Although the common-js plugin is installed, I have not tested it,
|
17
19
|
so for example `require` may not work in Svelte components.
|
18
|
-
To check which import statements work, please check the components
|
19
|
-
in the `spec/rails-vite-test-app/app/frontend/javascript/components` gem.
|
20
20
|
|
21
21
|
This all is developed on Rails-7 together with `vite_rails`.
|
22
22
|
|
@@ -27,7 +27,8 @@ and [ElMassimo](https://github.com/ElMassimo) because they all helped me with th
|
|
27
27
|
|
28
28
|
- actual node installed on the server
|
29
29
|
- tested on ruby 3.2.2 and rails 7.1
|
30
|
-
- svelte (see: [install svelte on vite
|
30
|
+
- svelte v5 (see: [how to install svelte on rails/vite](https://dev.to/chmich/setup-inertia-and-svelte-on-rails-7-3glk))
|
31
|
+
- turbo (recommended / [how to install turbo on rails](https://github.com/hotwired/turbo-rails?tab=readme-ov-file#installation))
|
31
32
|
|
32
33
|
## Installation
|
33
34
|
|
@@ -35,31 +36,37 @@ add
|
|
35
36
|
```ruby
|
36
37
|
gem "svelte-on-rails"
|
37
38
|
```
|
38
|
-
to your gemfile
|
39
|
-
|
40
|
-
and run
|
39
|
+
to your gemfile and run
|
41
40
|
|
42
41
|
```ruby
|
42
|
+
$ bundle
|
43
43
|
$ rails svelte_on_rails:install
|
44
44
|
```
|
45
45
|
|
46
|
-
This will create a little config file, please read the comments there
|
46
|
+
This will create a little config file, please read the comments there and set the tags:
|
47
|
+
|
48
|
+
- `frontend_folder` (relative to Rails.root)
|
49
|
+
- `components_folder` (relative to frontend_folder)
|
47
50
|
|
48
51
|
Set up the npm module [@csedl/svelte-on-rails](https://www.npmjs.com/package/@csedl/svelte-on-rails) on the client side.
|
49
52
|
|
50
53
|
## Usage
|
51
54
|
|
55
|
+
On the view
|
56
|
+
|
52
57
|
```haml
|
53
58
|
= svelte_component("myComponent", items: ['item1', 'item2'])
|
54
59
|
```
|
55
60
|
|
56
|
-
|
61
|
+
Within the `components_folder` (configs above) a component like `myComponent.svelte`
|
57
62
|
|
58
63
|
```sveltehtml
|
59
64
|
<script>
|
60
65
|
export let items
|
61
66
|
</script>
|
62
67
|
|
68
|
+
<h1>Greetings from svelte</h1>
|
69
|
+
|
63
70
|
<ul>
|
64
71
|
{#each items as item}
|
65
72
|
<li>{item}</li>
|
@@ -73,6 +80,10 @@ would render a component like `myComponent.svelte`
|
|
73
80
|
</style>
|
74
81
|
```
|
75
82
|
|
83
|
+
And you should see «Greetings from svelte» on the browser.
|
84
|
+
|
85
|
+
I inserted very detailed error messages on rails and on the
|
86
|
+
npm package, so please check the logs on your browser.
|
76
87
|
|
77
88
|
### Import statements
|
78
89
|
|
@@ -153,4 +164,4 @@ initial request and the rest happens on the frontend.
|
|
153
164
|
## Testing
|
154
165
|
|
155
166
|
Testings are within the gem by `rspec`. And there is a [rails project](https://gitlab.com/users/sedl/projects) with
|
156
|
-
testings (based on playwright) where
|
167
|
+
testings (based on playwright) where the npm package and this gem is tested together.
|
@@ -21,7 +21,7 @@ module SvelteOnRails
|
|
21
21
|
load_yaml_config if defined?(Rails)
|
22
22
|
end
|
23
23
|
|
24
|
-
def watch_changes
|
24
|
+
def watch_changes?
|
25
25
|
if @configs[Rails.env]
|
26
26
|
@configs[Rails.env]['watch_changes'] == true
|
27
27
|
else
|
@@ -34,11 +34,19 @@ module SvelteOnRails
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def frontend_folder
|
37
|
+
@configs['frontend_folder']
|
38
|
+
end
|
39
|
+
|
40
|
+
def frontend_folder_full
|
37
41
|
rails_root.join(@configs['frontend_folder'].to_s)
|
38
42
|
end
|
39
43
|
|
44
|
+
def components_folder_full
|
45
|
+
Pathname.new(frontend_folder_full).join(components_folder.to_s)
|
46
|
+
end
|
47
|
+
|
40
48
|
def components_folder
|
41
|
-
|
49
|
+
@configs['components_folder']
|
42
50
|
end
|
43
51
|
|
44
52
|
def render_server_side
|
@@ -5,19 +5,17 @@ module SvelteOnRails
|
|
5
5
|
|
6
6
|
def initialize(filename)
|
7
7
|
|
8
|
-
@svelte_file = SvelteOnRails::Configuration.instance.
|
8
|
+
@svelte_file = SvelteOnRails::Configuration.instance.components_folder_full + filename
|
9
9
|
@svelte_filename = filename
|
10
10
|
@compiled_file = "#{SvelteOnRails::Configuration.instance.dist_folder}/#{(filename.match(/\.svelte$/) ? filename[0..-8] : filename)}"
|
11
11
|
|
12
|
-
raise "File not found: #{@svelte_file}" unless File.exist?(@svelte_file)
|
13
|
-
|
14
12
|
end
|
15
13
|
|
16
14
|
def compile_if_changes
|
17
15
|
|
18
16
|
# letzte Änderung innerhalb des ordners ermitteln
|
19
17
|
|
20
|
-
watch_changes = SvelteOnRails::Configuration.instance.watch_changes
|
18
|
+
watch_changes = SvelteOnRails::Configuration.instance.watch_changes?
|
21
19
|
ts_file = SvelteOnRails::Configuration.instance.dist_folder.join('reset_timestamp')
|
22
20
|
|
23
21
|
have_changes = if watch_changes && File.exist?(ts_file)
|
@@ -122,5 +120,11 @@ module SvelteOnRails
|
|
122
120
|
FileUtils.touch SvelteOnRails::Configuration.instance.dist_folder.join('reset_timestamp')
|
123
121
|
end
|
124
122
|
|
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?
|
126
|
+
end
|
127
|
+
|
128
|
+
|
125
129
|
end
|
126
130
|
end
|
@@ -3,12 +3,23 @@ module SvelteOnRails
|
|
3
3
|
|
4
4
|
def svelte_component(filename, props = {})
|
5
5
|
|
6
|
+
# check filename
|
7
|
+
conf = SvelteOnRails::Configuration.instance
|
8
|
+
cff = conf.components_folder_full
|
9
|
+
file_path = cff + "#{filename}.svelte"
|
10
|
+
found = (conf.watch_changes? ? SvelteOnRails::RenderServerSide.file_exist_case_sensitive?(cff, filename + '.svelte') : File.exist?(file_path))
|
11
|
+
unless found
|
12
|
+
ff = conf.frontend_folder
|
13
|
+
cf = conf.components_folder
|
14
|
+
raise "File not found: #{file_path}\nsvelte-on-rails gem, view helper #svelte_component\n\nYour configurations are:\nfrontend_folder: «#{ff}»\ncomponents_folder: «#{cf}»\n.. and the filename attribute for the view helper: «#{filename}»\n"
|
15
|
+
end
|
16
|
+
|
6
17
|
# check what to do
|
7
18
|
|
8
19
|
rss = if props.key?(:render_server_side)
|
9
20
|
props.delete(:render_server_side)
|
10
21
|
else
|
11
|
-
|
22
|
+
conf.render_server_side
|
12
23
|
end
|
13
24
|
unless [true, false, :auto].include?(rss)
|
14
25
|
raise "Only true, false or auto are allowed for the argument #render_server_side"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: svelte-on-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Sedlmair
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-04-
|
11
|
+
date: 2025-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|