rails_mail 0.9.3 → 0.9.4

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: c0111e011c108a5b717fcb3f4074985e58faaeef49d4247587697be29facff12
4
- data.tar.gz: edbcf7e6c0856e325c7d3fba6d0d03ac024eb26874a194d9554b0b39685d2ddb
3
+ metadata.gz: 3b68a7af3f8450340634593140b18052ec4ca26d240c7779a639c80b5b03f3c9
4
+ data.tar.gz: 48c3cc14e90bc5948eae038b7be1b0ce0501efe81e46974a4d1d469a56acee54
5
5
  SHA512:
6
- metadata.gz: 1d4e8443a570257b4f3fd15b1a807610968968de29ad779a21e2073611b7efdd5f062e2073a250f2b3834a7af2f2b154ff92daba835fd9492747536178d49e42
7
- data.tar.gz: 27d2f45c1ffb9db48e0916078c6afe565aeaa9be29c6d6bf9dddb53fad28706501313539352c1e1857b29c3ba364a5474397a02ab6dd042999e87b149974f104
6
+ metadata.gz: 47a9c4410d756bb79a7475f0e7f207458d40aa5163007155dfc7bfa52bf9587526119a426f1c8e57829abf9b762470fccdf0639b8815858bcda8846f210fe061
7
+ data.tar.gz: 911f7d8d8cefe26660bc32a07c736d47a4d9d9c82cb38f4385aff2c349a9cee3a4ec50a4528d0844750d44658d9bf2979499ae7b77614010536d394d64786324
data/README.md CHANGED
@@ -15,9 +15,10 @@ RailsMail saves all outgoing emails to your database instead of actually sending
15
15
  * Clean, responsive UI for viewing email contents
16
16
  * Optional authentication support
17
17
  * Trimming emails older than a specified duration or a maximum number of emails
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)
18
+ * Ability to manually clear emails in bulk or individually. The bulk delete can be turned on/off 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
20
  * Ability to customize how the job that trims emails is enqueued
21
+ * Ability to customize the title in the top left of the page via a standard Rails view that overrides the engine's default view.
21
22
 
22
23
  ## Installation
23
24
 
@@ -79,7 +80,7 @@ To use RailsMail in your application:
79
80
  3. **Configure the initializer**
80
81
  See the [Configuration](#configuration) section for more details.
81
82
 
82
- 4. **Visit `/rails_mail` in your browser to view all captured emails.**
83
+ 4. **Visit `/rails_mail` (or where ever you mounted the engine) in your browser to view all captured emails.**
83
84
 
84
85
  ### Configuration
85
86
 
@@ -113,6 +114,13 @@ end
113
114
  - `trim_emails_max_count`: Keeps only the N most recent emails, deleting older ones.
114
115
  - `sync_via`: Controls whether the trimming job runs synchronously (:now) or asynchronously (:later)
115
116
 
117
+ ### Customize the title
118
+ Since this is a Rails engine, you can customize the title by creating a file at `app/views/layouts/rails_mail/_title.html.erb`.
119
+
120
+ ```erb
121
+ <h1 class="text-xl font-bold">My apps mails</h1>
122
+ ```
123
+
116
124
  ## Authentication
117
125
  Authentication is optional, but recommended and will depend on your application's authentication setup. This gem provides an `authentication_callback` that you can configure in the initializer which is helpful for Authlogic. If you are using Devise, you can simply wrap the mount point of the engine.
118
126
 
@@ -17,6 +17,8 @@ module RailsMail
17
17
  def show
18
18
  @emails = Email.order(created_at: :desc)
19
19
  @email = Email.find(params[:id])
20
+ session[:current_email_id] = @email.id
21
+
20
22
  if request.headers["Turbo-Frame"]
21
23
  render partial: "rails_mail/emails/show", locals: { email: @email }
22
24
  else
@@ -24,6 +26,17 @@ module RailsMail
24
26
  end
25
27
  end
26
28
 
29
+ def destroy
30
+ @email = Email.find(params[:id])
31
+ @current_email_id = session[:current_email_id]
32
+ @email.destroy
33
+
34
+ respond_to do |format|
35
+ format.html { redirect_to emails_path }
36
+ format.turbo_stream
37
+ end
38
+ end
39
+
27
40
  def destroy_all
28
41
  Email.destroy_all
29
42
  respond_to do |format|
@@ -1,12 +1,14 @@
1
1
  import { Application } from "stimulus";
2
2
  import "turbo";
3
3
  import EmailHighlightController from "email_highlight_controller";
4
+ import RedirectController from "redirect_controller";
4
5
  import AutoSubmit from 'auto_submit'
5
6
  import Timeago from 'timeago'
6
7
 
7
8
  const application = Application.start();
8
9
 
9
10
  application.register("email-highlight", EmailHighlightController);
11
+ application.register("redirect", RedirectController);
10
12
  application.register('auto-submit', AutoSubmit)
11
13
  application.register('timeago', Timeago)
12
14
 
@@ -19,14 +19,14 @@ export default class extends Controller {
19
19
 
20
20
  // Called when a link is clicked
21
21
  highlight(event) {
22
- // Remove active class from all links
22
+ // Remove active class from all email containers
23
23
  this.linkTargets.forEach(link => {
24
- link.classList.remove(this.constructor.activeClass)
24
+ link.closest(".group").classList.remove(this.constructor.activeClass)
25
25
  })
26
26
 
27
- // Add active class to clicked link
27
+ // Add active class to clicked email's container
28
28
  const clickedLink = event.currentTarget
29
- clickedLink.classList.add(this.constructor.activeClass)
29
+ clickedLink.closest(".group").classList.add(this.constructor.activeClass)
30
30
  }
31
31
 
32
32
  highlightCurrentEmail() {
@@ -35,12 +35,13 @@ export default class extends Controller {
35
35
  if (emailContent) {
36
36
  const currentEmailId = emailContent.dataset.emailId
37
37
 
38
- // Highlight the link with the matching email ID
38
+ // Highlight the container with the matching email ID
39
39
  this.linkTargets.forEach(link => {
40
+ const container = link.closest(".group")
40
41
  if (link.dataset.emailId === currentEmailId) {
41
- link.classList.add(this.constructor.activeClass)
42
+ container.classList.add(this.constructor.activeClass)
42
43
  } else {
43
- link.classList.remove(this.constructor.activeClass)
44
+ container.classList.remove(this.constructor.activeClass)
44
45
  }
45
46
  })
46
47
  }
@@ -0,0 +1,9 @@
1
+ import { Controller } from 'stimulus'
2
+
3
+ export default class extends Controller {
4
+ static values = { url: String }
5
+ connect () {
6
+ // window.location.href = this.urlValue
7
+ Turbo.visit(this.urlValue)
8
+ }
9
+ }
@@ -20,6 +20,10 @@ module RailsMail
20
20
  content_type&.include?("text/html")
21
21
  end
22
22
 
23
+ def next_email
24
+ RailsMail::Email.where("id < ?", id).last || RailsMail::Email.first
25
+ end
26
+
23
27
  private
24
28
 
25
29
  def broadcast_email
@@ -0,0 +1 @@
1
+ <h1 class="text-xl font-bold">Rails Mail</h1>
@@ -17,18 +17,35 @@
17
17
  </head>
18
18
 
19
19
  <body class="bg-gray-100">
20
- <div class="flex h-screen">
20
+ <div class="flex h-screen relative">
21
+ <!-- Mobile menu checkbox (hidden) -->
22
+ <input type="checkbox" class="hidden peer" id="sidebar-toggle">
23
+
24
+ <!-- Collapsed menu button -->
25
+ <label for="sidebar-toggle" class="lg:hidden fixed top-4 left-4 z-20 p-2 rounded-md text-gray-600 hover:text-gray-900 hover:bg-gray-100 cursor-pointer peer-checked:hidden">
26
+ <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
27
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
28
+ </svg>
29
+ </label>
30
+
21
31
  <!-- Sidebar -->
22
- <div class="w-80 bg-white border-r border-gray-200 flex flex-col">
32
+ <div class="fixed lg:static inset-y-0 left-0 transform -translate-x-full peer-checked:translate-x-0 lg:translate-x-0 transition duration-200 ease-in-out w-80 bg-white border-r border-gray-200 flex flex-col z-10">
23
33
  <div class="flex-none p-4">
24
- <div class="flex items-center justify-between">
25
- <div class="flex items-center">
26
- <%= link_to root_path, class: "text-gray-900" do %>
27
- <h1 class="text-xl font-bold">Rails Mail</h1>
28
- <% end %>
29
- </div>
34
+ <div class="flex items-center justify-between w-full">
35
+ <!-- Menu icon (visible only on mobile) -->
36
+ <label for="sidebar-toggle" class="lg:hidden p-2 rounded-md text-gray-600 hover:text-gray-900 hover:bg-gray-100 cursor-pointer">
37
+ <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
38
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
39
+ </svg>
40
+ </label>
41
+
42
+ <!-- Title (centered) -->
43
+ <%= link_to root_path, class: "text-gray-900" do %>
44
+ <%= render "layouts/rails_mail/title" %>
45
+ <% end %>
30
46
 
31
- <% if instance_eval(&RailsMail.show_clear_button?) %>
47
+ <!-- Clear All button (or empty div for spacing when button is hidden) -->
48
+ <% if instance_eval(&RailsMail.show_clear_button?) %>
32
49
  <%= button_to destroy_all_emails_path,
33
50
  class: "text-sm text-gray-600 hover:text-gray-900",
34
51
  form: { data: { turbo_confirm: "Are you sure you want to clear all emails?" } },
@@ -40,6 +57,8 @@
40
57
  Clear All
41
58
  </div>
42
59
  <% end %>
60
+ <% else %>
61
+ <div class="w-[88px]"></div> <!-- Placeholder to maintain spacing when button is hidden -->
43
62
  <% end %>
44
63
  </div>
45
64
  </div>
@@ -60,8 +79,8 @@
60
79
  </div>
61
80
 
62
81
  <!-- Main content -->
63
- <div class="flex-1 overflow-y-auto">
64
- <div class="p-8">
82
+ <div class="flex-1 overflow-y-auto lg:ml-0">
83
+ <div class="p-8 lg:p-8 sm:p-4">
65
84
  <turbo-frame id="email_content">
66
85
  <%= yield %>
67
86
  </turbo-frame>
@@ -0,0 +1,21 @@
1
+ <turbo-stream action="remove" target="<%= dom_id(@email) %>">
2
+ </turbo-stream>
3
+
4
+ <% if RailsMail::Email.count == 0 %>
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>
10
+ <% elsif @email.id == @current_email_id.to_i%>
11
+ <turbo-stream action="update" target="email_content">
12
+ <template>
13
+ <div class="" data-controller="redirect" data-redirect-url-value="<%= email_path(@email.next_email) %>">
14
+ <div class="flex justify-center items-center min-h-screen">
15
+ <div class="animate-spin rounded-full h-12 w-12 border-b-2 border-gray-900"></div>
16
+ </div>
17
+ </div>
18
+ </template>
19
+ </turbo-stream>
20
+
21
+ <% end %>
@@ -2,24 +2,42 @@
2
2
  on_current_page = current_page?(RailsMail::Engine.routes.url_helpers.email_path(email))
3
3
  highlight_class = on_current_page ? 'bg-gray-300' : ''
4
4
  %>
5
- <%= link_to RailsMail::Engine.routes.url_helpers.email_path(email),
6
- class: "block px-3 py-2 rounded-md hover:bg-gray-200 #{highlight_class} active:bg-gray-300 focus:bg-gray-300",
7
- data: {
8
- "turbo-frame": "email_content",
9
- "turbo-action": "advance",
10
- "turbo-prefetch": "false",
11
- "email-highlight-target": "link",
12
- "email-id": email.id,
13
- action: "click->email-highlight#highlight"
14
- } do %>
15
- <div class="text-sm font-medium text-gray-900 truncate"><%= email.subject %></div>
16
- <div class="text-xs text-gray-500">
17
- <span class="truncate"><%= email.from %></span>
18
- <time
19
- data-controller="timeago"
20
- data-timeago-datetime-value="<%= email.created_at.iso8601 %>"
21
- data-timeago-refresh-interval-value="1000"
22
- data-timeago-include-seconds-value="true"
23
- class="ml-2 text-gray-400"><%= time_ago_in_words(email.created_at) %> ago</time>
24
- </div>
5
+ <%= content_tag :div, id: dom_id(email), class: "group flex items-center px-3 py-2 hover:bg-gray-200 #{highlight_class} active:bg-gray-300 focus:bg-gray-300" do %>
6
+ <%= link_to RailsMail::Engine.routes.url_helpers.email_path(email),
7
+ class: "flex-1 min-w-0 rounded-md",
8
+ data: {
9
+ "turbo-frame": "email_content",
10
+ "turbo-action": "advance",
11
+ "turbo-prefetch": "false",
12
+ "email-highlight-target": "link",
13
+ "email-id": email.id,
14
+ action: "click->email-highlight#highlight"
15
+ } do %>
16
+ <div class="min-w-0">
17
+ <div class="text-sm font-medium text-gray-900 truncate"><%= email.subject %></div>
18
+ <div class="text-xs text-gray-500">
19
+ <span class="truncate"><%= email.from %></span>
20
+ <time
21
+ data-controller="timeago"
22
+ data-timeago-datetime-value="<%= email.created_at.iso8601 %>"
23
+ data-timeago-refresh-interval-value="1000"
24
+ data-timeago-include-seconds-value="true"
25
+ class="ml-2 text-gray-400"><%= time_ago_in_words(email.created_at) %> ago</time>
26
+ </div>
27
+ </div>
28
+ <% end %>
29
+
30
+ <%= button_to email_path(email, current_email_id: @email.id),
31
+ method: :delete,
32
+ class: "hidden group-hover:block p-1 hover:bg-gray-300 rounded",
33
+ form: {
34
+ data: {
35
+ turbo_confirm: "Are you sure you want to delete this email?",
36
+ turbo_frame: "_top"
37
+ }
38
+ } do %>
39
+ <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 text-gray-500 transition-colors" fill="none" viewBox="0 0 24 24" stroke="currentColor">
40
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
41
+ </svg>
42
+ <% end %>
25
43
  <% end %>
data/config/routes.rb CHANGED
@@ -4,7 +4,7 @@ RailsMail::Engine.routes.draw do
4
4
  get "static/:name", action: :static, as: :frontend_static, constraints: { format: %w[css js] }
5
5
  end
6
6
 
7
- resources :emails, only: [ :index, :show ] do
7
+ resources :emails, only: [ :index, :show, :destroy ] do
8
8
  collection do
9
9
  delete "emails/destroy_all", to: "emails#destroy_all", as: :destroy_all
10
10
  end
@@ -1,3 +1,3 @@
1
1
  module RailsMail
2
- VERSION = "0.9.3"
2
+ VERSION = "0.9.4"
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.3
4
+ version: 0.9.4
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-02-09 00:00:00.000000000 Z
11
+ date: 2025-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -69,6 +69,7 @@ files:
69
69
  - app/frontend/rails_mail/modules/consumer.js
70
70
  - app/frontend/rails_mail/modules/email_highlight_controller.js
71
71
  - app/frontend/rails_mail/modules/emails_channel.js
72
+ - app/frontend/rails_mail/modules/redirect_controller.js
72
73
  - app/frontend/rails_mail/modules/timeago.js
73
74
  - app/frontend/rails_mail/style.css
74
75
  - app/frontend/rails_mail/vendor/action_cable.js
@@ -80,11 +81,13 @@ files:
80
81
  - app/helpers/rails_mail/turbo_helper.rb
81
82
  - app/jobs/rails_mail/trim_emails_job.rb
82
83
  - app/models/rails_mail/email.rb
84
+ - app/views/layouts/rails_mail/_title.html.erb
83
85
  - app/views/layouts/rails_mail/application.html.erb
84
86
  - app/views/rails_mail/emails/_email.html.erb
85
87
  - app/views/rails_mail/emails/_empty_state.html.erb
86
88
  - app/views/rails_mail/emails/_form.html.erb
87
89
  - app/views/rails_mail/emails/_show.html.erb
90
+ - app/views/rails_mail/emails/destroy.turbo_stream.erb
88
91
  - app/views/rails_mail/emails/destroy_all.turbo_stream.erb
89
92
  - app/views/rails_mail/emails/edit.html.erb
90
93
  - app/views/rails_mail/emails/index.html.erb