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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b172f3a295136f0317cc6fabb713262b1d1ac813894ef7e07f9b48da61f01a0
4
- data.tar.gz: 477f5ce8a86e4d0e7bbf508be99486a9763454ee027b43240cb3432cf5250c37
3
+ metadata.gz: 66ba05e463ee27dcf6234fd49f46f1879daecd331f52549080d1d9f2f9e0748d
4
+ data.tar.gz: 1947be68d44b723ed074098728db6a0aaba6e5c5bbbb72dc09604b5fc4dc93f3
5
5
  SHA512:
6
- metadata.gz: 2f2595ac48833224788450ce49f31d775ffcd552dd628b630caa450045b02a38c725c81fadeaf4833b6eb8134d32b28c7c1b69fd387b639d0c9c655a22549a08
7
- data.tar.gz: fd6aecc7d1923717b5e0119b337d221d6cf0e5c1e4a6b95f5a2a58911787b0e5a4587022850ea546a2c9e385e7d19a8fd96856ecbb07f010830bbe0d5319641b
6
+ metadata.gz: 3c4a60a0c0f2d372535af2a7972c4df70ecb2958e0f0f2e9c718f6aeeccbab8f2797c329ec8ea789e5aa9d9e5154bc5b5cc88f70d0a5211416aa1d5d0296d8ad
7
+ data.tar.gz: afa1cef4cef2787e3da4d0a040b6261f1313b503ae149238faa74f779c46a5d78a569a4ac98c84d0e76276c514d8940f9dd6b6086a58c9c7e54490a2671d18a1
data/README.md CHANGED
@@ -5,20 +5,11 @@
5
5
 
6
6
  ---
7
7
 
8
- **Svelte on Rails: Modern Front-End + Rails Simplicity**
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 approach to building reactive, high-performance front-end components.
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 / TurboStream
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
- **Configs**
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
- run
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:
@@ -40,7 +40,7 @@ module SvelteOnRails
40
40
 
41
41
  args = {
42
42
  eventDetail: event_detail,
43
- component: '/false/',
43
+ component: ':false:',
44
44
  event: event,
45
45
  selector: selector
46
46
  }
@@ -13,15 +13,20 @@ module SvelteOnRails
13
13
 
14
14
  # separate offset and limit
15
15
 
16
- opts = attributes.grep(Hash).first.symbolize_keys
17
- offset = opts[:offset]
18
- limit = opts[:limit]
19
- attr = if offset || limit
20
- unless self.respond_to?(:each)
21
- raise 'offset and limit are only supported for record sets that respond to :each'
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.join('')};
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
 
@@ -40,7 +40,7 @@ module SvelteOnRails
40
40
 
41
41
  args = {
42
42
  eventDetail: event_detail,
43
- component: '/false/',
43
+ component: ':false:',
44
44
  event: event,
45
45
  selector: selector
46
46
  }
@@ -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
 
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: 5.3.1
4
+ version: 5.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Sedlmair