svelte-on-rails 8.0.1 โ 8.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 +13 -6
- data/lib/svelte_on_rails/active_record_extensions.rb +15 -4
- data/lib/svelte_on_rails/lib/to_svelte.rb +37 -7
- data/lib/svelte_on_rails/view_helpers.rb +3 -3
- 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: 8888526927853e78465bc1bbda518d82a0a499c33a1d99d5ada3ea411c0baf70
|
4
|
+
data.tar.gz: 0c019007e8d68e48e659a47041a15af833d7bd1c1a8b0414af8a51d836a2397d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91f0eb2d62372a9a7b2337adbb209c6db8f0eade705fe50d4a1fef516cb856999cfa3753521422cab4476399769e0c43672f79d716e839f19097ae4bfa0b273a
|
7
|
+
data.tar.gz: f7e4e9c10f8cdcbed1e56087fc2470b4c82f575bbf730bc816656dcf03c98becacf97c6efd98936e5696c1e1625d03a2234e251cd0bc9d197888cd72a8e07f88
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ See: [Comparitions on the guide](https://svelte-on-rails.dev/about/why.html)
|
|
24
24
|
|
25
25
|
see [issues](https://gitlab.com/sedl/svelte-on-rails/-/issues)
|
26
26
|
|
27
|
-
# Description
|
27
|
+
# Description
|
28
28
|
|
29
29
|
Renders Svelte components server-side and, together with [@csedl/svelte-on-rails](https://www.npmjs.com/package/@csedl/svelte-on-rails),
|
30
30
|
hydrates the component on the frontend.
|
@@ -38,8 +38,9 @@ If you have issues, please open one, and contributors are welcome!
|
|
38
38
|
|
39
39
|
- tested on
|
40
40
|
- ruby 3.2.2 and rails 7.1
|
41
|
+
- Recommended: ruby 3x
|
41
42
|
- ruby 2.7.5 and rails 6.1
|
42
|
-
- vite@6 (v7 not supported, see issues)
|
43
|
+
- vite@6 (v7 not yet supported, see issues)
|
43
44
|
- turbolinks and hotwired/turbo
|
44
45
|
- vite_rails (the installer will install it by option --full or --vite)
|
45
46
|
- 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))
|
@@ -55,7 +56,9 @@ If you have issues, please open one, and contributors are welcome!
|
|
55
56
|
On ruby <3 Arguments are misinterpreted, see [issue-10](https://gitlab.com/sedl/svelte-on-rails/-/issues/10)
|
56
57
|
|
57
58
|
|
58
|
-
## Installation
|
59
|
+
## Installation on a existing app
|
60
|
+
|
61
|
+
=> To generate a two-minute, full-featured app, refer to the [guide/installer with options](https://svelte-on-rails.dev/installation/installer_options.html).
|
59
62
|
|
60
63
|
Required: `vite_rails` must be installed, it wants a `app/frontend` folder.
|
61
64
|
|
@@ -67,7 +70,7 @@ Within the app, add the gem
|
|
67
70
|
bundle add svelte-on-rails
|
68
71
|
```
|
69
72
|
|
70
|
-
and run the
|
73
|
+
and run the installer without options
|
71
74
|
|
72
75
|
```bash
|
73
76
|
rails g svelte_on_rails:install
|
@@ -89,13 +92,17 @@ Add it to the view
|
|
89
92
|
<%= svelte_component('HelloWorld', {title: 'Hello World'}) %>
|
90
93
|
```
|
91
94
|
|
92
|
-
And you will see
|
95
|
+
And you will see ยซSvelte Hello Worldยป on the browser! ๐ ๐ค
|
93
96
|
|
94
97
|
# Contributors welcome
|
95
98
|
|
96
99
|
see [Guide / run your first test](https://svelte-on-rails.dev/first_test.html)
|
97
100
|
|
101
|
+
# Special Thanks
|
102
|
+
|
103
|
+
- [vite_ruby](https://github.com/ElMassimo/vite_ruby)
|
104
|
+
- [react_on_rails](https://github.com/shakacode/react_on_rails)
|
98
105
|
|
99
106
|
## Licence
|
100
107
|
|
101
|
-
Copyright ยฉ 2025-
|
108
|
+
Copyright ยฉ 2025-2027 sedlmair.ch. Distributed by [MIT License](https://svelte-on-rails.dev/license.html)
|
@@ -9,8 +9,12 @@ module SvelteOnRails
|
|
9
9
|
@to_svelte ||= begin
|
10
10
|
|
11
11
|
cl = SvelteOnRails::Lib::SvelteAttributes
|
12
|
-
|
13
|
-
|
12
|
+
lab, enums, val = cl.new.calculate_instance(self, attributes, associations)
|
13
|
+
k = self.class.to_s.underscore
|
14
|
+
res = lab
|
15
|
+
res["#{k}_enums"] = enums if enums
|
16
|
+
res[k] = val
|
17
|
+
res
|
14
18
|
|
15
19
|
end
|
16
20
|
end
|
@@ -25,7 +29,10 @@ module SvelteOnRails
|
|
25
29
|
|
26
30
|
@to_svelte ||= begin
|
27
31
|
cl = SvelteOnRails::Lib::SvelteAttributes
|
28
|
-
|
32
|
+
lab, enums = cl.new.calculate_class(self, attributes, associations)
|
33
|
+
lab["#{self.to_s.underscore}_enums"] = enums if enums
|
34
|
+
lab
|
35
|
+
|
29
36
|
end
|
30
37
|
end
|
31
38
|
|
@@ -38,7 +45,11 @@ module SvelteOnRails
|
|
38
45
|
def to_svelte(*attributes, **associations)
|
39
46
|
@to_svelte ||= begin
|
40
47
|
cl = SvelteOnRails::Lib::SvelteAttributes
|
41
|
-
cl.new.calculate_relation(self, attributes, associations)
|
48
|
+
lab, enums, val = cl.new.calculate_relation(self, attributes, associations)
|
49
|
+
k = self.klass.to_s.underscore
|
50
|
+
lab[k.pluralize] = val
|
51
|
+
lab["#{k}_enums"] = enums if enums
|
52
|
+
lab
|
42
53
|
end
|
43
54
|
end
|
44
55
|
|
@@ -26,8 +26,6 @@ module SvelteOnRails
|
|
26
26
|
record
|
27
27
|
end
|
28
28
|
|
29
|
-
# set_labels(record.first, attributes)
|
30
|
-
|
31
29
|
values = recs2.map do |rec|
|
32
30
|
calculate_instance(rec, attributes, associations, call_stack: next_stack)
|
33
31
|
end
|
@@ -46,6 +44,8 @@ module SvelteOnRails
|
|
46
44
|
_key = attr.to_s
|
47
45
|
|
48
46
|
values[_key] = record.send(_key)
|
47
|
+
|
48
|
+
fetch_enum(record.class, attr)
|
49
49
|
end
|
50
50
|
|
51
51
|
associations.each do |key, val|
|
@@ -71,7 +71,7 @@ module SvelteOnRails
|
|
71
71
|
if recs.respond_to?(:each)
|
72
72
|
values[_key] = calculate_instance(
|
73
73
|
recs,
|
74
|
-
val.reject{|v|v.is_a?(Hash)},
|
74
|
+
val.reject { |v| v.is_a?(Hash) },
|
75
75
|
{},
|
76
76
|
call_stack: next_stack,
|
77
77
|
offset: _offset,
|
@@ -95,6 +95,7 @@ module SvelteOnRails
|
|
95
95
|
else
|
96
96
|
[
|
97
97
|
@labels,
|
98
|
+
@enums,
|
98
99
|
values
|
99
100
|
]
|
100
101
|
end
|
@@ -106,6 +107,9 @@ module SvelteOnRails
|
|
106
107
|
next_stack = call_stack + 1
|
107
108
|
|
108
109
|
set_labels(model, attributes, associations)
|
110
|
+
attributes.each do |attr|
|
111
|
+
fetch_enum(model, attr)
|
112
|
+
end
|
109
113
|
|
110
114
|
associations.each do |key, value|
|
111
115
|
reflect = model.reflect_on_association(key.to_s)
|
@@ -120,19 +124,28 @@ module SvelteOnRails
|
|
120
124
|
end
|
121
125
|
|
122
126
|
if call_stack == 0
|
123
|
-
|
127
|
+
[
|
128
|
+
@labels,
|
129
|
+
@enums
|
130
|
+
]
|
124
131
|
end
|
132
|
+
|
125
133
|
end
|
126
134
|
|
127
135
|
def calculate_relation(relation, attributes, associations)
|
128
136
|
set_labels(relation.klass, attributes)
|
137
|
+
attributes.each do |attr|
|
138
|
+
fetch_enum(relation.klass, attr)
|
139
|
+
end
|
129
140
|
r = relation.map do |rec|
|
130
141
|
calculate_instance(rec, attributes, associations, call_stack: 1)
|
131
142
|
end
|
132
143
|
|
133
|
-
|
134
|
-
|
135
|
-
|
144
|
+
[
|
145
|
+
@labels,
|
146
|
+
@enums,
|
147
|
+
r
|
148
|
+
]
|
136
149
|
|
137
150
|
end
|
138
151
|
|
@@ -188,6 +201,23 @@ module SvelteOnRails
|
|
188
201
|
end
|
189
202
|
end
|
190
203
|
|
204
|
+
def fetch_enum(model, attribute)
|
205
|
+
return unless model.respond_to?(:defined_enums)
|
206
|
+
raise ArgumentError, "attribute_name must be a symbol" unless attribute.is_a?(Symbol)
|
207
|
+
|
208
|
+
enums = model.defined_enums
|
209
|
+
return nil unless enums.key?(attribute.to_s)
|
210
|
+
|
211
|
+
@enums ||= {}
|
212
|
+
@enums[attribute.to_s] = enums[attribute.to_s].map do |k,v|
|
213
|
+
translation_key = "activerecord.attributes.#{model.model_name.i18n_key}.#{attribute}/#{k}"
|
214
|
+
[
|
215
|
+
k,
|
216
|
+
I18n.t(translation_key, default: k.humanize)
|
217
|
+
]
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
191
221
|
end
|
192
222
|
end
|
193
223
|
end
|
@@ -72,7 +72,7 @@ module SvelteOnRails
|
|
72
72
|
if args.length > 2
|
73
73
|
kw_err = true
|
74
74
|
elsif args.length >= 1
|
75
|
-
if args.last.keys & [:html, :options]
|
75
|
+
if (args.last.keys & [:html, :options]).present?
|
76
76
|
last_is_kwargs = true
|
77
77
|
if (args.last.keys - [:html, :options]).present?
|
78
78
|
kw_err = true
|
@@ -88,8 +88,8 @@ module SvelteOnRails
|
|
88
88
|
|
89
89
|
[
|
90
90
|
(first_is_props ? args.first : nil),
|
91
|
-
(last_is_kwargs ? args[1][:html] :
|
92
|
-
(last_is_kwargs ? args[1][:options] :
|
91
|
+
(last_is_kwargs ? args[1][:html] || {} : {}),
|
92
|
+
(last_is_kwargs ? args[1][:options] : {}),
|
93
93
|
]
|
94
94
|
end
|
95
95
|
|