svelte-on-rails 7.0.0 → 7.1.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.
- checksums.yaml +4 -4
- data/README.md +24 -87
- data/lib/svelte_on_rails/view_helpers.rb +22 -4
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d0391b58c56174ccd55c88487ebb02e71da117ee56834c7a271757cc2f9e4be
|
4
|
+
data.tar.gz: a0c3f07377ed6fa3b5ce816d72674aa2e2cba02c63ac55c1975a2ce6dfb5b8a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fdf719228d92a54f0ee763c56493cb344521589f5cd6202f97a1779e35a5e9f9e5eda9c912ddcbd43695654729fcd3d5493a868c85ae8cfa9eed9ad504d9d29
|
7
|
+
data.tar.gz: 034c37f56fa009208ca065b88350048ebc612dbded303bf2bfa8cb36c83b7060c758555ae085ad830a85a030ab35ceec66c93c15b081f1ad8bc21a725242cef1
|
data/README.md
CHANGED
@@ -11,29 +11,7 @@ Realizing [DHH's vision](https://rubyonrails.org/2021/12/15/Rails-7-fulfilling-a
|
|
11
11
|
|
12
12
|
Svelte offers the simplest and most elegant soulution to building reactive, high-performance front-end components.
|
13
13
|
|
14
|
-
|
15
|
-
- Full-stack development delivers maximum value:
|
16
|
-
- Unified testing from database to frontend
|
17
|
-
- Single-source system delivery
|
18
|
-
- For the most HTML Hotwired is enough
|
19
|
-
- **Compared to integrated React or Vue**
|
20
|
-
- No virtual DOM, resulting in leaner packages and faster performance
|
21
|
-
- See Rich Harris’ [Rethinking Reactivity](https://svelte.dev/blog/svelte-3-rethinking-reactivity) (3:50–6:40) for a compelling comparison
|
22
|
-
- Easier to learn
|
23
|
-
- While React and Vue have larger communities, Svelte’s ecosystem is robust and growing, ideal for Rails integration
|
24
|
-
- **Compared to Hotwired**
|
25
|
-
- Stimulus is a initializer, but not a tool for frontend-apps!
|
26
|
-
- Svelte eliminates redundant HTML initial state logic
|
27
|
-
- Consolidates component logic into a single file
|
28
|
-
- Offloads rendering to JavaScript by Frontend, Server side Rendering only where necessary, reducing server load
|
29
|
-
- **Seamless Integration**
|
30
|
-
- Works flawlessly with Hotwired/Turbo
|
31
|
-
- Enhances Hotwire’s capabilities
|
32
|
-
- **Developer-Friendly**
|
33
|
-
- Simple to learn, intuitive, and powerful
|
34
|
-
- Lightning-fast performance
|
35
|
-
|
36
|
-
Svelte empowers Rails’ full-stack vision with modern, efficient front-end integration.
|
14
|
+
See: [Comparitions on the guide](https://svelte-on-rails-docs-51acfa.gitlab.io/about/why.html)
|
37
15
|
|
38
16
|
# Features
|
39
17
|
|
@@ -51,19 +29,31 @@ see [issues](https://gitlab.com/sedl/svelte-on-rails/-/issues)
|
|
51
29
|
Renders Svelte components server-side and, together with [@csedl/svelte-on-rails](https://www.npmjs.com/package/@csedl/svelte-on-rails),
|
52
30
|
hydrates the component on the frontend.
|
53
31
|
|
54
|
-
|
55
|
-
|
56
|
-
performance optimized.
|
57
|
-
|
58
|
-
**STATUS:** This gem is in the early stages of development, but is ready for use.
|
59
|
-
It has nearly 100% test coverage, with all tests passing. It has been in use since May/June 2025
|
60
|
-
on the systems of my two biggest customers.
|
32
|
+
Together with `turbo-rails` or `turbolinks`, if configured, it renders server-side only on initial requests
|
33
|
+
and delivers a empty tag that will be rendered by frontend.
|
61
34
|
|
62
35
|
If you have issues, please open one, and contributors are welcome!
|
63
36
|
|
64
37
|
## Requirements
|
65
38
|
|
66
|
-
|
39
|
+
- tested on
|
40
|
+
- ruby 3.2.2 and rails 7.1
|
41
|
+
- ruby 2.7.5 and rails 6.1
|
42
|
+
- vite@6 (v7 not supported, see issues)
|
43
|
+
- turbolinks and hotwired/turbo
|
44
|
+
- vite_rails (the installer will install it by option --full or --vite)
|
45
|
+
- svelte@5, @sveltejs/vite-plugin-svelte@5 (see: [how to install svelte on rails/vite](https://dev.to/chmich/setup-inertia-and-svelte-on-rails-7-3glk))
|
46
|
+
- turbo (recommended / [how to install turbo on rails](https://github.com/hotwired/turbo-rails?tab=readme-ov-file#installation))
|
47
|
+
- npm on latest versions
|
48
|
+
- actual node installed.
|
49
|
+
- if `nvm` is installed it gets the path to the node-binary from there.
|
50
|
+
- When `.nvmrc` is present on projects root, it is respected
|
51
|
+
- If node is not included on the PATH you can configure your node path by environment variable `SVELTE_ON_RAILS_NODE_BIN`
|
52
|
+
|
53
|
+
**PROPS ON RUBY <= 3**
|
54
|
+
|
55
|
+
|
56
|
+
|
67
57
|
|
68
58
|
## Installation
|
69
59
|
|
@@ -99,64 +89,11 @@ Add it to the view
|
|
99
89
|
<%= svelte_component('HelloWorld', {title: 'Hello World'}) %>
|
100
90
|
```
|
101
91
|
|
92
|
+
And you will see "Svelte Hello World" on the browser! 👍 🤗
|
102
93
|
|
103
|
-
|
104
|
-
|
105
|
-
**Explanation**
|
106
|
-
|
107
|
-
this Minimal installer does:
|
108
|
-
|
109
|
-
- add `app/frontend/initializers/svelte.js`
|
110
|
-
- Adds a import statement for that initializer to `application.js`
|
111
|
-
- add `app/frontend/ssr/ssr.js`
|
112
|
-
- add `config/svelte_on_rails.yml`
|
113
|
-
- add `vite-ssr.config.ts`
|
114
|
-
- add command `npm run build:ssr` to package.json
|
115
|
-
- installs or updates npm packages to the latest:
|
116
|
-
- `@csedl/svelte-on-rails`
|
117
|
-
- `typescript`
|
118
|
-
- `@types/node`
|
119
|
-
|
120
|
-
|
121
|
-
## Process explanation
|
122
|
-
|
123
|
-
**Why not client and server rendering in one process?**
|
124
|
-
|
125
|
-
That was my idea! `application.js` which is the usual entry point for the client
|
126
|
-
side could live on the same assets and manifest like svelte components that are
|
127
|
-
compiled as chunks which each is its own entry point. This failed:
|
128
|
-
|
129
|
-
- The `vite-plugin-ruby` did not support this: it constrained all to one entry point.
|
130
|
-
- See how fat the `vite-ssr.config.ts` is. For the client side this is not necessary.
|
131
|
-
|
132
|
-
At the end, I decided to split the process. For now it is cleaner. But that is not the last decision.
|
133
|
-
|
134
|
-
**Why not compiling server side purely by rollup?**
|
135
|
-
|
136
|
-
Advantages would be much slimmer packages and faster compilation. On the first
|
137
|
-
step i did this and i backed up a working and tested code on the branch [rollup-ssr](https://gitlab.com/sedl/svelte-on-rails/-/blob/rollup-ssr/BRANCH_INFO.md?ref_type=heads).
|
138
|
-
|
139
|
-
I decided to use Vite to bring the client and server side rendering
|
140
|
-
closer together.
|
141
|
-
|
142
|
-
But this, too, is not the last decision.
|
143
|
-
|
144
|
-
For now we proceed with vite.
|
145
|
-
|
146
|
-
**How does it work now?**
|
147
|
-
|
148
|
-
Client side rendering is done by vite like usual.
|
149
|
-
|
150
|
-
Server side rendering is triggered, similar to [vite_rails](https://vite-ruby.netlify.app/guide/deployment.html)
|
151
|
-
on `assets:precompile`, and, if `watch_changes` is configured,
|
152
|
-
which is default for development, it is triggered
|
153
|
-
on every change of a `*.svelte` file within the configured `components_folder`.
|
154
|
-
|
155
|
-
On the server side only the `*.svelte` files are served. Theyr included
|
156
|
-
assets are linked to the client side assets folder, which is mapped by `manifest.json`.
|
94
|
+
# Contributors welcome
|
157
95
|
|
158
|
-
|
159
|
-
Within `vite-ssr.config.ts`, by the `RAILS_ENV` variable, is decided which one is used.
|
96
|
+
see [Guide / run your first test](https://svelte-on-rails-docs-51acfa.gitlab.io/first_test.html)
|
160
97
|
|
161
98
|
|
162
99
|
## Licence
|
@@ -2,9 +2,11 @@
|
|
2
2
|
module SvelteOnRails
|
3
3
|
module ViewHelpers
|
4
4
|
|
5
|
-
def svelte_component(path, props = {}, html: {}, options: {})
|
5
|
+
def svelte_component(path, props = {}, html: {}, options: {}, _props: {})
|
6
6
|
|
7
|
-
|
7
|
+
prp = validate_props(props, _props)
|
8
|
+
|
9
|
+
support = SvelteOnRails::Lib::ViewHelperSupport.new(path, prp, html, options, request, false)
|
8
10
|
|
9
11
|
support.debug_log("Rendering component: #{path}")
|
10
12
|
log_message = '?'
|
@@ -18,9 +20,11 @@ module SvelteOnRails
|
|
18
20
|
|
19
21
|
end
|
20
22
|
|
21
|
-
def cached_svelte_component(path, props = {}, html: {}, options: {})
|
23
|
+
def cached_svelte_component(path, props = {}, html: {}, options: {}, _props: {})
|
24
|
+
|
25
|
+
prp = validate_props(props, _props)
|
22
26
|
|
23
|
-
support = SvelteOnRails::Lib::ViewHelperSupport.new(path,
|
27
|
+
support = SvelteOnRails::Lib::ViewHelperSupport.new(path, prp, html, options, request, true)
|
24
28
|
|
25
29
|
log_message = '?'
|
26
30
|
redis = support.conf.redis_instance
|
@@ -94,5 +98,19 @@ module SvelteOnRails
|
|
94
98
|
end
|
95
99
|
end
|
96
100
|
|
101
|
+
def validate_props(props, _props)
|
102
|
+
if props.present? && _props.present?
|
103
|
+
raise "you can only pass props as the first argument OR use the _props keyword argument. the latter only is made as workaround for Apps <= ruby-3"
|
104
|
+
end
|
105
|
+
if RUBY_VERSION.split('.').first.to_i >= 3 && _props.present?
|
106
|
+
raise "The _props keyword-argument is only meant as workaround for Apps <= ruby-3 because of avoiding misinterpreting hash as keyword arguments"
|
107
|
+
end
|
108
|
+
if props.present?
|
109
|
+
props
|
110
|
+
else
|
111
|
+
_props
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
97
115
|
end
|
98
116
|
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: 7.
|
4
|
+
version: 7.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Sedlmair
|
@@ -78,13 +78,13 @@ files:
|
|
78
78
|
- templates/config_base/app/frontend/ssr/ssr.js
|
79
79
|
- templates/config_base/config/svelte_on_rails.yml
|
80
80
|
- templates/config_base/vite-ssr.config.ts
|
81
|
-
homepage: https://
|
81
|
+
homepage: https://svelte-on-rails-docs-51acfa.gitlab.io/
|
82
82
|
licenses:
|
83
83
|
- MIT
|
84
84
|
metadata:
|
85
|
-
homepage_uri: https://
|
86
|
-
source_code_uri: https://
|
87
|
-
changelog_uri: https://
|
85
|
+
homepage_uri: https://svelte-on-rails-docs-51acfa.gitlab.io/
|
86
|
+
source_code_uri: https://svelte-on-rails-docs-51acfa.gitlab.io/
|
87
|
+
changelog_uri: https://svelte-on-rails-docs-51acfa.gitlab.io/
|
88
88
|
post_install: ruby -r svelte_on_rails/install -e 'SvelteOnRails::Install.run'
|
89
89
|
rdoc_options: []
|
90
90
|
require_paths:
|