better_mailer_previews 1.0.0 → 1.0.2
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 +4 -4
- data/README.md +1 -0
- data/app/controllers/better_mailer_previews/mailers_controller.rb +8 -6
- data/app/helpers/better_mailer_previews/application_helper.rb +7 -3
- data/app/views/better_mailer_previews/mailers/show.html.erb +7 -4
- data/config/routes.rb +4 -3
- data/lib/better_mailer_previews/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8c29be1158c74ff4d8c0e3cf3aa86961bc8036594f60e6c7c85bc1be716d6598
|
|
4
|
+
data.tar.gz: bd4621808e9762147f33881161e903caa58f7783b835554b2dc604900ee6b429
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8a749e68c91575dad519d4aee7e1e3eef186b6fa02a75bbbc6ddd07807e3599ee2c2281bd252a00f81969bef0bd6f399a700312b17b65dac7c5b21a36d973dec
|
|
7
|
+
data.tar.gz: aca9c4067976f393707452df148feb59c982890fc2471fab82a923339e2717e55c7c8b039ac58c8b65609b66c262dc3501945b188e0f2dc4bcfb20e5663d96c5
|
data/README.md
CHANGED
|
@@ -8,6 +8,7 @@ This gem/engine builds on top of native Rails mailer previews, with a few key en
|
|
|
8
8
|
- **Easily resize individual mailers, for testing responsive layouts**
|
|
9
9
|
- **Forward your previews to an email address (uses the default ActionMailer delivery method for your app).**
|
|
10
10
|
- **Fully compatible with, and can live alongside, native [Rails ActionMailer Previews](https://guides.rubyonrails.org/action_mailer_basics.html#previewing-emails)**
|
|
11
|
+
- **Supports namespaced mailers (think User::SignupMailer) as of v1.0.1**
|
|
11
12
|
|
|
12
13
|
Here's a little demo I've put together ↓
|
|
13
14
|
|
|
@@ -20,23 +20,25 @@ module BetterMailerPreviews
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def show
|
|
23
|
-
@
|
|
23
|
+
@mailer_path = params[:mailer_path]
|
|
24
24
|
@email_type = params[:email_type]
|
|
25
25
|
|
|
26
|
-
@url_for_mailer = "/rails/mailers/#{@
|
|
26
|
+
@url_for_mailer = "/rails/mailers/#{@mailer_path}/#{@email_type}"
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def send_email
|
|
30
|
-
#
|
|
30
|
+
# mailer_path: underscore_case of base mailer path | test/invoice_mailer
|
|
31
31
|
# email_type: string mailer method to call on class | "round"
|
|
32
32
|
# email_address: string email address to send to | "test@t.com"
|
|
33
|
-
|
|
33
|
+
mailer_path = params[:mailer_path]
|
|
34
34
|
email_type = params[:email_type]
|
|
35
35
|
email_address = params[:email_address]
|
|
36
36
|
|
|
37
37
|
# Instantiate the preview class (ie: InvoiceMailerPreview),
|
|
38
38
|
# then render it's preview html into a string.
|
|
39
|
-
|
|
39
|
+
preview_class_string = mailer_path.split("/").map(&:camelize).join("::").concat("Preview")
|
|
40
|
+
preview_class = preview_class_string.constantize
|
|
41
|
+
|
|
40
42
|
preview_method = email_type.to_sym
|
|
41
43
|
mail = preview_class.new.public_send(preview_method).message
|
|
42
44
|
html_content = mail.body.decoded
|
|
@@ -46,7 +48,7 @@ module BetterMailerPreviews
|
|
|
46
48
|
content_type: "text/html",
|
|
47
49
|
from: "better-mailer-previews@railsnotes.xyz",
|
|
48
50
|
to: email_address,
|
|
49
|
-
subject: "#{
|
|
51
|
+
subject: "#{preview_class_string}.#{preview_method} (via BetterMailerPreviews)",
|
|
50
52
|
body: html_content,
|
|
51
53
|
).deliver_now
|
|
52
54
|
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
module BetterMailerPreviews
|
|
2
2
|
module ApplicationHelper
|
|
3
3
|
|
|
4
|
-
# For generating mailer preview link names on mailers/index
|
|
4
|
+
# For generating mailer preview link names on mailers/index,
|
|
5
|
+
# including namespaced methods.
|
|
5
6
|
#
|
|
6
7
|
# input: "/rails/mailers/invoice_mailer/saas"
|
|
7
8
|
# output: "Preview InvoiceMailer.SaaS →"
|
|
8
9
|
#
|
|
9
10
|
def preview_text_for_url(url)
|
|
10
|
-
|
|
11
|
+
camelized = url.split("/")[3...].map { |element| element.camelize }
|
|
12
|
+
last_element = camelized.pop
|
|
13
|
+
pretty_mailer_preview_name = camelized.join("/") + "." + last_element
|
|
14
|
+
|
|
11
15
|
return "Preview #{pretty_mailer_preview_name} →"
|
|
12
16
|
end
|
|
13
17
|
|
|
@@ -18,7 +22,7 @@ module BetterMailerPreviews
|
|
|
18
22
|
#
|
|
19
23
|
def preview_path_for_url(url)
|
|
20
24
|
mounted_engine_path = BetterMailerPreviews::Engine.routes.find_script_name({})
|
|
21
|
-
url.split("/")[
|
|
25
|
+
url.split("/")[3..].join("/").prepend("#{mounted_engine_path}/")
|
|
22
26
|
end
|
|
23
27
|
end
|
|
24
28
|
end
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
<div class="w-full flex justify-between items-end">
|
|
2
|
-
<
|
|
2
|
+
<div class="flex flex-col">
|
|
3
|
+
<%= link_to '← home', root_path, class: "text-sm text-gray-400 w-fit hover:text-gray-700 hover:underline" %>
|
|
4
|
+
<h1 class="text-5xl font-medium tracking-tighter"><%= @mailer_path.titleize %> — <%= @email_type.titleize %></h1>
|
|
5
|
+
</div>
|
|
3
6
|
<div class="">
|
|
4
|
-
<%= form_with url: send_mailer_email_path(
|
|
7
|
+
<%= form_with url: send_mailer_email_path(mailer_path: @mailer_path, email_type: @email_type),
|
|
5
8
|
method: :post,
|
|
6
9
|
local: true,
|
|
7
10
|
class: "flex items-end gap-x-2" do |form| %>
|
|
@@ -15,14 +18,14 @@
|
|
|
15
18
|
<p class="text-xs text-gray-400 mt-1 w-64"><%= flash[:notice] %></p>
|
|
16
19
|
</div>
|
|
17
20
|
</div>
|
|
18
|
-
<div class="flex
|
|
21
|
+
<div class="flex mt-6 mb-4 py-4 border gap-x-8 items-center">
|
|
19
22
|
<div class="w-3/4 pr-12 pb-4 border-r-2 resize-x overflow-auto">
|
|
20
23
|
<div class="shrink-0 flex items-center bg-gray-950 py-2 px-4 z-10 rounded-t-lg">
|
|
21
24
|
<div class="hidden sm:block shrink-0 mr-2 h-4 w-4 bg-gray-600 rounded-full"></div>
|
|
22
25
|
<div class="hidden sm:block shrink-0 mr-2 h-4 w-4 bg-gray-600 rounded-full"></div>
|
|
23
26
|
<div class="hidden sm:block shrink-0 mr-2 h-4 w-4 bg-gray-600 rounded-full"></div>
|
|
24
27
|
<div class="flex-grow flex items-center justify-center sm:ml-6 sm:mr-24 py-2 px-4 bg-gray-600 rounded-full leading-5 text-sm text-gray-200 text-center truncate">
|
|
25
|
-
<div class="truncate"><span class="font-medium text-gray-100">Mailer Preview</span> — <%= "#{@
|
|
28
|
+
<div class="truncate"><span class="font-medium text-gray-100">Mailer Preview</span> — <%= "#{@mailer_path}/#{@email_type}" %></div>
|
|
26
29
|
</div>
|
|
27
30
|
</div>
|
|
28
31
|
<div class="bg-gray-950 px-2 rounded-b-lg pb-2">
|
data/config/routes.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
BetterMailerPreviews::Engine.routes.draw do
|
|
2
|
-
root to:
|
|
2
|
+
root to: "mailers#index"
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
# Wildcard routes to handle namespaced mailers
|
|
5
|
+
get "/*mailer_path/:email_type", to: "mailers#show", as: :mailer_preview
|
|
6
|
+
post "/*mailer_path/:email_type/send", to: "mailers#send_email", as: :send_mailer_email
|
|
6
7
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: better_mailer_previews
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Harrison Broadbent
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2023-12-
|
|
11
|
+
date: 2023-12-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|