actionview-svelte-handler 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.md +157 -0
- data/README.md +57 -0
- data/Rakefile +3 -0
- data/lib/svelte/handler.rb +47 -0
- data/lib/svelte/helpers.rb +16 -0
- data/lib/svelte/railtie.rb +13 -0
- data/lib/svelte/version.rb +3 -0
- data/lib/svelte.rb +11 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8a8d743d73bb7a9c2d20b16c9ba153ee83bb558800780f9913ed92edd6b9c3f5
|
4
|
+
data.tar.gz: 2b506e0b2402d4c236e24caaf1d8ee09db301585568bfbbb3f5e68c90dd21e3a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 37254f91eb9aded2426d894cf44047af5b0d31c73f99ec9946aff73518301b24d537c63888151e1a542fcd725360036de91551450893c83337f7dba3a87de1f0
|
7
|
+
data.tar.gz: 1536e077c112bd44b1785792892f39f0cd5ea4057bf5a23ee6758cdcd94631ce93fd2ff787b4164a7d99648f64fd49f2c17064f32353069cfd995fe78006821c
|
data/LICENSE.md
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
# GNU LESSER GENERAL PUBLIC LICENSE
|
2
|
+
|
3
|
+
Version 3, 29 June 2007
|
4
|
+
|
5
|
+
Copyright (C) 2007 Free Software Foundation, Inc.
|
6
|
+
<https://fsf.org/>
|
7
|
+
|
8
|
+
Everyone is permitted to copy and distribute verbatim copies of this
|
9
|
+
license document, but changing it is not allowed.
|
10
|
+
|
11
|
+
This version of the GNU Lesser General Public License incorporates the
|
12
|
+
terms and conditions of version 3 of the GNU General Public License,
|
13
|
+
supplemented by the additional permissions listed below.
|
14
|
+
|
15
|
+
## 0. Additional Definitions.
|
16
|
+
|
17
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
18
|
+
General Public License, and the "GNU GPL" refers to version 3 of the
|
19
|
+
GNU General Public License.
|
20
|
+
|
21
|
+
"The Library" refers to a covered work governed by this License, other
|
22
|
+
than an Application or a Combined Work as defined below.
|
23
|
+
|
24
|
+
An "Application" is any work that makes use of an interface provided
|
25
|
+
by the Library, but which is not otherwise based on the Library.
|
26
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
27
|
+
of using an interface provided by the Library.
|
28
|
+
|
29
|
+
A "Combined Work" is a work produced by combining or linking an
|
30
|
+
Application with the Library. The particular version of the Library
|
31
|
+
with which the Combined Work was made is also called the "Linked
|
32
|
+
Version".
|
33
|
+
|
34
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
35
|
+
Corresponding Source for the Combined Work, excluding any source code
|
36
|
+
for portions of the Combined Work that, considered in isolation, are
|
37
|
+
based on the Application, and not on the Linked Version.
|
38
|
+
|
39
|
+
The "Corresponding Application Code" for a Combined Work means the
|
40
|
+
object code and/or source code for the Application, including any data
|
41
|
+
and utility programs needed for reproducing the Combined Work from the
|
42
|
+
Application, but excluding the System Libraries of the Combined Work.
|
43
|
+
|
44
|
+
## 1. Exception to Section 3 of the GNU GPL.
|
45
|
+
|
46
|
+
You may convey a covered work under sections 3 and 4 of this License
|
47
|
+
without being bound by section 3 of the GNU GPL.
|
48
|
+
|
49
|
+
## 2. Conveying Modified Versions.
|
50
|
+
|
51
|
+
If you modify a copy of the Library, and, in your modifications, a
|
52
|
+
facility refers to a function or data to be supplied by an Application
|
53
|
+
that uses the facility (other than as an argument passed when the
|
54
|
+
facility is invoked), then you may convey a copy of the modified
|
55
|
+
version:
|
56
|
+
|
57
|
+
- a) under this License, provided that you make a good faith effort
|
58
|
+
to ensure that, in the event an Application does not supply the
|
59
|
+
function or data, the facility still operates, and performs
|
60
|
+
whatever part of its purpose remains meaningful, or
|
61
|
+
- b) under the GNU GPL, with none of the additional permissions of
|
62
|
+
this License applicable to that copy.
|
63
|
+
|
64
|
+
## 3. Object Code Incorporating Material from Library Header Files.
|
65
|
+
|
66
|
+
The object code form of an Application may incorporate material from a
|
67
|
+
header file that is part of the Library. You may convey such object
|
68
|
+
code under terms of your choice, provided that, if the incorporated
|
69
|
+
material is not limited to numerical parameters, data structure
|
70
|
+
layouts and accessors, or small macros, inline functions and templates
|
71
|
+
(ten or fewer lines in length), you do both of the following:
|
72
|
+
|
73
|
+
- a) Give prominent notice with each copy of the object code that
|
74
|
+
the Library is used in it and that the Library and its use are
|
75
|
+
covered by this License.
|
76
|
+
- b) Accompany the object code with a copy of the GNU GPL and this
|
77
|
+
license document.
|
78
|
+
|
79
|
+
## 4. Combined Works.
|
80
|
+
|
81
|
+
You may convey a Combined Work under terms of your choice that, taken
|
82
|
+
together, effectively do not restrict modification of the portions of
|
83
|
+
the Library contained in the Combined Work and reverse engineering for
|
84
|
+
debugging such modifications, if you also do each of the following:
|
85
|
+
|
86
|
+
- a) Give prominent notice with each copy of the Combined Work that
|
87
|
+
the Library is used in it and that the Library and its use are
|
88
|
+
covered by this License.
|
89
|
+
- b) Accompany the Combined Work with a copy of the GNU GPL and this
|
90
|
+
license document.
|
91
|
+
- c) For a Combined Work that displays copyright notices during
|
92
|
+
execution, include the copyright notice for the Library among
|
93
|
+
these notices, as well as a reference directing the user to the
|
94
|
+
copies of the GNU GPL and this license document.
|
95
|
+
- d) Do one of the following:
|
96
|
+
- 0) Convey the Minimal Corresponding Source under the terms of
|
97
|
+
this License, and the Corresponding Application Code in a form
|
98
|
+
suitable for, and under terms that permit, the user to
|
99
|
+
recombine or relink the Application with a modified version of
|
100
|
+
the Linked Version to produce a modified Combined Work, in the
|
101
|
+
manner specified by section 6 of the GNU GPL for conveying
|
102
|
+
Corresponding Source.
|
103
|
+
- 1) Use a suitable shared library mechanism for linking with
|
104
|
+
the Library. A suitable mechanism is one that (a) uses at run
|
105
|
+
time a copy of the Library already present on the user's
|
106
|
+
computer system, and (b) will operate properly with a modified
|
107
|
+
version of the Library that is interface-compatible with the
|
108
|
+
Linked Version.
|
109
|
+
- e) Provide Installation Information, but only if you would
|
110
|
+
otherwise be required to provide such information under section 6
|
111
|
+
of the GNU GPL, and only to the extent that such information is
|
112
|
+
necessary to install and execute a modified version of the
|
113
|
+
Combined Work produced by recombining or relinking the Application
|
114
|
+
with a modified version of the Linked Version. (If you use option
|
115
|
+
4d0, the Installation Information must accompany the Minimal
|
116
|
+
Corresponding Source and Corresponding Application Code. If you
|
117
|
+
use option 4d1, you must provide the Installation Information in
|
118
|
+
the manner specified by section 6 of the GNU GPL for conveying
|
119
|
+
Corresponding Source.)
|
120
|
+
|
121
|
+
## 5. Combined Libraries.
|
122
|
+
|
123
|
+
You may place library facilities that are a work based on the Library
|
124
|
+
side by side in a single library together with other library
|
125
|
+
facilities that are not Applications and are not covered by this
|
126
|
+
License, and convey such a combined library under terms of your
|
127
|
+
choice, if you do both of the following:
|
128
|
+
|
129
|
+
- a) Accompany the combined library with a copy of the same work
|
130
|
+
based on the Library, uncombined with any other library
|
131
|
+
facilities, conveyed under the terms of this License.
|
132
|
+
- b) Give prominent notice with the combined library that part of it
|
133
|
+
is a work based on the Library, and explaining where to find the
|
134
|
+
accompanying uncombined form of the same work.
|
135
|
+
|
136
|
+
## 6. Revised Versions of the GNU Lesser General Public License.
|
137
|
+
|
138
|
+
The Free Software Foundation may publish revised and/or new versions
|
139
|
+
of the GNU Lesser General Public License from time to time. Such new
|
140
|
+
versions will be similar in spirit to the present version, but may
|
141
|
+
differ in detail to address new problems or concerns.
|
142
|
+
|
143
|
+
Each version is given a distinguishing version number. If the Library
|
144
|
+
as you received it specifies that a certain numbered version of the
|
145
|
+
GNU Lesser General Public License "or any later version" applies to
|
146
|
+
it, you have the option of following the terms and conditions either
|
147
|
+
of that published version or of any later version published by the
|
148
|
+
Free Software Foundation. If the Library as you received it does not
|
149
|
+
specify a version number of the GNU Lesser General Public License, you
|
150
|
+
may choose any version of the GNU Lesser General Public License ever
|
151
|
+
published by the Free Software Foundation.
|
152
|
+
|
153
|
+
If the Library as you received it specifies that a proxy can decide
|
154
|
+
whether future versions of the GNU Lesser General Public License shall
|
155
|
+
apply, that proxy's public statement of acceptance of any version is
|
156
|
+
permanent authorization for you to choose that version for the
|
157
|
+
Library.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# actionview-svelte-handler
|
2
|
+
|
3
|
+
Create `.svelte` views seamlessly in Rails applications.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Add `.html.svelte` views to your application instead of `.html.erb`. Note that ERB helpers will cease to be available.
|
8
|
+
|
9
|
+
To pass props, use the `Svelte.props` object in your controller then access it like a store with `$props`:
|
10
|
+
|
11
|
+
`users_controller.rb`:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
def show
|
15
|
+
Svelte.props[:user] = User.find_by(username: params[:username])
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
`show.html.svelte`:
|
20
|
+
|
21
|
+
```html
|
22
|
+
<script>
|
23
|
+
let name = $props.user.name
|
24
|
+
$: mailto = "mailto://" + $props.user.email
|
25
|
+
</script>
|
26
|
+
|
27
|
+
<h1>Hello, {name}</h1>
|
28
|
+
<a href={mailto}>{$props.user.email}</a>
|
29
|
+
|
30
|
+
<style>
|
31
|
+
h1 {
|
32
|
+
color: red
|
33
|
+
}
|
34
|
+
</style>
|
35
|
+
```
|
36
|
+
|
37
|
+
## Installation
|
38
|
+
|
39
|
+
1. Ensure you have the [Bun](https://bun.sh) JavaScript runtime in your `$PATH`
|
40
|
+
|
41
|
+
3. Execute:
|
42
|
+
|
43
|
+
```bash
|
44
|
+
bundle add actionview-svelte-helper
|
45
|
+
```
|
46
|
+
|
47
|
+
4. And then add the `svelte_tags` helper at the end of the `<head>` in `application.html.erb`:
|
48
|
+
|
49
|
+
```erb
|
50
|
+
<head>
|
51
|
+
<!-- other head content -->
|
52
|
+
<%= svelte_tags %>
|
53
|
+
</head>
|
54
|
+
```
|
55
|
+
|
56
|
+
## License
|
57
|
+
The gem is available as open source under the terms of the [LGPL License](https://opensource.org/license/lgpl-3-0).
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
module Svelte
|
2
|
+
class Handler < ActionView::Template::Handlers::Raw
|
3
|
+
include ActionView::Helpers::JavaScriptHelper
|
4
|
+
|
5
|
+
def call(template, source)
|
6
|
+
file = Tempfile.new
|
7
|
+
src = Tempfile.new
|
8
|
+
src.write source.b
|
9
|
+
src.rewind
|
10
|
+
|
11
|
+
file.write <<-JS
|
12
|
+
import { compile } from 'svelte/compiler';
|
13
|
+
|
14
|
+
const src = await Bun.file("#{src.path}").text()
|
15
|
+
const result = compile(src, {generate: "dom", name: "Component", css: "injected", sveltePath: "https://esm.sh/svelte"})
|
16
|
+
|
17
|
+
process.stdout.write(JSON.stringify(result))
|
18
|
+
JS
|
19
|
+
|
20
|
+
file.rewind
|
21
|
+
|
22
|
+
compiled = JSON.parse(%x(bun run #{file.path})).deep_symbolize_keys
|
23
|
+
|
24
|
+
source = <<-HTML
|
25
|
+
<is-land on:visible on:idle>
|
26
|
+
<template data-island>
|
27
|
+
<div id="svelte-app-client">
|
28
|
+
</div>
|
29
|
+
|
30
|
+
<script type="module">
|
31
|
+
#{compiled.dig(:js, :code)}
|
32
|
+
|
33
|
+
new Component({ target: document.getElementById("svelte-app-client") });
|
34
|
+
</script>
|
35
|
+
|
36
|
+
</template>
|
37
|
+
</is-land>
|
38
|
+
HTML
|
39
|
+
|
40
|
+
super
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.call(template, source)
|
44
|
+
new.call(template, source)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Svelte
|
2
|
+
module Helpers
|
3
|
+
include ActionView::Helpers::JavaScriptHelper
|
4
|
+
def svelte_tags
|
5
|
+
js = <<-JS
|
6
|
+
import "https://esm.sh/@11ty/is-land";
|
7
|
+
import "https://esm.sh/@11ty/is-land/is-land-autoinit.js";
|
8
|
+
import { readable } from "https://esm.sh/svelte/store"
|
9
|
+
|
10
|
+
window.props = readable(JSON.parse("#{j(Svelte.props.to_json)}"))
|
11
|
+
JS
|
12
|
+
|
13
|
+
tag.script(js.html_safe, type: "module")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "svelte/handler"
|
2
|
+
require "svelte/helpers"
|
3
|
+
|
4
|
+
module Svelte
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
initializer "svelte.register_actionview" do
|
7
|
+
ActiveSupport.on_load :action_view do
|
8
|
+
ActionView::Template.register_template_handler :svelte, Svelte::Handler
|
9
|
+
ActionView::Base.send :include, Svelte::Helpers
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/svelte.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "svelte/railtie"
|
2
|
+
require "svelte/handler"
|
3
|
+
require "svelte/helpers"
|
4
|
+
require "svelte/version"
|
5
|
+
require "active_support/isolated_execution_state"
|
6
|
+
|
7
|
+
module Svelte
|
8
|
+
def self.props
|
9
|
+
ActiveSupport::IsolatedExecutionState[:svelte_props] ||= {}
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: actionview-svelte-handler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- reesericci
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-07-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '7.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '7.0'
|
27
|
+
description: Documentation is available at https://codeberg.org/reesericci/actionview-svelte-handler
|
28
|
+
email:
|
29
|
+
- me@reeseric.ci
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- LICENSE.md
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- lib/svelte.rb
|
38
|
+
- lib/svelte/handler.rb
|
39
|
+
- lib/svelte/helpers.rb
|
40
|
+
- lib/svelte/railtie.rb
|
41
|
+
- lib/svelte/version.rb
|
42
|
+
homepage: https://codeberg.org/reesericci/actionview-svelte-handler
|
43
|
+
licenses:
|
44
|
+
- LGPL-v3.0-or-later
|
45
|
+
metadata:
|
46
|
+
homepage_uri: https://codeberg.org/reesericci/actionview-svelte-handler
|
47
|
+
source_code_uri: https://codeberg.org/reesericci/actionview-svelte-handler
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubygems_version: 3.5.9
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: Create .svelte views seamlessly in Rails applications
|
67
|
+
test_files: []
|