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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a5b082815997cb25d49acaec8336d565dd9c03a1a4a0d98d453fd16cf4eb515
4
- data.tar.gz: a1c6f9008760194eb79874ae695db11ffce158316fb14cac0ed6584889fa0bae
3
+ metadata.gz: c0111e011c108a5b717fcb3f4074985e58faaeef49d4247587697be29facff12
4
+ data.tar.gz: edbcf7e6c0856e325c7d3fba6d0d03ac024eb26874a194d9554b0b39685d2ddb
5
5
  SHA512:
6
- metadata.gz: b48e6c395e19ba01bea9290bd66e1f006347868f8f327b80c5c2dca5002cd1b14de5d00cfea7d1f4bfb5b4be80e153967b26597ff16e105fde4903b4bdb57ded
7
- data.tar.gz: d8821e83718954273d9fe6d1211ae8ae4b6f88762cab0a05c4c7dc9a9e35efc1f5a62bc3424a9e80bf50e2c9739dec8404c267e8d05c69dfe79614fccd46c097
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
 
@@ -1,7 +1,9 @@
1
1
  module RailsMail
2
2
  class BaseController < ActionController::Base
3
3
  layout "rails_mail/application"
4
- helper TurboHelper if defined?(TurboHelper)
4
+ helper RailsMail::TurboHelper
5
+ include RailsMail::TurboHelper
6
+
5
7
  before_action :authenticate!
6
8
 
7
9
  private
@@ -25,15 +25,10 @@ module RailsMail
25
25
  end
26
26
 
27
27
  def destroy_all
28
- # Email.destroy_all
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
@@ -4,7 +4,7 @@ export default class extends Controller {
4
4
  static targets = ["link"]
5
5
 
6
6
  // Define the Tailwind class as a static property
7
- static activeClass = "bg-gray-100"
7
+ static activeClass = "bg-gray-300"
8
8
 
9
9
  connect() {
10
10
  console.log("EmailHighlightController connected")
@@ -1,6 +1,6 @@
1
1
  module RailsMail
2
2
  module TurboHelper
3
- def turbo_frame_tag(name, src: nil, &block)
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 turbo_stream_from(*streamables, **attributes)
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 turbo_stream
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)
@@ -12,6 +12,8 @@ module RailsMail
12
12
  if RailsMail.configuration.trim_emails_max_count
13
13
  trim_by_count
14
14
  end
15
+ rescue StandardError => e
16
+ Rails.logger.error "RailsMail::TrimJob#perform Failed: #{e.message}"
15
17
  end
16
18
 
17
19
  private
@@ -6,7 +6,7 @@ module RailsMail
6
6
  validates :to, presence: true
7
7
 
8
8
  after_create_commit :broadcast_email
9
- after_create :schedule_trim_job
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 NameError => e
34
- Rails.logger.debug "Skipping broadcast: #{e.message}"
34
+ rescue StandardError => e
35
+ Rails.logger.error "RailsMail::Email#broadcast_email failed: #{e.message}"
35
36
  end
36
37
 
37
- def schedule_trim_job
38
- if RailsMail.configuration.trim_via == :perform_now
39
- RailsMail::TrimEmailsJob.perform_now
40
- else
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
- <%= turbo_frame_tag "email_content" do %>
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
- <%= turbo_frame_tag "email_content", src: email_path(@email) do %>
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,4 +1,4 @@
1
- <%= turbo_frame_tag "email_content" do %>
1
+ <%= rails_mail_turbo_frame_tag "email_content" do %>
2
2
  <div class="bg-white shadow rounded-lg">
3
3
  <div class="px-6 py-4 border-b border-gray-200">
4
4
  <h1 class="text-2xl font-semibold text-gray-900"><%= @email.subject %></h1>
@@ -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-100' : ''
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-50 #{highlight_class} active:bg-gray-100 focus:bg-gray-100",
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
- <%= turbo_stream_from "rails_mail:emails", channel: "RailsMail::EmailsChannel" %>
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
- RailsMail.configure do |config|
4
- # Authentication setup
5
- # if left blank, authentication is skipped
6
- # config.authentication_callback do
7
- # Example implementation for Authlogic:
8
- # user_session = UserSession.find
9
- # msg = Rails.env.development? ? 'Forbidden - make sure you have the correct permission in config/initializers/rails_mail.rb' : 'Not Found'
10
- # raise ActionController::RoutingError.new(msg) unless user_session&.user&.admin?
11
- # end
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
- config.show_clear_button do
14
- # show clear button in development
15
- # and prefer to trim in non-development environments
16
- # to prevent accidental deletion of emails
17
- Rails.env.development?
18
- end
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
- config.trim_emails_older_than = 30.days
21
- config.trim_emails_max_count = 1000
22
- config.trim_via = :perform_later
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, :trim_via
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
- @trim_via = :perform_later
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)
@@ -1,3 +1,3 @@
1
1
  module RailsMail
2
- VERSION = "0.9.2"
2
+ VERSION = "0.9.3"
3
3
  end
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.2
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-01-30 00:00:00.000000000 Z
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