rails_mail 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/app/controllers/rails_mail/base_controller.rb +3 -1
- data/app/controllers/rails_mail/emails_controller.rb +2 -7
- data/app/frontend/rails_mail/modules/email_highlight_controller.js +1 -1
- data/app/helpers/rails_mail/turbo_helper.rb +7 -3
- data/app/jobs/rails_mail/trim_emails_job.rb +2 -0
- data/app/models/rails_mail/email.rb +8 -9
- data/app/views/rails_mail/emails/_show.html.erb +1 -1
- data/app/views/rails_mail/emails/destroy_all.turbo_stream.erb +9 -0
- data/app/views/rails_mail/emails/index.html.erb +1 -1
- data/app/views/rails_mail/emails/show.html.erb +1 -1
- data/app/views/rails_mail/shared/_email.html.erb +2 -2
- data/app/views/rails_mail/shared/_email_sidebar.html.erb +1 -1
- data/lib/generators/rails_mail/install/templates/initializer.rb +33 -18
- data/lib/rails_mail/configuration.rb +3 -9
- data/lib/rails_mail/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0111e011c108a5b717fcb3f4074985e58faaeef49d4247587697be29facff12
|
4
|
+
data.tar.gz: edbcf7e6c0856e325c7d3fba6d0d03ac024eb26874a194d9554b0b39685d2ddb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d4e8443a570257b4f3fd15b1a807610968968de29ad779a21e2073611b7efdd5f062e2073a250f2b3834a7af2f2b154ff92daba835fd9492747536178d49e42
|
7
|
+
data.tar.gz: 27d2f45c1ffb9db48e0916078c6afe565aeaa9be29c6d6bf9dddb53fad28706501313539352c1e1857b29c3ba364a5474397a02ab6dd042999e87b149974f104
|
data/README.md
CHANGED
@@ -17,6 +17,7 @@ RailsMail saves all outgoing emails to your database instead of actually sending
|
|
17
17
|
* Trimming emails older than a specified duration or a maximum number of emails
|
18
18
|
* Ability to manually clear emails out and turn on/off that functionality based on environment (eg, so that in Staging, other stakeholders can't clear emails out, but in dev sometimes you want a clean slate)
|
19
19
|
* Dynamic time ago in words using date-fns
|
20
|
+
* Ability to customize how the job that trims emails is enqueued
|
20
21
|
|
21
22
|
## Installation
|
22
23
|
|
@@ -25,15 +25,10 @@ module RailsMail
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def destroy_all
|
28
|
-
|
28
|
+
Email.destroy_all
|
29
29
|
respond_to do |format|
|
30
30
|
format.html { redirect_to emails_path }
|
31
|
-
format.turbo_stream
|
32
|
-
render turbo_stream: [
|
33
|
-
turbo_stream.update("email-sidebar", ""),
|
34
|
-
turbo_stream.update("email_content", partial: "empty_state")
|
35
|
-
]
|
36
|
-
}
|
31
|
+
format.turbo_stream
|
37
32
|
end
|
38
33
|
end
|
39
34
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module RailsMail
|
2
2
|
module TurboHelper
|
3
|
-
def
|
3
|
+
def rails_mail_turbo_frame_tag(name, src: nil, &block)
|
4
4
|
tag.turbo_frame id: name, src: src do
|
5
5
|
if block_given?
|
6
6
|
yield
|
@@ -8,7 +8,7 @@ module RailsMail
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
11
|
+
def rails_mail_turbo_stream_from(*streamables, **attributes)
|
12
12
|
return unless defined?(::ActionCable)
|
13
13
|
|
14
14
|
raise ArgumentError, "streamables can't be blank" unless streamables.any?(&:present?)
|
@@ -18,7 +18,7 @@ module RailsMail
|
|
18
18
|
tag.turbo_cable_stream_source(**attributes)
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
21
|
+
def rails_mail_turbo_stream
|
22
22
|
TurboStreamBuilder.new
|
23
23
|
end
|
24
24
|
|
@@ -31,6 +31,10 @@ module RailsMail
|
|
31
31
|
build_stream("prepend", target, content)
|
32
32
|
end
|
33
33
|
|
34
|
+
def update(target:, content:)
|
35
|
+
build_stream("update", target, content)
|
36
|
+
end
|
37
|
+
|
34
38
|
private
|
35
39
|
|
36
40
|
def build_stream(action, target, content)
|
@@ -6,7 +6,7 @@ module RailsMail
|
|
6
6
|
validates :to, presence: true
|
7
7
|
|
8
8
|
after_create_commit :broadcast_email
|
9
|
-
|
9
|
+
after_create_commit :enqueue_trim_job
|
10
10
|
|
11
11
|
scope :search, ->(query) {
|
12
12
|
where("CAST(data AS CHAR) LIKE :q", q: "%#{query}%")
|
@@ -19,6 +19,7 @@ module RailsMail
|
|
19
19
|
def html?
|
20
20
|
content_type&.include?("text/html")
|
21
21
|
end
|
22
|
+
|
22
23
|
private
|
23
24
|
|
24
25
|
def broadcast_email
|
@@ -30,16 +31,14 @@ module RailsMail
|
|
30
31
|
partial: "rails_mail/shared/email",
|
31
32
|
locals: { email: self }
|
32
33
|
)
|
33
|
-
rescue
|
34
|
-
Rails.logger.
|
34
|
+
rescue StandardError => e
|
35
|
+
Rails.logger.error "RailsMail::Email#broadcast_email failed: #{e.message}"
|
35
36
|
end
|
36
37
|
|
37
|
-
def
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
RailsMail::TrimEmailsJob.perform_later
|
42
|
-
end
|
38
|
+
def enqueue_trim_job
|
39
|
+
RailsMail.configuration.enqueue_trim_job.call(self)
|
40
|
+
rescue StandardError => e
|
41
|
+
Rails.logger.error "RailsMail::Email#enqueue_trim_job Failed: #{e.message}"
|
43
42
|
end
|
44
43
|
end
|
45
44
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%=
|
1
|
+
<%= rails_mail_turbo_frame_tag "email_content" do %>
|
2
2
|
<div class="bg-white shadow rounded-lg" data-email-id="<%= email.id %>"
|
3
3
|
data-email-highlight-current-id-value="<%= email.id %>">
|
4
4
|
<div class="px-6 py-4 border-b border-gray-200">
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<turbo-stream action="update" target="email-sidebar">
|
2
|
+
<template>
|
3
|
+
</template>
|
4
|
+
</turbo-stream>
|
5
|
+
<turbo-stream action="update" target="email_content">
|
6
|
+
<template>
|
7
|
+
<%= render(partial: "rails_mail/emails/empty_state", formats: [ :html ]) %>
|
8
|
+
</template>
|
9
|
+
</turbo-stream>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<% if @email.present? %>
|
2
|
-
<%=
|
2
|
+
<%= rails_mail_turbo_frame_tag "email_content", src: email_path(@email) do %>
|
3
3
|
<div class="bg-white shadow rounded-lg">
|
4
4
|
<div class="px-6 py-4">
|
5
5
|
<div class="animate-pulse">
|
@@ -1,9 +1,9 @@
|
|
1
1
|
<%
|
2
2
|
on_current_page = current_page?(RailsMail::Engine.routes.url_helpers.email_path(email))
|
3
|
-
highlight_class = on_current_page ? 'bg-gray-
|
3
|
+
highlight_class = on_current_page ? 'bg-gray-300' : ''
|
4
4
|
%>
|
5
5
|
<%= link_to RailsMail::Engine.routes.url_helpers.email_path(email),
|
6
|
-
class: "block px-3 py-2 rounded-md hover:bg-gray-
|
6
|
+
class: "block px-3 py-2 rounded-md hover:bg-gray-200 #{highlight_class} active:bg-gray-300 focus:bg-gray-300",
|
7
7
|
data: {
|
8
8
|
"turbo-frame": "email_content",
|
9
9
|
"turbo-action": "advance",
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<% if defined?(::ActionCable) %>
|
2
|
-
<%=
|
2
|
+
<%= rails_mail_turbo_stream_from "rails_mail:emails", channel: "RailsMail::EmailsChannel" %>
|
3
3
|
<% end %>
|
4
4
|
|
5
5
|
<div id="email-sidebar" data-controller="email-highlight">
|
@@ -1,23 +1,38 @@
|
|
1
1
|
# rubocop:disable Layout/CommentIndentation
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
Rails.configuration.to_prepare do
|
4
|
+
RailsMail.configure do |config|
|
5
|
+
# Authentication setup
|
6
|
+
# if left blank, authentication is skipped
|
7
|
+
# config.authentication_callback do
|
8
|
+
# Example implementation for Authlogic:
|
9
|
+
# user_session = UserSession.find
|
10
|
+
# msg = Rails.env.development? ? 'Forbidden - make sure you have the correct permission in config/initializers/rails_mail.rb' : 'Not Found'
|
11
|
+
# raise ActionController::RoutingError.new(msg) unless user_session&.user&.admin?
|
12
|
+
# end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
config.show_clear_button do
|
15
|
+
# show clear button in development
|
16
|
+
# and prefer to trim in non-development environments
|
17
|
+
# to prevent accidental deletion of emails
|
18
|
+
Rails.env.development?
|
19
|
+
end
|
20
|
+
|
21
|
+
config.trim_emails_older_than = 30.days
|
22
|
+
config.trim_emails_max_count = 1000
|
23
|
+
|
24
|
+
# Configure how trim jobs are enqueued
|
25
|
+
# You can use perform_now for immediate execution (default):
|
26
|
+
# config.enqueue_trim_job = ->(email) { RailsMail::TrimEmailsJob.perform_now }
|
19
27
|
|
20
|
-
|
21
|
-
|
22
|
-
|
28
|
+
# Or create a custom job class:
|
29
|
+
# class CustomTrimEmailsJob < RailsMail::TrimEmailsJob
|
30
|
+
# def perform
|
31
|
+
# Rails.logger.debug "CustomTrimEmailsJob#perform"
|
32
|
+
# super
|
33
|
+
# end
|
34
|
+
# end
|
35
|
+
|
36
|
+
# config.enqueue_trim_job = ->(email) { CustomTrimEmailsJob.perform_later }
|
37
|
+
end
|
23
38
|
end
|
@@ -1,21 +1,15 @@
|
|
1
1
|
module RailsMail
|
2
2
|
class Configuration
|
3
3
|
attr_accessor :authentication_callback, :show_clear_button,
|
4
|
-
:trim_emails_older_than, :trim_emails_max_count,
|
4
|
+
:trim_emails_older_than, :trim_emails_max_count,
|
5
|
+
:enqueue_trim_job
|
5
6
|
|
6
7
|
def initialize
|
7
8
|
@authentication_callback = nil
|
8
9
|
@show_clear_button = nil
|
9
10
|
@trim_emails_older_than = nil
|
10
11
|
@trim_emails_max_count = nil
|
11
|
-
@
|
12
|
-
end
|
13
|
-
|
14
|
-
def trim_via=(value)
|
15
|
-
unless [ :perform_now, :perform_later ].include?(value)
|
16
|
-
raise ArgumentError, "trim_via must be :now or :later"
|
17
|
-
end
|
18
|
-
@trim_via = value
|
12
|
+
@enqueue_trim_job = ->(email) { RailsMail::TrimEmailsJob.perform_later }
|
19
13
|
end
|
20
14
|
|
21
15
|
def authentication_callback=(callback)
|
data/lib/rails_mail/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_mail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Philips
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- app/views/rails_mail/emails/_empty_state.html.erb
|
86
86
|
- app/views/rails_mail/emails/_form.html.erb
|
87
87
|
- app/views/rails_mail/emails/_show.html.erb
|
88
|
+
- app/views/rails_mail/emails/destroy_all.turbo_stream.erb
|
88
89
|
- app/views/rails_mail/emails/edit.html.erb
|
89
90
|
- app/views/rails_mail/emails/index.html.erb
|
90
91
|
- app/views/rails_mail/emails/index.turbo_stream.erb
|