faw_toast 1.3.0 → 1.4.1

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: dc39d92ac6fc1ce8da21e5b03174d62fa6ab8181655a3d3b8765b64259e08a77
4
- data.tar.gz: 405c14d7a313d6169ce47fac895b219bffcf152ed345c51f751ccebaa73809cf
3
+ metadata.gz: 20b5f4ba4431cccf4fb2e389d96eb476f6bcad0e647510b7efd45c0dc6e739b6
4
+ data.tar.gz: f59a37ec861743eedfa4a7a1d6eb71f681a395345c60fc34f2ed4dfbae34c5dd
5
5
  SHA512:
6
- metadata.gz: 23df80b449b32f2c360c0f36141d7a19d5514e9d0e7532402b2fd74a617f873d4784eac7f8b6e0a956116b86797117c7189f1aadc27a272b6af29b8101d09f5c
7
- data.tar.gz: 1147a18542a6a9b4ee15d85b9d3e9ee62a071122be40d75adc9234db2115be66083da9d743c0382b975e559f44ad069d09761e1d765b16927a7ee1b1e20566e4
6
+ metadata.gz: 40a6bcadcc29476e6b7c3caf40f8b06e41a48c283ba6ed28e945c2923181896da92d8169d21f90ec91ac92a41ab05395f2cd4d5d420ba2a4cdb4e00381273385
7
+ data.tar.gz: 777749653a1c46b020e285cd39c25767d45a7040f52d6a02dc58bdb81a852c05cbd86d261d145aed7916ebd83a72c0c78c66970be0f09e5e9074fbaf9a3fd469
data/README.md CHANGED
@@ -40,16 +40,13 @@ rails generate faw_toast:install
40
40
 
41
41
  This will:
42
42
  1. Create a configuration initializer at `config/initializers/faw_toast.rb`
43
- 2. Add the toast container to your application layout
43
+ 2. Include the following into your `application.html.erb`
44
+ * Add a style tag for the configurable css variables
45
+ * `<%= stylesheet_link_tag "faw_toast", "data-turbo-track": "reload" %>`
46
+ * `<%= javascript_include_tag "faw_toast", "data-turbo-track": "reload", type: "module" %>`
47
+ * Add the toast container div
44
48
 
45
- Include the css and javascript files in your `application.html.erb` layout file.
46
-
47
- For `propshaft`
48
- ```erb
49
- <%= stylesheet_link_tag "faw_toast", "data-turbo-track": "reload" %>
50
- <%= javascript_include_tag "faw_toast", "data-turbo-track": "reload", type: "module" %>
51
- ```
52
- and if you are using `sprockets` include the following lines in your `config/manifest.js`
49
+ If you are using `sprockets` you may need to add the following lines to your `app/config/manifest.js`
53
50
  ```javascript
54
51
  //= link faw_toast.js
55
52
  //= link faw_toast.css
@@ -57,6 +54,8 @@ and if you are using `sprockets` include the following lines in your `config/man
57
54
 
58
55
  ## Usage
59
56
 
57
+ ### Basic Usage
58
+
60
59
  FawToast works with Rails flash messages. You can use it like this
61
60
 
62
61
  ```ruby
@@ -85,6 +84,28 @@ Turbo::StreamsChannel.broadcast_append_to(
85
84
  )
86
85
  ```
87
86
 
87
+ ### With Turbo Streams
88
+
89
+ For Turbo Streams applications, you can use the built-in `render_message` helper:
90
+
91
+ ```ruby
92
+ # In your controller
93
+ def create
94
+ # Your logic here
95
+ render_message(:success, :ok, "Item was successfully created!")
96
+ end
97
+ ```
98
+
99
+ The `render_message` method takes three parameters:
100
+ - `flash_type`: The type of flash message (:success, :alert, :danger, etc.)
101
+ - `status`: The HTTP status code to return (:ok, :created, etc.)
102
+ - `message`: The message to display in the toast
103
+
104
+ This helper automatically:
105
+ 1. Sets the flash message
106
+ 2. Renders a Turbo Stream that appends the toast to the toast container
107
+ 3. Sets the appropriate HTTP status code
108
+
88
109
  FawToast supports the following flash types out of the box:
89
110
  - `:success` - Green border
90
111
  - `:alert` - Red border
@@ -1,6 +1,14 @@
1
- <% flash.each do |type, message| %>
1
+ <% if local_assigns[:type] && local_assigns[:message] %>
2
2
  <div class="faw-toast <%= flash_class(type) %>">
3
3
  <%= message %>
4
4
  <div class="faw-toast-progress"></div>
5
5
  </div>
6
+ <% else %>
7
+ <% flash.each do |type, message| %>
8
+ <div class="faw-toast <%= flash_class(type) %>">
9
+ <%= message %>
10
+ <div class="faw-toast-progress"></div>
11
+ </div>
12
+ <% end %>
6
13
  <% end %>
14
+
@@ -20,6 +20,11 @@ module FawToast
20
20
  render_toast
21
21
  end
22
22
  end
23
+
24
+ def render_message(flash_type = :success, status = :ok, message = nil)
25
+ flash.now[flash_type] = message
26
+ render turbo_stream: turbo_stream.append("faw-toast-container", partial: "faw_toast/toast"), status: status
27
+ end
23
28
 
24
29
  def toast_css_variables
25
30
  # Generate a style tag with CSS variables based on configuration
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FawToast
4
- VERSION = "1.3.0"
4
+ VERSION = "1.4.1"
5
5
  end
@@ -15,7 +15,7 @@ module FawToast
15
15
  inject_into_file "app/views/layouts/application.html.erb", after: "<head>" do
16
16
  <<-HTML
17
17
 
18
- <%= toast_css_variables %>
18
+ <%= toast_css_variables %>
19
19
  HTML
20
20
  end
21
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faw_toast
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - alexwebgr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-27 00:00:00.000000000 Z
11
+ date: 2025-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails