svelte-on-rails 5.3.1 → 5.3.2
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 +28 -44
- data/lib/svelte_on_rails/action_cable.rb +1 -1
- data/lib/svelte_on_rails/active_record_extensions.rb +13 -8
- data/lib/svelte_on_rails/lib/view_helper_support.rb +7 -1
- data/lib/svelte_on_rails/renderer/render.js +2 -2
- data/lib/svelte_on_rails/turbo_stream.rb +1 -1
- data/templates/all_features_test/app/frontend/initializers/actionCable.js +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66ba05e463ee27dcf6234fd49f46f1879daecd331f52549080d1d9f2f9e0748d
|
4
|
+
data.tar.gz: 1947be68d44b723ed074098728db6a0aaba6e5c5bbbb72dc09604b5fc4dc93f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c4a60a0c0f2d372535af2a7972c4df70ecb2958e0f0f2e9c718f6aeeccbab8f2797c329ec8ea789e5aa9d9e5154bc5b5cc88f70d0a5211416aa1d5d0296d8ad
|
7
|
+
data.tar.gz: afa1cef4cef2787e3da4d0a040b6261f1313b503ae149238faa74f779c46a5d78a569a4ac98c84d0e76276c514d8940f9dd6b6086a58c9c7e54490a2671d18a1
|
data/README.md
CHANGED
@@ -5,20 +5,11 @@
|
|
5
5
|
|
6
6
|
---
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
Guided by our Principles:
|
11
|
-
|
12
|
-
- **Minimal JavaScript but Reactive Power**
|
13
|
-
- **Beautiful Code, More Joy, Better Results**
|
14
|
-
- **Convention over Configuration**
|
15
|
-
|
16
|
-
`svelte-on-rails` completes [DHH's vision](https://rubyonrails.org/2021/12/15/Rails-7-fulfilling-a-vision)
|
17
|
-
for modern front-end demands.
|
8
|
+
Realizing [DHH's vision](https://rubyonrails.org/2021/12/15/Rails-7-fulfilling-a-vision) with modern front-end technologies.
|
18
9
|
|
19
10
|
# Why Integrate Svelte?
|
20
11
|
|
21
|
-
Svelte offers the simplest and most elegant
|
12
|
+
Svelte offers the simplest and most elegant soulution to building reactive, high-performance front-end components.
|
22
13
|
|
23
14
|
- **Seamless Integration**
|
24
15
|
- Works flawlessly with Hotwired/Turbo
|
@@ -388,39 +379,19 @@ on the svelte-on-rails config file or pass the `expires_in` as argument to the v
|
|
388
379
|
|
389
380
|
Pass `debug: true` to the helper and you will see on the logs how your configuration works.
|
390
381
|
|
391
|
-
## ActionCable
|
382
|
+
## ActionCable vs. TurboStream
|
392
383
|
|
393
384
|
There are two ways that the server can talk to the client over Websocket:
|
394
385
|
|
395
|
-
- ActionCable transmits directly to the frontends javascript
|
396
|
-
- TurboStreams is a wrapper around ActionCable
|
397
|
-
- You always need a html part for communication
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
Check the regarding keys and their commends on the [config file](https://gitlab.com/sedl/svelte-on-rails/-/blob/main/templates/config_base/config/svelte_on_rails.yml?ref_type=heads).
|
402
|
-
From there, you just need:
|
403
|
-
|
404
|
-
```yaml
|
405
|
-
turbo_stream:
|
406
|
-
target_html_id: 'svelte-on-rails-stream-actions-box'
|
407
|
-
channel: 'public'
|
408
|
-
```
|
409
|
-
|
410
|
-
## ActionCable vs TurboStream
|
411
|
-
|
412
|
-
- **ActionCable**
|
413
|
-
- Cleaner setup no html needed
|
414
|
-
- Seams to initialize securer, especially for testings (not: production)
|
415
|
-
- **TurboStream**
|
416
|
-
- Secured Streams by html-tag `signed-stream-name` if you want to send confidential data
|
417
|
-
over streams or have different channels for each user privileges
|
418
|
-
- Has [Compatibility issue with UJS](https://github.com/hotwired/turbo-rails?tab=readme-ov-file#compatibility-with-rails-ujs)
|
386
|
+
- **ActionCable** transmits directly to the frontends javascript
|
387
|
+
- **TurboStreams** is a wrapper around ActionCable
|
388
|
+
- You always need a html part for communication by secured channels
|
389
|
+
- Makes sense when you want to transfer confidential data or separate onto privileged user channels
|
390
|
+
- Has [compatibility issues with Rails-UJS](https://github.com/hotwired/turbo-rails?tab=readme-ov-file#compatibility-with-rails-ujs)
|
419
391
|
|
392
|
+
|
420
393
|
## SvelteOnRails::ActionCable
|
421
394
|
|
422
|
-
ActionCable is the more basic library behind `TurboStream` and it is a second Option to call Javascript Actions from the server.
|
423
|
-
|
424
395
|
**Setup**
|
425
396
|
|
426
397
|
Add `app/channels/svelte_on_rails_channel.rb`
|
@@ -437,7 +408,14 @@ class SvelteOnRailsChannel < ApplicationCable::Channel
|
|
437
408
|
end
|
438
409
|
```
|
439
410
|
|
440
|
-
|
411
|
+
config
|
412
|
+
|
413
|
+
```yaml
|
414
|
+
action_cable:
|
415
|
+
channel: "svelte_on_rails_channel"
|
416
|
+
```
|
417
|
+
|
418
|
+
javascript
|
441
419
|
|
442
420
|
```shell
|
443
421
|
npm i @rails/actioncable
|
@@ -510,11 +488,6 @@ on the whole `document` and fires the given event there.
|
|
510
488
|
|
511
489
|
# SvelteOnRails::TurboStream
|
512
490
|
|
513
|
-
Turbo Stream makes more sense when you think of sending confidential data to the components
|
514
|
-
or you want to separate to channels based on user groups, for example.
|
515
|
-
|
516
|
-
Few setup is needed for that:
|
517
|
-
|
518
491
|
**Setup**
|
519
492
|
|
520
493
|
Please setup the `turbo-rails` gem and follow the chapter [Come alive with Turbo Streams](https://github.com/hotwired/turbo-rails?tab=readme-ov-file#come-alive-with-turbo-streams), which mainly is:
|
@@ -541,6 +514,17 @@ you can test it by:
|
|
541
514
|
|
542
515
|
When this works you are good to go.
|
543
516
|
|
517
|
+
**Configs**
|
518
|
+
|
519
|
+
Check the regarding keys and their commends on the [config file](https://gitlab.com/sedl/svelte-on-rails/-/blob/main/templates/config_base/config/svelte_on_rails.yml?ref_type=heads).
|
520
|
+
From there, you just need:
|
521
|
+
|
522
|
+
```yaml
|
523
|
+
turbo_stream:
|
524
|
+
target_html_id: 'svelte-on-rails-stream-actions-box'
|
525
|
+
channel: 'public'
|
526
|
+
```
|
527
|
+
|
544
528
|
**Minimal Usage Example**
|
545
529
|
|
546
530
|
And call this by:
|
@@ -13,15 +13,20 @@ module SvelteOnRails
|
|
13
13
|
|
14
14
|
# separate offset and limit
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
h = attributes.grep(Hash)
|
17
|
+
attr = if h.present?
|
18
|
+
opts = h.first.symbolize_keys
|
19
|
+
offset = opts[:offset]
|
20
|
+
limit = opts[:limit]
|
21
|
+
if offset || limit
|
22
|
+
unless self.respond_to?(:each)
|
23
|
+
raise 'offset and limit are only supported for record sets that respond to :each'
|
24
|
+
end
|
25
|
+
_opts = opts.reject { |key, _| [:offset, :limit].include?(key) }
|
26
|
+
attributes.select { |item| !item.is_a?(Hash) }.push(_opts)
|
27
|
+
else
|
28
|
+
attributes
|
22
29
|
end
|
23
|
-
_opts = opts.reject { |key, _| [:offset, :limit].include?(key) }
|
24
|
-
attributes.select { |item| !item.is_a?(Hash) }.push(_opts)
|
25
30
|
else
|
26
31
|
attributes
|
27
32
|
end
|
@@ -79,7 +79,13 @@ module SvelteOnRails
|
|
79
79
|
|
80
80
|
def render_ssr
|
81
81
|
renderer = SvelteOnRails::Renderer.new(filename)
|
82
|
-
renderer.render(@svelte_props)
|
82
|
+
res = renderer.render(@svelte_props)
|
83
|
+
if res['html'].is_a?(Array)
|
84
|
+
res['html'] = res['html'].join
|
85
|
+
res
|
86
|
+
else
|
87
|
+
res
|
88
|
+
end
|
83
89
|
end
|
84
90
|
|
85
91
|
def custom_cache_key
|
@@ -14,13 +14,13 @@ import {loadComponentModule, readPropsFromStdin} from './utils.js';
|
|
14
14
|
|
15
15
|
try {
|
16
16
|
MyComponent(payload, props); // Writes directly to payload.out
|
17
|
-
console.log(`[svelte-on-rails:debug] written to payload`)
|
17
|
+
console.log(`[svelte-on-rails:debug] written to payload (typeof payload.out => «${typeof payload.out}»)`)
|
18
18
|
} catch (error) {
|
19
19
|
console.error('[svelte-on-rails:debug] Error rendering component:', error);
|
20
20
|
process.exit(1);
|
21
21
|
}
|
22
22
|
|
23
|
-
const res = {status: 'SUCCESS', html: payload.out
|
23
|
+
const res = {status: 'SUCCESS', html: payload.out};
|
24
24
|
console.log('[svelte-on-rails:successful-json-response]' + JSON.stringify(res));
|
25
25
|
})();
|
26
26
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { createConsumer } from "@rails/actioncable"
|
2
|
-
import {dispatchSvelteStreamEvent, actionCableDebugLog} from '@csedl/svelte-on-rails'
|
2
|
+
import { SvelteOnRails, dispatchSvelteStreamEvent, actionCableDebugLog } from '@csedl/svelte-on-rails'
|
3
|
+
SvelteOnRails.debug = true
|
3
4
|
|
4
5
|
const consumer = createConsumer()
|
5
6
|
|