actionview-svelte-handler 0.2.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.forgejo/workflows/javascript_police.yml +22 -0
- data/.forgejo/workflows/ruby_police.yml +27 -0
- data/.gitignore +14 -0
- data/.ruby-version +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +284 -0
- data/README.md +113 -17
- data/Steepfile +12 -0
- data/actionview-svelte-handler.gemspec +21 -0
- data/bin/test +5 -0
- data/build.esbuild.js +22 -0
- data/lib/generators/svelte/install_generator.rb +13 -0
- data/lib/generators/svelte/templates/install/initializer.rb +17 -0
- data/lib/svelte/errors.rb +151 -0
- data/lib/svelte/handler.rb +53 -41
- data/lib/svelte/helpers.rb +13 -3
- data/lib/svelte/js/.DO_NOT_MODIFY.md +2 -0
- data/lib/svelte/js/builder.js +122 -0
- data/lib/svelte/railtie.rb +5 -1
- data/lib/svelte/templates/assembler.js.erb +16 -0
- data/lib/svelte/templates/island.html.erb +20 -0
- data/lib/svelte/variabilization.rb +11 -0
- data/lib/svelte/version.rb +1 -1
- data/lib/svelte.rb +31 -2
- data/lib/tasks/svelte_tasks.rake +4 -0
- data/lib/ts/builder.ts +174 -0
- data/lib/ts/types/.DO_NOT_MODIFY.md +2 -0
- data/lib/ts/types/builder.d.ts +42 -0
- data/package-lock.json +6643 -0
- data/package.json +39 -0
- data/rbs_collection.lock.yaml +344 -0
- data/rbs_collection.yaml +18 -0
- data/sig/lib/svelte/errors.rbs +38 -0
- data/sig/lib/svelte/handler.rbs +9 -0
- data/sig/lib/svelte/helpers.rbs +7 -0
- data/sig/lib/svelte/version.rbs +3 -0
- data/sig/lib/svelte.rbs +19 -0
- data/svelte-on-rails.png +0 -0
- data/tsconfig.json +15 -0
- data/watch.esbuild.js +4 -0
- metadata +37 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6e128e00d55cf10c4227ef9962666d22945291c51908ba5944a921e9409f038
|
4
|
+
data.tar.gz: 89f864d3f18f58c4efce009b75f2dae79a88f0b9b5ccc6bce80db94e2910ef31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d465f91a8e4e24c80bf11485edcd4657de64f9f4a355c7d18ef204839eacd1168f3aa3d22b030432955b77355adbb126d61eba5d0dcb632039ef5e0cffcae95
|
7
|
+
data.tar.gz: fb274f310264f5b719231b65b703985f9b4ead1828d1b27d631e9321e80b4ba7bb5c78ae4662d8e51f5bfb42781ca43210419a20589a9465a8fb24fad41a87d7
|
@@ -0,0 +1,22 @@
|
|
1
|
+
name: JavaScript Police
|
2
|
+
on:
|
3
|
+
workflow_dispatch:
|
4
|
+
pull_request:
|
5
|
+
push:
|
6
|
+
branches: [ main ]
|
7
|
+
jobs:
|
8
|
+
lint_and_check_types:
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
steps:
|
11
|
+
- name: Checkout code
|
12
|
+
uses: actions/checkout@v4
|
13
|
+
- name: Set up JS
|
14
|
+
uses: https://github.com/actions/setup-node@v4
|
15
|
+
with:
|
16
|
+
node-version: latest
|
17
|
+
- name: Install dependencies
|
18
|
+
run: npm install
|
19
|
+
- name: Lint code for consistent style
|
20
|
+
run: npm run lint
|
21
|
+
- name: Build & check types
|
22
|
+
run: npm run build
|
@@ -0,0 +1,27 @@
|
|
1
|
+
name: Ruby Police
|
2
|
+
|
3
|
+
on:
|
4
|
+
workflow_dispatch:
|
5
|
+
pull_request:
|
6
|
+
push:
|
7
|
+
branches: [ main ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
lint_and_check_types:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
steps:
|
13
|
+
- name: Checkout code
|
14
|
+
uses: actions/checkout@v4
|
15
|
+
- name: Set up Ruby
|
16
|
+
uses: https://github.com/ruby/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: .ruby-version
|
19
|
+
bundler-cache: true
|
20
|
+
- name: Install Bundler
|
21
|
+
run: gem install bundler
|
22
|
+
- name: Lint code for consistent style
|
23
|
+
run: bundle exec standardrb --fix --format github
|
24
|
+
- name: Install RBS collection
|
25
|
+
run: bundle exec rbs collection install
|
26
|
+
- name: Check types
|
27
|
+
run: bundle exec steep check --jobs=24
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.3.0
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
3
|
+
|
4
|
+
# Specify your gem's dependencies in svelte.gemspec.
|
5
|
+
gemspec
|
6
|
+
|
7
|
+
# Start debugger with binding.b [https://github.com/ruby/debug]
|
8
|
+
# gem "debug", ">= 1.0.0"
|
9
|
+
|
10
|
+
gem "steep", "~> 1.7"
|
11
|
+
|
12
|
+
gem "standard", "~> 1.39"
|
13
|
+
|
14
|
+
gem "rbs", "~> 3.5"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,284 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
actionview-svelte-handler (0.4.1)
|
5
|
+
rails (>= 7.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actioncable (7.1.3.4)
|
11
|
+
actionpack (= 7.1.3.4)
|
12
|
+
activesupport (= 7.1.3.4)
|
13
|
+
nio4r (~> 2.0)
|
14
|
+
websocket-driver (>= 0.6.1)
|
15
|
+
zeitwerk (~> 2.6)
|
16
|
+
actionmailbox (7.1.3.4)
|
17
|
+
actionpack (= 7.1.3.4)
|
18
|
+
activejob (= 7.1.3.4)
|
19
|
+
activerecord (= 7.1.3.4)
|
20
|
+
activestorage (= 7.1.3.4)
|
21
|
+
activesupport (= 7.1.3.4)
|
22
|
+
mail (>= 2.7.1)
|
23
|
+
net-imap
|
24
|
+
net-pop
|
25
|
+
net-smtp
|
26
|
+
actionmailer (7.1.3.4)
|
27
|
+
actionpack (= 7.1.3.4)
|
28
|
+
actionview (= 7.1.3.4)
|
29
|
+
activejob (= 7.1.3.4)
|
30
|
+
activesupport (= 7.1.3.4)
|
31
|
+
mail (~> 2.5, >= 2.5.4)
|
32
|
+
net-imap
|
33
|
+
net-pop
|
34
|
+
net-smtp
|
35
|
+
rails-dom-testing (~> 2.2)
|
36
|
+
actionpack (7.1.3.4)
|
37
|
+
actionview (= 7.1.3.4)
|
38
|
+
activesupport (= 7.1.3.4)
|
39
|
+
nokogiri (>= 1.8.5)
|
40
|
+
racc
|
41
|
+
rack (>= 2.2.4)
|
42
|
+
rack-session (>= 1.0.1)
|
43
|
+
rack-test (>= 0.6.3)
|
44
|
+
rails-dom-testing (~> 2.2)
|
45
|
+
rails-html-sanitizer (~> 1.6)
|
46
|
+
actiontext (7.1.3.4)
|
47
|
+
actionpack (= 7.1.3.4)
|
48
|
+
activerecord (= 7.1.3.4)
|
49
|
+
activestorage (= 7.1.3.4)
|
50
|
+
activesupport (= 7.1.3.4)
|
51
|
+
globalid (>= 0.6.0)
|
52
|
+
nokogiri (>= 1.8.5)
|
53
|
+
actionview (7.1.3.4)
|
54
|
+
activesupport (= 7.1.3.4)
|
55
|
+
builder (~> 3.1)
|
56
|
+
erubi (~> 1.11)
|
57
|
+
rails-dom-testing (~> 2.2)
|
58
|
+
rails-html-sanitizer (~> 1.6)
|
59
|
+
activejob (7.1.3.4)
|
60
|
+
activesupport (= 7.1.3.4)
|
61
|
+
globalid (>= 0.3.6)
|
62
|
+
activemodel (7.1.3.4)
|
63
|
+
activesupport (= 7.1.3.4)
|
64
|
+
activerecord (7.1.3.4)
|
65
|
+
activemodel (= 7.1.3.4)
|
66
|
+
activesupport (= 7.1.3.4)
|
67
|
+
timeout (>= 0.4.0)
|
68
|
+
activestorage (7.1.3.4)
|
69
|
+
actionpack (= 7.1.3.4)
|
70
|
+
activejob (= 7.1.3.4)
|
71
|
+
activerecord (= 7.1.3.4)
|
72
|
+
activesupport (= 7.1.3.4)
|
73
|
+
marcel (~> 1.0)
|
74
|
+
activesupport (7.1.3.4)
|
75
|
+
base64
|
76
|
+
bigdecimal
|
77
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
78
|
+
connection_pool (>= 2.2.5)
|
79
|
+
drb
|
80
|
+
i18n (>= 1.6, < 2)
|
81
|
+
minitest (>= 5.1)
|
82
|
+
mutex_m
|
83
|
+
tzinfo (~> 2.0)
|
84
|
+
ast (2.4.2)
|
85
|
+
base64 (0.2.0)
|
86
|
+
bigdecimal (3.1.8)
|
87
|
+
builder (3.3.0)
|
88
|
+
concurrent-ruby (1.3.3)
|
89
|
+
connection_pool (2.4.1)
|
90
|
+
crass (1.0.6)
|
91
|
+
csv (3.3.0)
|
92
|
+
date (3.3.4)
|
93
|
+
drb (2.2.1)
|
94
|
+
erubi (1.13.0)
|
95
|
+
ffi (1.17.0-aarch64-linux-gnu)
|
96
|
+
ffi (1.17.0-arm-linux-gnu)
|
97
|
+
ffi (1.17.0-arm64-darwin)
|
98
|
+
ffi (1.17.0-x86-linux-gnu)
|
99
|
+
ffi (1.17.0-x86_64-darwin)
|
100
|
+
ffi (1.17.0-x86_64-linux-gnu)
|
101
|
+
fileutils (1.7.2)
|
102
|
+
globalid (1.2.1)
|
103
|
+
activesupport (>= 6.1)
|
104
|
+
i18n (1.14.5)
|
105
|
+
concurrent-ruby (~> 1.0)
|
106
|
+
io-console (0.7.2)
|
107
|
+
irb (1.14.0)
|
108
|
+
rdoc (>= 4.0.0)
|
109
|
+
reline (>= 0.4.2)
|
110
|
+
json (2.7.2)
|
111
|
+
language_server-protocol (3.17.0.3)
|
112
|
+
lint_roller (1.1.0)
|
113
|
+
listen (3.9.0)
|
114
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
115
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
116
|
+
logger (1.6.0)
|
117
|
+
loofah (2.22.0)
|
118
|
+
crass (~> 1.0.2)
|
119
|
+
nokogiri (>= 1.12.0)
|
120
|
+
mail (2.8.1)
|
121
|
+
mini_mime (>= 0.1.1)
|
122
|
+
net-imap
|
123
|
+
net-pop
|
124
|
+
net-smtp
|
125
|
+
marcel (1.0.4)
|
126
|
+
mini_mime (1.1.5)
|
127
|
+
minitest (5.24.1)
|
128
|
+
mutex_m (0.2.0)
|
129
|
+
net-imap (0.4.14)
|
130
|
+
date
|
131
|
+
net-protocol
|
132
|
+
net-pop (0.1.2)
|
133
|
+
net-protocol
|
134
|
+
net-protocol (0.2.2)
|
135
|
+
timeout
|
136
|
+
net-smtp (0.5.0)
|
137
|
+
net-protocol
|
138
|
+
nio4r (2.7.3)
|
139
|
+
nokogiri (1.16.7-aarch64-linux)
|
140
|
+
racc (~> 1.4)
|
141
|
+
nokogiri (1.16.7-arm-linux)
|
142
|
+
racc (~> 1.4)
|
143
|
+
nokogiri (1.16.7-arm64-darwin)
|
144
|
+
racc (~> 1.4)
|
145
|
+
nokogiri (1.16.7-x86-linux)
|
146
|
+
racc (~> 1.4)
|
147
|
+
nokogiri (1.16.7-x86_64-darwin)
|
148
|
+
racc (~> 1.4)
|
149
|
+
nokogiri (1.16.7-x86_64-linux)
|
150
|
+
racc (~> 1.4)
|
151
|
+
parallel (1.25.1)
|
152
|
+
parser (3.3.4.0)
|
153
|
+
ast (~> 2.4.1)
|
154
|
+
racc
|
155
|
+
psych (5.1.2)
|
156
|
+
stringio
|
157
|
+
racc (1.8.0)
|
158
|
+
rack (3.1.7)
|
159
|
+
rack-session (2.0.0)
|
160
|
+
rack (>= 3.0.0)
|
161
|
+
rack-test (2.1.0)
|
162
|
+
rack (>= 1.3)
|
163
|
+
rackup (2.1.0)
|
164
|
+
rack (>= 3)
|
165
|
+
webrick (~> 1.8)
|
166
|
+
rails (7.1.3.4)
|
167
|
+
actioncable (= 7.1.3.4)
|
168
|
+
actionmailbox (= 7.1.3.4)
|
169
|
+
actionmailer (= 7.1.3.4)
|
170
|
+
actionpack (= 7.1.3.4)
|
171
|
+
actiontext (= 7.1.3.4)
|
172
|
+
actionview (= 7.1.3.4)
|
173
|
+
activejob (= 7.1.3.4)
|
174
|
+
activemodel (= 7.1.3.4)
|
175
|
+
activerecord (= 7.1.3.4)
|
176
|
+
activestorage (= 7.1.3.4)
|
177
|
+
activesupport (= 7.1.3.4)
|
178
|
+
bundler (>= 1.15.0)
|
179
|
+
railties (= 7.1.3.4)
|
180
|
+
rails-dom-testing (2.2.0)
|
181
|
+
activesupport (>= 5.0.0)
|
182
|
+
minitest
|
183
|
+
nokogiri (>= 1.6)
|
184
|
+
rails-html-sanitizer (1.6.0)
|
185
|
+
loofah (~> 2.21)
|
186
|
+
nokogiri (~> 1.14)
|
187
|
+
railties (7.1.3.4)
|
188
|
+
actionpack (= 7.1.3.4)
|
189
|
+
activesupport (= 7.1.3.4)
|
190
|
+
irb
|
191
|
+
rackup (>= 1.0.0)
|
192
|
+
rake (>= 12.2)
|
193
|
+
thor (~> 1.0, >= 1.2.2)
|
194
|
+
zeitwerk (~> 2.6)
|
195
|
+
rainbow (3.1.1)
|
196
|
+
rake (13.2.1)
|
197
|
+
rb-fsevent (0.11.2)
|
198
|
+
rb-inotify (0.11.1)
|
199
|
+
ffi (~> 1.0)
|
200
|
+
rbs (3.5.2)
|
201
|
+
logger
|
202
|
+
rdoc (6.7.0)
|
203
|
+
psych (>= 4.0.0)
|
204
|
+
regexp_parser (2.9.2)
|
205
|
+
reline (0.5.9)
|
206
|
+
io-console (~> 0.5)
|
207
|
+
rexml (3.3.4)
|
208
|
+
strscan
|
209
|
+
rubocop (1.64.1)
|
210
|
+
json (~> 2.3)
|
211
|
+
language_server-protocol (>= 3.17.0)
|
212
|
+
parallel (~> 1.10)
|
213
|
+
parser (>= 3.3.0.2)
|
214
|
+
rainbow (>= 2.2.2, < 4.0)
|
215
|
+
regexp_parser (>= 1.8, < 3.0)
|
216
|
+
rexml (>= 3.2.5, < 4.0)
|
217
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
218
|
+
ruby-progressbar (~> 1.7)
|
219
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
220
|
+
rubocop-ast (1.31.3)
|
221
|
+
parser (>= 3.3.1.0)
|
222
|
+
rubocop-performance (1.21.1)
|
223
|
+
rubocop (>= 1.48.1, < 2.0)
|
224
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
225
|
+
ruby-progressbar (1.13.0)
|
226
|
+
securerandom (0.3.1)
|
227
|
+
standard (1.39.2)
|
228
|
+
language_server-protocol (~> 3.17.0.2)
|
229
|
+
lint_roller (~> 1.0)
|
230
|
+
rubocop (~> 1.64.0)
|
231
|
+
standard-custom (~> 1.0.0)
|
232
|
+
standard-performance (~> 1.4)
|
233
|
+
standard-custom (1.0.2)
|
234
|
+
lint_roller (~> 1.0)
|
235
|
+
rubocop (~> 1.50)
|
236
|
+
standard-performance (1.4.0)
|
237
|
+
lint_roller (~> 1.1)
|
238
|
+
rubocop-performance (~> 1.21.0)
|
239
|
+
steep (1.7.1)
|
240
|
+
activesupport (>= 5.1)
|
241
|
+
concurrent-ruby (>= 1.1.10)
|
242
|
+
csv (>= 3.0.9)
|
243
|
+
fileutils (>= 1.1.0)
|
244
|
+
json (>= 2.1.0)
|
245
|
+
language_server-protocol (>= 3.15, < 4.0)
|
246
|
+
listen (~> 3.0)
|
247
|
+
logger (>= 1.3.0)
|
248
|
+
parser (>= 3.1)
|
249
|
+
rainbow (>= 2.2.2, < 4.0)
|
250
|
+
rbs (>= 3.5.0.pre)
|
251
|
+
securerandom (>= 0.1)
|
252
|
+
strscan (>= 1.0.0)
|
253
|
+
terminal-table (>= 2, < 4)
|
254
|
+
stringio (3.1.1)
|
255
|
+
strscan (3.1.0)
|
256
|
+
terminal-table (3.0.2)
|
257
|
+
unicode-display_width (>= 1.1.1, < 3)
|
258
|
+
thor (1.3.1)
|
259
|
+
timeout (0.4.1)
|
260
|
+
tzinfo (2.0.6)
|
261
|
+
concurrent-ruby (~> 1.0)
|
262
|
+
unicode-display_width (2.5.0)
|
263
|
+
webrick (1.8.1)
|
264
|
+
websocket-driver (0.7.6)
|
265
|
+
websocket-extensions (>= 0.1.0)
|
266
|
+
websocket-extensions (0.1.5)
|
267
|
+
zeitwerk (2.6.16)
|
268
|
+
|
269
|
+
PLATFORMS
|
270
|
+
aarch64-linux
|
271
|
+
arm-linux
|
272
|
+
arm64-darwin
|
273
|
+
x86-linux
|
274
|
+
x86_64-darwin
|
275
|
+
x86_64-linux
|
276
|
+
|
277
|
+
DEPENDENCIES
|
278
|
+
actionview-svelte-handler!
|
279
|
+
rbs (~> 3.5)
|
280
|
+
standard (~> 1.39)
|
281
|
+
steep (~> 1.7)
|
282
|
+
|
283
|
+
BUNDLED WITH
|
284
|
+
2.5.11
|
data/README.md
CHANGED
@@ -1,14 +1,27 @@
|
|
1
|
-
|
1
|
+
<img src="https://codeberg.org/reesericci/actionview-svelte-handler/raw/branch/main/svelte-on-rails.png" width="100px">
|
2
2
|
|
3
|
-
|
3
|
+
# `actionview-svelte-handler`
|
4
|
+
|
5
|
+
[![Copyleft License: LGPL-3.0-or-later](https://img.shields.io/badge/%F0%9F%84%AF_copyleft-LGPL--3.0--or--later-black)](https://spdx.org/licenses/LGPL-3.0-or-later.html)
|
6
|
+
[![Gem Version](https://img.shields.io/gem/v/actionview-svelte-handler)](https://rubygems.org/gems/actionview-svelte-handler)
|
7
|
+
<img src="https://web.badges.world/badges/operated/ruby3.png" alt="Ruby Powered" height="20px" style="image-rendering: pixelated;">
|
8
|
+
|
9
|
+
`actionview-svelte-handler` is a template handler for Action View that allows you to create [Svelte](https://svelte.dev) views in Rails applications with ease.
|
4
10
|
|
5
11
|
## Usage
|
6
12
|
|
7
|
-
Add `.html.svelte` views to your application instead of `.html.erb`.
|
13
|
+
Add `.html.svelte` views to your application instead of `.html.erb`.
|
14
|
+
|
15
|
+
> [!CAUTION]
|
16
|
+
> This will make ERB helpers unavailable because Svelte is registered as a template handler, replacing ERB when it is used.
|
8
17
|
|
9
|
-
To pass props, use the `Svelte.props` object in your controller then access
|
18
|
+
To pass props, use the `Svelte.props` object in your controller (or set instance variables), and then access them as a store with `$props`.
|
10
19
|
|
11
|
-
|
20
|
+
### Example usage
|
21
|
+
|
22
|
+
#### Controller
|
23
|
+
|
24
|
+
`app/controllers/users_controller.rb`:
|
12
25
|
|
13
26
|
```ruby
|
14
27
|
def show
|
@@ -16,7 +29,9 @@ def show
|
|
16
29
|
end
|
17
30
|
```
|
18
31
|
|
19
|
-
|
32
|
+
#### View
|
33
|
+
|
34
|
+
`app/views/users/show.html.svelte`:
|
20
35
|
|
21
36
|
```html
|
22
37
|
<script>
|
@@ -34,24 +49,105 @@ end
|
|
34
49
|
</style>
|
35
50
|
```
|
36
51
|
|
52
|
+
### Configuration
|
53
|
+
|
54
|
+
Configuration options can be found in `config/initializers/svelte.rb`. The following is a list of options and some information:
|
55
|
+
|
56
|
+
| Option with type | Description | Default |
|
57
|
+
| ------------------- | ---------------------------------------------------------------------- | ----------------------------------- |
|
58
|
+
| `ssr <bool>` | Global server-side rendering. Does not override the svelte[ssr] local. | `true` |
|
59
|
+
| `aliases <Hash[Symbol, String]>` | Path aliases when importing from Svelte views. | See [path aliases](#path-aliases) |
|
60
|
+
| `preprocess <Hash[String \| Symbol, String]>` | Configuration for [svelte-preprocess](https://github.com/sveltejs/svelte-preprocess/blob/main/docs/usage.md) | `{}` |
|
61
|
+
|
62
|
+
#### Example usage (with `Svelte.configure` block)
|
63
|
+
|
64
|
+
`config/initializers/svelte.rb`:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
Svelte.configure do |config|
|
68
|
+
config.ssr = true
|
69
|
+
config.aliases = {
|
70
|
+
:$views => Rails.root.join("app", "views")
|
71
|
+
}
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
### Locals
|
76
|
+
|
77
|
+
To set per-render options, we use a set of locals underneath the `svelte` hash. Locals are always the highest precedence
|
78
|
+
|
79
|
+
| Option with type | Description | Default |
|
80
|
+
| ------------------- | -------------------------------------------------------------------------- | ------------------------------------- |
|
81
|
+
| `ssr <bool>` | Server-side prerendering | `true` |
|
82
|
+
| `island <Hash[String, String]>` | HTML attributes for [is-land](https://github.com/11ty/is-land) | `{ "on:visible": "", "on:idle": "" }` |
|
83
|
+
|
84
|
+
#### Example usage
|
85
|
+
|
86
|
+
`app/controllers/example_controller.rb`:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
render "view", locals: { svelte: { ssr: false } }
|
90
|
+
```
|
91
|
+
|
92
|
+
### Variants
|
93
|
+
|
94
|
+
To configure server-side rendering at a file level, you can use the `client` and `server` variants. Just set your file name like in the example.
|
95
|
+
|
96
|
+
#### Example usage
|
97
|
+
|
98
|
+
`app/views/example/show.html+client.svelte`
|
99
|
+
|
100
|
+
`app/views/example/show.html+server.svelte`
|
101
|
+
|
102
|
+
`app/controllers/example_controller.rb`:
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
render "view", variant: "client"
|
106
|
+
```
|
107
|
+
|
108
|
+
### Path aliases
|
109
|
+
|
110
|
+
Path aliases are used as quick references from your Svelte views to key paths in your application. They are primarily utilized when importing other Svelte components (i.e. partials).
|
111
|
+
|
112
|
+
The list of path aliases set by the generator is as follows:
|
113
|
+
|
114
|
+
| Alias | Resolution |
|
115
|
+
| -------- | -------------------------------- |
|
116
|
+
| `$root` | `Rails.root` |
|
117
|
+
| `$app` | `Rails.root.join "app"` |
|
118
|
+
| `$views` | `Rails.root.join "app", "views"` |
|
119
|
+
|
120
|
+
#### Example usage
|
121
|
+
|
122
|
+
```javascript
|
123
|
+
import Card from "$views/application/card.html.svelte"
|
124
|
+
```
|
125
|
+
|
37
126
|
## Installation
|
38
127
|
|
39
|
-
1. Ensure you have
|
128
|
+
1. Ensure you have [Node.js >=v12.16.0](https://nodejs.org) and [NPM](https://npmjs.com) in your `$PATH`
|
40
129
|
|
41
|
-
3.
|
130
|
+
3. Add the `actionview-svelte-handler` gem to your Gemfile by executing:
|
42
131
|
|
43
132
|
```bash
|
44
|
-
bundle add actionview-svelte-
|
133
|
+
bundle add actionview-svelte-handler
|
45
134
|
```
|
46
135
|
|
47
|
-
4. And then
|
136
|
+
4. And then execute the generator:
|
48
137
|
|
49
|
-
```
|
50
|
-
|
51
|
-
<!-- other head content -->
|
52
|
-
<%= svelte_tags %>
|
53
|
-
</head>
|
138
|
+
```bash
|
139
|
+
bin/rails generate svelte:install
|
54
140
|
```
|
55
141
|
|
56
|
-
|
57
|
-
|
142
|
+
5. Enjoy!
|
143
|
+
|
144
|
+
## Copyright
|
145
|
+
|
146
|
+
Copyright (C) 2024 [Software Freedom Conservancy](https://sfconservancy.org/assignment/603092cf-aeeb-4ee3-a5e0-903bd14805a8/) and Action View Svelte Handler contributors
|
147
|
+
|
148
|
+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
149
|
+
|
150
|
+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
151
|
+
|
152
|
+
You should have received a copy of the GNU Lesser General Public License along with this program. If not, see https://www.gnu.org/licenses/.
|
153
|
+
|
data/Steepfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative "lib/svelte/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "actionview-svelte-handler"
|
5
|
+
spec.version = Svelte::VERSION
|
6
|
+
spec.authors = ["reesericci"]
|
7
|
+
spec.email = ["me@reeseric.ci"]
|
8
|
+
spec.homepage = "https://codeberg.org/reesericci/actionview-svelte-handler"
|
9
|
+
spec.summary = "Create .svelte views seamlessly in Rails applications"
|
10
|
+
spec.description = "Documentation is available at #{spec.homepage}"
|
11
|
+
spec.license = "LGPL-v3.0-or-later"
|
12
|
+
|
13
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
14
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
15
|
+
|
16
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
17
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
end
|
19
|
+
|
20
|
+
spec.add_dependency "rails", ">= 7.0"
|
21
|
+
end
|
data/bin/test
ADDED
data/build.esbuild.js
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
import * as esbuild from 'esbuild'
|
2
|
+
|
3
|
+
const buildOpts = {
|
4
|
+
entryPoints: ['lib/ts/*.ts'],
|
5
|
+
bundle: false,
|
6
|
+
outdir: 'lib/svelte/js',
|
7
|
+
format: 'esm',
|
8
|
+
write: true,
|
9
|
+
platform: 'node',
|
10
|
+
banner: {
|
11
|
+
js: `/*
|
12
|
+
IF YOU ARE READING THIS, YOU ARE VIEWING THE BUILT JS FROM THE SOURCE TYPESCRIPT AT ../ts/ .
|
13
|
+
|
14
|
+
DO NOT MODIFY.
|
15
|
+
*/
|
16
|
+
`
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
await esbuild.build(buildOpts)
|
21
|
+
|
22
|
+
export default buildOpts
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Svelte::InstallGenerator < Rails::Generators::Base
|
2
|
+
desc "This generator installs actionview-svelte-handler"
|
3
|
+
|
4
|
+
source_root File.expand_path("templates/install", __dir__)
|
5
|
+
|
6
|
+
def install
|
7
|
+
copy_file "initializer.rb", "config/initializers/svelte.rb"
|
8
|
+
insert_into_file "app/views/layouts/application.html.erb",
|
9
|
+
" <%= svelte_tags %>\n",
|
10
|
+
before: "</head>"
|
11
|
+
`npm install #{Svelte.gem_dir} --install-links --save=false`
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Svelte.configure do |config|
|
2
|
+
# @note overridable at render time with svelte[:ssr] local
|
3
|
+
# @default true
|
4
|
+
# @return [Boolean] whether server-side rendering is enabled globally
|
5
|
+
config.ssr = true
|
6
|
+
|
7
|
+
# @return [Hash] path aliases available in ESM imports in Svelte files
|
8
|
+
config.aliases = {
|
9
|
+
:$root => Rails.root,
|
10
|
+
:$app => Rails.root.join("app"),
|
11
|
+
:$views => Rails.root.join("app", "views")
|
12
|
+
}
|
13
|
+
|
14
|
+
# @default {}
|
15
|
+
# @return [Hash] of your Svelte preprocess configuration
|
16
|
+
config.preprocess = {}
|
17
|
+
end
|