dlnk_toast 0.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 +7 -0
- data/CHANGELOG.md +14 -0
- data/LICENSE +21 -0
- data/README.md +109 -0
- data/app/assets/stylesheets/dlnk_toast/application.css +142 -0
- data/app/helpers/dlnk_toast/toast_helper.rb +7 -0
- data/app/javascript/dlnk_toast/toast_controller.js +71 -0
- data/app/views/dlnk_toast/_toast.html.erb +51 -0
- data/config/locales/en.yml +3 -0
- data/config/locales/fr.yml +3 -0
- data/lib/dlnk_toast/configuration.rb +17 -0
- data/lib/dlnk_toast/engine.rb +22 -0
- data/lib/dlnk_toast/version.rb +3 -0
- data/lib/dlnk_toast.rb +6 -0
- data/lib/generators/dlnk_toast/install/install_generator.rb +44 -0
- data/lib/generators/dlnk_toast/install/templates/initializer.rb +7 -0
- metadata +103 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 79d9562b09be7d950804a9a8ef92b03639b46ffc0482a1cc2cd2521ce6b3b258
|
|
4
|
+
data.tar.gz: f0d679777b69412f81931ab7bde6abc862bb9a0d113fd035422f33cb39067d51
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 47c4823b8cc92e1e3189dcc6d31a678129f6272817dac0b708f8c4195bdeccaf195320f2564cb4a7c7048ae68d7cf94ad289040616f96843e268081526de7cfc
|
|
7
|
+
data.tar.gz: 35f1ca56f77df72772c85efc1e9675088a262d30bbe0a3fa13ff6927efcfcfc3b4795af2bf1527baeefdf920b4fa8db447e7a56ce42aae577c9672b57e3ac788
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.1.0] - 2026-02-24
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Initial release
|
|
7
|
+
- Flash-based toast notifications with notice/alert support
|
|
8
|
+
- Stimulus controller for pause/resume on hover
|
|
9
|
+
- Vanilla CSS with CSS variables for customization
|
|
10
|
+
- Responsive design with mobile support
|
|
11
|
+
- Accessibility features (ARIA labels, roles)
|
|
12
|
+
- i18n support (English, French)
|
|
13
|
+
- Rails generator for easy installation
|
|
14
|
+
- Configuration system for toast duration
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cyril
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# DlnkToast
|
|
2
|
+
|
|
3
|
+
Simple, elegant toast notifications for Rails 7+ applications using Hotwire and vanilla CSS.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ⨠Flash-based notifications (notice/alert)
|
|
8
|
+
- šÆ Stimulus controller for UX (pause on hover, dismiss)
|
|
9
|
+
- šØ Vanilla CSS with CSS variables for easy customization
|
|
10
|
+
- š± Responsive design
|
|
11
|
+
- āæ Built-in accessibility (ARIA labels, roles)
|
|
12
|
+
- š Internationalization (i18n) support
|
|
13
|
+
- š Zero JavaScript bundle impact (uses importmap)
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
Add to your Gemfile:
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
gem "dlnk_toast"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Then run the installer:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
bundle install
|
|
27
|
+
bin/rails generate dlnk_toast:install
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The installer will:
|
|
31
|
+
- Create `config/initializers/dlnk_toast.rb`
|
|
32
|
+
- Add the Stimulus controller to your importmap (if present)
|
|
33
|
+
- Inject the toast partial into your layouts
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
Use Rails flash messages as usual:
|
|
38
|
+
|
|
39
|
+
```ruby
|
|
40
|
+
def create
|
|
41
|
+
@user = User.new(user_params)
|
|
42
|
+
if @user.save
|
|
43
|
+
redirect_to @user, notice: "User created successfully"
|
|
44
|
+
else
|
|
45
|
+
render :new, alert: "Failed to create user"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Your flash messages will automatically appear as toasts!
|
|
51
|
+
|
|
52
|
+
## Customization
|
|
53
|
+
|
|
54
|
+
### CSS Variables
|
|
55
|
+
|
|
56
|
+
Override these in your `app/assets/stylesheets/application.css`:
|
|
57
|
+
|
|
58
|
+
```css
|
|
59
|
+
:root {
|
|
60
|
+
--dlnk-toast-bg: #1a1a1a;
|
|
61
|
+
--dlnk-toast-border: #1f1f1f;
|
|
62
|
+
--dlnk-toast-text: #ffffff;
|
|
63
|
+
--dlnk-toast-text-dim: #6B6B6B;
|
|
64
|
+
--dlnk-toast-accent: #D4A017; /* Success color */
|
|
65
|
+
--dlnk-toast-error: #ef4444; /* Alert color */
|
|
66
|
+
--dlnk-toast-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Duration
|
|
71
|
+
|
|
72
|
+
Edit `config/initializers/dlnk_toast.rb`:
|
|
73
|
+
|
|
74
|
+
```ruby
|
|
75
|
+
DlnkToast.configure do |config|
|
|
76
|
+
config.duration = 5000 # milliseconds
|
|
77
|
+
end
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Manual Rendering
|
|
81
|
+
|
|
82
|
+
If you need to render toasts outside of layouts:
|
|
83
|
+
|
|
84
|
+
```erb
|
|
85
|
+
<%= render_toast %>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Translations
|
|
89
|
+
|
|
90
|
+
Translations are provided for English and French. Add custom ones to your locale files:
|
|
91
|
+
|
|
92
|
+
```yaml
|
|
93
|
+
# config/locales/en.yml
|
|
94
|
+
en:
|
|
95
|
+
dlnk_toast:
|
|
96
|
+
close: "Close"
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Browser Support
|
|
100
|
+
|
|
101
|
+
Works in all modern browsers that support CSS Grid, Flexbox, and CSS custom properties.
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
MIT License. See LICENSE file for details.
|
|
106
|
+
|
|
107
|
+
## Contributing
|
|
108
|
+
|
|
109
|
+
Bug reports and pull requests are welcome on GitHub.
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/* DlnkToast: Toast Notifications for Rails + Hotwire */
|
|
2
|
+
|
|
3
|
+
/* āāā CSS Variables (customize in your app) āāā */
|
|
4
|
+
:root {
|
|
5
|
+
--dlnk-toast-bg: #1a1a1a;
|
|
6
|
+
--dlnk-toast-border: #1f1f1f;
|
|
7
|
+
--dlnk-toast-text: #ffffff;
|
|
8
|
+
--dlnk-toast-text-dim: #6B6B6B;
|
|
9
|
+
--dlnk-toast-accent: #D4A017;
|
|
10
|
+
--dlnk-toast-error: #ef4444;
|
|
11
|
+
--dlnk-toast-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/* āāā Animations āāā */
|
|
15
|
+
@keyframes dlnk-toast-in {
|
|
16
|
+
from {
|
|
17
|
+
opacity: 0;
|
|
18
|
+
transform: translateX(100%);
|
|
19
|
+
}
|
|
20
|
+
to {
|
|
21
|
+
opacity: 1;
|
|
22
|
+
transform: translateX(0);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@keyframes dlnk-toast-out {
|
|
27
|
+
from {
|
|
28
|
+
opacity: 1;
|
|
29
|
+
transform: translateX(0);
|
|
30
|
+
}
|
|
31
|
+
to {
|
|
32
|
+
opacity: 0;
|
|
33
|
+
transform: translateX(100%);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* āāā Toast Component āāā */
|
|
38
|
+
.dlnk-toast {
|
|
39
|
+
position: fixed;
|
|
40
|
+
top: 5rem;
|
|
41
|
+
right: 1rem;
|
|
42
|
+
z-index: 50;
|
|
43
|
+
max-width: 28rem;
|
|
44
|
+
width: 100%;
|
|
45
|
+
box-sizing: border-box;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.dlnk-toast--enter {
|
|
49
|
+
animation: dlnk-toast-in 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.dlnk-toast--exit {
|
|
53
|
+
animation: dlnk-toast-out 0.2s cubic-bezier(0.4, 0, 1, 1) both;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.dlnk-toast__body {
|
|
57
|
+
background: var(--dlnk-toast-bg);
|
|
58
|
+
border: 1px solid var(--dlnk-toast-border);
|
|
59
|
+
border-radius: 0.5rem;
|
|
60
|
+
box-shadow: var(--dlnk-toast-shadow);
|
|
61
|
+
overflow: hidden;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.dlnk-toast__content {
|
|
65
|
+
display: flex;
|
|
66
|
+
align-items: center;
|
|
67
|
+
gap: 0.75rem;
|
|
68
|
+
padding: 0.75rem 1rem;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.dlnk-toast__icon {
|
|
72
|
+
width: 1.25rem;
|
|
73
|
+
height: 1.25rem;
|
|
74
|
+
flex-shrink: 0;
|
|
75
|
+
stroke-width: 2;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.dlnk-toast__icon--success {
|
|
79
|
+
color: var(--dlnk-toast-accent);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.dlnk-toast__icon--error {
|
|
83
|
+
color: var(--dlnk-toast-error);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.dlnk-toast__message {
|
|
87
|
+
color: var(--dlnk-toast-text);
|
|
88
|
+
font-size: 0.875rem;
|
|
89
|
+
font-weight: 500;
|
|
90
|
+
flex: 1;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.dlnk-toast__close {
|
|
94
|
+
background: none;
|
|
95
|
+
border: none;
|
|
96
|
+
padding: 0;
|
|
97
|
+
color: var(--dlnk-toast-text-dim);
|
|
98
|
+
cursor: pointer;
|
|
99
|
+
flex-shrink: 0;
|
|
100
|
+
display: inline-flex;
|
|
101
|
+
align-items: center;
|
|
102
|
+
justify-content: center;
|
|
103
|
+
transition: color 0.2s ease;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.dlnk-toast__close:hover {
|
|
107
|
+
color: var(--dlnk-toast-text);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.dlnk-toast__close-icon {
|
|
111
|
+
width: 1rem;
|
|
112
|
+
height: 1rem;
|
|
113
|
+
stroke-width: 2;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.dlnk-toast__progress-bar {
|
|
117
|
+
height: 0.125rem;
|
|
118
|
+
background: var(--dlnk-toast-border);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.dlnk-toast__progress {
|
|
122
|
+
height: 100%;
|
|
123
|
+
transition: width linear;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.dlnk-toast__progress--success {
|
|
127
|
+
background: var(--dlnk-toast-accent);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.dlnk-toast__progress--error {
|
|
131
|
+
background: var(--dlnk-toast-error);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/* āāā Responsive āāā */
|
|
135
|
+
@media (max-width: 640px) {
|
|
136
|
+
.dlnk-toast {
|
|
137
|
+
top: 1rem;
|
|
138
|
+
right: 0.5rem;
|
|
139
|
+
left: 0.5rem;
|
|
140
|
+
max-width: none;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
|
2
|
+
|
|
3
|
+
export default class extends Controller {
|
|
4
|
+
static targets = ["progress"]
|
|
5
|
+
static values = { duration: { type: Number, default: 4000 } }
|
|
6
|
+
|
|
7
|
+
connect() {
|
|
8
|
+
this.remaining = this.durationValue
|
|
9
|
+
this.startTimer()
|
|
10
|
+
this.startProgress()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
disconnect() {
|
|
14
|
+
this.clearTimer()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
close() {
|
|
18
|
+
this.clearTimer()
|
|
19
|
+
this.element.classList.remove("dlnk-toast--enter")
|
|
20
|
+
this.element.classList.add("dlnk-toast--exit")
|
|
21
|
+
this.element.addEventListener("animationend", () => this.element.remove(), { once: true })
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
pause() {
|
|
25
|
+
this.clearTimer()
|
|
26
|
+
if (this.hasProgressTarget) {
|
|
27
|
+
const computed = getComputedStyle(this.progressTarget)
|
|
28
|
+
this.pausedWidth = computed.width
|
|
29
|
+
this.progressTarget.style.transition = "none"
|
|
30
|
+
this.progressTarget.style.width = this.pausedWidth
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
resume() {
|
|
35
|
+
if (this.hasProgressTarget) {
|
|
36
|
+
const currentPercent = (parseFloat(this.pausedWidth) / this.progressTarget.parentElement.offsetWidth) * 100
|
|
37
|
+
this.remaining = (currentPercent / 100) * this.durationValue
|
|
38
|
+
requestAnimationFrame(() => {
|
|
39
|
+
this.progressTarget.style.transition = `width ${this.remaining}ms linear`
|
|
40
|
+
this.progressTarget.style.width = "0%"
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
this.startTimerWithRemaining()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// private
|
|
47
|
+
|
|
48
|
+
startTimer() {
|
|
49
|
+
this.timer = setTimeout(() => this.close(), this.durationValue)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
startTimerWithRemaining() {
|
|
53
|
+
this.timer = setTimeout(() => this.close(), this.remaining)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
clearTimer() {
|
|
57
|
+
if (this.timer) {
|
|
58
|
+
clearTimeout(this.timer)
|
|
59
|
+
this.timer = null
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
startProgress() {
|
|
64
|
+
if (!this.hasProgressTarget) return
|
|
65
|
+
this.progressTarget.style.width = "100%"
|
|
66
|
+
requestAnimationFrame(() => {
|
|
67
|
+
this.progressTarget.style.transition = `width ${this.durationValue}ms linear`
|
|
68
|
+
this.progressTarget.style.width = "0%"
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<% if flash[:notice].present? %>
|
|
2
|
+
<div class="dlnk-toast dlnk-toast--enter dlnk-toast--notice"
|
|
3
|
+
role="status"
|
|
4
|
+
aria-live="polite"
|
|
5
|
+
data-controller="dlnk-toast"
|
|
6
|
+
data-dlnk-toast-duration-value="<%= DlnkToast.configuration.duration %>"
|
|
7
|
+
data-action="mouseenter->dlnk-toast#pause mouseleave->dlnk-toast#resume">
|
|
8
|
+
<div class="dlnk-toast__body">
|
|
9
|
+
<div class="dlnk-toast__content">
|
|
10
|
+
<svg class="dlnk-toast__icon dlnk-toast__icon--success" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
|
11
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
|
|
12
|
+
</svg>
|
|
13
|
+
<span class="dlnk-toast__message"><%= flash[:notice] %></span>
|
|
14
|
+
<button data-action="dlnk-toast#close" aria-label="<%= t('dlnk_toast.close') %>" class="dlnk-toast__close">
|
|
15
|
+
<svg class="dlnk-toast__close-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
|
16
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
|
|
17
|
+
</svg>
|
|
18
|
+
</button>
|
|
19
|
+
</div>
|
|
20
|
+
<div class="dlnk-toast__progress-bar">
|
|
21
|
+
<div data-dlnk-toast-target="progress" class="dlnk-toast__progress dlnk-toast__progress--success" style="width: 100%"></div>
|
|
22
|
+
</div>
|
|
23
|
+
</div>
|
|
24
|
+
</div>
|
|
25
|
+
<% end %>
|
|
26
|
+
|
|
27
|
+
<% if flash[:alert].present? %>
|
|
28
|
+
<div class="dlnk-toast dlnk-toast--enter dlnk-toast--alert"
|
|
29
|
+
role="alert"
|
|
30
|
+
aria-live="assertive"
|
|
31
|
+
data-controller="dlnk-toast"
|
|
32
|
+
data-dlnk-toast-duration-value="<%= DlnkToast.configuration.duration %>"
|
|
33
|
+
data-action="mouseenter->dlnk-toast#pause mouseleave->dlnk-toast#resume">
|
|
34
|
+
<div class="dlnk-toast__body">
|
|
35
|
+
<div class="dlnk-toast__content">
|
|
36
|
+
<svg class="dlnk-toast__icon dlnk-toast__icon--error" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
|
37
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
|
|
38
|
+
</svg>
|
|
39
|
+
<span class="dlnk-toast__message"><%= flash[:alert] %></span>
|
|
40
|
+
<button data-action="dlnk-toast#close" aria-label="<%= t('dlnk_toast.close') %>" class="dlnk-toast__close">
|
|
41
|
+
<svg class="dlnk-toast__close-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
|
42
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
|
|
43
|
+
</svg>
|
|
44
|
+
</button>
|
|
45
|
+
</div>
|
|
46
|
+
<div class="dlnk-toast__progress-bar">
|
|
47
|
+
<div data-dlnk-toast-target="progress" class="dlnk-toast__progress dlnk-toast__progress--error" style="width: 100%"></div>
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
<% end %>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module DlnkToast
|
|
2
|
+
class Configuration
|
|
3
|
+
attr_accessor :duration
|
|
4
|
+
|
|
5
|
+
def initialize
|
|
6
|
+
@duration = 4000
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.configuration
|
|
11
|
+
@configuration ||= Configuration.new
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.configure
|
|
15
|
+
yield(configuration)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module DlnkToast
|
|
2
|
+
class Engine < ::Rails::Engine
|
|
3
|
+
isolate_namespace DlnkToast
|
|
4
|
+
|
|
5
|
+
initializer "dlnk_toast.helpers" do
|
|
6
|
+
ActiveSupport.on_load(:action_controller_base) do
|
|
7
|
+
helper DlnkToast::ToastHelper
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
initializer "dlnk_toast.assets" do |app|
|
|
12
|
+
app.config.assets.paths << root.join("app/assets/stylesheets")
|
|
13
|
+
app.config.assets.paths << root.join("app/javascript")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
initializer "dlnk_toast.i18n" do
|
|
17
|
+
Engine.root.glob("config/locales/**/*.yml").each do |locale|
|
|
18
|
+
I18n.load_path << locale unless I18n.load_path.include?(locale)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/dlnk_toast.rb
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require "rails/generators"
|
|
2
|
+
|
|
3
|
+
module DlnkToast
|
|
4
|
+
module Generators
|
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
|
6
|
+
source_root File.expand_path("templates", __dir__)
|
|
7
|
+
|
|
8
|
+
desc "Install DlnkToast into your Rails application"
|
|
9
|
+
|
|
10
|
+
def copy_initializer
|
|
11
|
+
copy_file "initializer.rb", "config/initializers/dlnk_toast.rb"
|
|
12
|
+
say "Created config/initializers/dlnk_toast.rb"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def add_importmap_pin
|
|
16
|
+
return unless File.exist?("config/importmap.rb")
|
|
17
|
+
append_to_file "config/importmap.rb", "\npin \"dlnk_toast\", preload: true"
|
|
18
|
+
say "Added dlnk_toast to importmap.rb"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def inject_toast_in_layouts
|
|
22
|
+
inject_into_file "app/views/layouts/application.html.erb", before: "</body>" do
|
|
23
|
+
"\n <%= render 'dlnk_toast/toast' %>\n"
|
|
24
|
+
end
|
|
25
|
+
say "Added toast partial to app/views/layouts/application.html.erb"
|
|
26
|
+
|
|
27
|
+
if File.exist?("app/views/layouts/admin.html.erb")
|
|
28
|
+
inject_into_file "app/views/layouts/admin.html.erb", before: "</body>" do
|
|
29
|
+
"\n <%= render 'dlnk_toast/toast' %>\n"
|
|
30
|
+
end
|
|
31
|
+
say "Added toast partial to app/views/layouts/admin.html.erb"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def display_next_steps
|
|
36
|
+
say "\nā DlnkToast installed successfully!"
|
|
37
|
+
say "\nNext steps:"
|
|
38
|
+
say " 1. Customize CSS variables in app/assets/stylesheets/application.css"
|
|
39
|
+
say " 2. Adjust toast duration in config/initializers/dlnk_toast.rb if needed"
|
|
40
|
+
say " 3. Flash notices/alerts will now appear as toasts!"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: dlnk_toast
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Cyril
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: railties
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '7.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '7.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: rake
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '13.0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '13.0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: rails
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '7.0'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '7.0'
|
|
54
|
+
description: Flash-based toast notifications using Stimulus and vanilla CSS for Rails
|
|
55
|
+
7+ applications
|
|
56
|
+
email:
|
|
57
|
+
- contact@dlnk.fr
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- CHANGELOG.md
|
|
63
|
+
- LICENSE
|
|
64
|
+
- README.md
|
|
65
|
+
- app/assets/stylesheets/dlnk_toast/application.css
|
|
66
|
+
- app/helpers/dlnk_toast/toast_helper.rb
|
|
67
|
+
- app/javascript/dlnk_toast/toast_controller.js
|
|
68
|
+
- app/views/dlnk_toast/_toast.html.erb
|
|
69
|
+
- config/locales/en.yml
|
|
70
|
+
- config/locales/fr.yml
|
|
71
|
+
- lib/dlnk_toast.rb
|
|
72
|
+
- lib/dlnk_toast/configuration.rb
|
|
73
|
+
- lib/dlnk_toast/engine.rb
|
|
74
|
+
- lib/dlnk_toast/version.rb
|
|
75
|
+
- lib/generators/dlnk_toast/install/install_generator.rb
|
|
76
|
+
- lib/generators/dlnk_toast/install/templates/initializer.rb
|
|
77
|
+
homepage: https://github.com/cyril/dlnk_toast
|
|
78
|
+
licenses:
|
|
79
|
+
- MIT
|
|
80
|
+
metadata:
|
|
81
|
+
rubygems_mfa_required: 'true'
|
|
82
|
+
homepage_uri: https://github.com/cyril/dlnk_toast
|
|
83
|
+
source_code_uri: https://github.com/cyril/dlnk_toast.git
|
|
84
|
+
bug_tracker_uri: https://github.com/cyril/dlnk_toast/issues
|
|
85
|
+
changelog_uri: https://github.com/cyril/dlnk_toast/blob/main/CHANGELOG.md
|
|
86
|
+
rdoc_options: []
|
|
87
|
+
require_paths:
|
|
88
|
+
- lib
|
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
|
+
requirements:
|
|
91
|
+
- - ">="
|
|
92
|
+
- !ruby/object:Gem::Version
|
|
93
|
+
version: '3.0'
|
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
|
+
requirements:
|
|
96
|
+
- - ">="
|
|
97
|
+
- !ruby/object:Gem::Version
|
|
98
|
+
version: '0'
|
|
99
|
+
requirements: []
|
|
100
|
+
rubygems_version: 4.0.3
|
|
101
|
+
specification_version: 4
|
|
102
|
+
summary: Hotwire toast notifications for Rails
|
|
103
|
+
test_files: []
|