better_mailer_previews 0.2.21 → 0.2.29
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 +34 -7
- data/app/controllers/better_mailer_previews/mailers_controller.rb +28 -0
- data/app/views/better_mailer_previews/mailers/index.html.erb +0 -7
- data/app/views/better_mailer_previews/mailers/show.html.erb +18 -2
- data/config/routes.rb +1 -0
- 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: ed2b8e431d05cc6cce1a49590111765e8d89edfb95af2ddd4f230bf875654e24
|
|
4
|
+
data.tar.gz: 79d319691b7b7c63db0c5304ecbe7f24a30aac358810d1d641f9e8b4409de456
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: de462d3acc0e681fac6f96fce65ceac01ab3b2f20b3499949504d077fb6399c75a0a93b9c656c8f0770acaf4d9b60f1fc140fa68ddbfc0a35a329893379b8892
|
|
7
|
+
data.tar.gz: 7ede2f31ccae45095e56dbc70b324f83e9e92e224f1761bf6bf51127bd5aab991f41d7ded10f7fad94129c95ff3abcf1c93aca811890393c139e9d8bdc33794f
|
data/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# Better Mailer Previews — A lightweight Rails engine for improved email previews.
|
|
2
|
+
|
|
2
3
|
Better Mailer Previews is a Ruby on Rails gem that **makes previewing all your ActionMailer email templates easier.**
|
|
3
4
|
|
|
4
|
-
This gem/engine builds on top of native Rails mailer previews, with a few key enhancements like —
|
|
5
|
+
This gem/engine builds on top of native Rails mailer previews, with a few key enhancements like —
|
|
5
6
|
|
|
6
7
|
- **Shows _all_ your previews _live_ on the homepage**
|
|
7
8
|
- **Easily resize individual mailers, for testing responsive layouts**
|
|
@@ -15,13 +16,14 @@ Here's a little demo I've put together ↓
|
|
|
15
16
|
</kbd>
|
|
16
17
|
</p>
|
|
17
18
|
|
|
18
|
-
## Why did I build this?
|
|
19
|
+
## Why did I build this?
|
|
19
20
|
|
|
20
|
-
I've used native Rails mailer previews extensively for building my [ActionMailer email templates](https://railsnotesui.xyz), but they're pretty barebones and lacking. In particular, I wanted a way to bulk-preview templates (rather than checking them one by one). I also wanted to be able to easily resize the email container for testing responsive layouts.
|
|
21
|
+
I've used native Rails mailer previews extensively for building my [ActionMailer email templates](https://railsnotesui.xyz), but they're pretty barebones and lacking. In particular, I wanted a way to bulk-preview templates (rather than checking them one by one). I also wanted to be able to easily resize the email container for testing responsive layouts.
|
|
21
22
|
|
|
22
23
|
This gem is my idea brought to life, and I hope you'll find it useful!
|
|
23
24
|
|
|
24
25
|
## Getting Started
|
|
26
|
+
|
|
25
27
|
1. Add this line to the development group in your application's Gemfile:
|
|
26
28
|
|
|
27
29
|
```ruby
|
|
@@ -32,11 +34,12 @@ end
|
|
|
32
34
|
```
|
|
33
35
|
|
|
34
36
|
2. And then execute:
|
|
37
|
+
|
|
35
38
|
```bash
|
|
36
39
|
$ bundle
|
|
37
40
|
```
|
|
38
41
|
|
|
39
|
-
3. Finally, you need to mount this engine in your `routes.rb` file —
|
|
42
|
+
3. Finally, you need to mount this engine in your `routes.rb` file —
|
|
40
43
|
|
|
41
44
|
```ruby
|
|
42
45
|
# routes.rb
|
|
@@ -50,15 +53,38 @@ end
|
|
|
50
53
|
4. Run your Rails app, and visit `localhost:3000/better_mailer_previews`.
|
|
51
54
|
5. Profit ✨
|
|
52
55
|
|
|
53
|
-
##
|
|
56
|
+
## Sending email previews to an email address
|
|
57
|
+
|
|
58
|
+
This gem let's you send your email previews to an email address, using whatever default delivery method you have configured.
|
|
54
59
|
|
|
55
|
-
|
|
60
|
+
Better Mailer Previews sends it's emails using whichever `config.action_mailer.delivery_method` is defined for the environment. For example, if you're using [Mailhog](https://github.com/mailhog/MailHog) in development to test your emails, you might have a configuration like this —
|
|
61
|
+
|
|
62
|
+
```ruby
|
|
63
|
+
# config/environments/development.rb
|
|
64
|
+
#
|
|
65
|
+
Rails.application.configure do
|
|
66
|
+
...
|
|
67
|
+
config.action_mailer.delivery_method = :smtp
|
|
68
|
+
config.action_mailer.smtp_settings = {address: "127.0.0.1", port: 1025}
|
|
69
|
+
config.action_mailer.raise_delivery_errors = false
|
|
70
|
+
end
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
In this case, Better Mailer Previews will send it's emails to Mailhog too (since it uses your existing configuration). If you want to send emails to a _live_ inbox (like your personal email), you'd need to configure a live delivery method for the current environment.
|
|
74
|
+
|
|
75
|
+
## How can I get previews to show up for my mailers?
|
|
76
|
+
|
|
77
|
+
This engine will display all the [Actionmailer Previews](https://guides.rubyonrails.org/action_mailer_basics.html#previewing-emails) defined in the host Ruby on Rails app. These are the mailer previews you've defined in `test/mailers/previews`, for use with native [Actionmailer Previews](https://guides.rubyonrails.org/action_mailer_basics.html#previewing-emails).
|
|
56
78
|
|
|
57
79
|
For all the mailers you'd like to preview, you need to set up the corresponding `ActionMailer::Preview` class. Once you've done that, this engine will automatically pull them all in and let you preview them!
|
|
58
80
|
|
|
81
|
+
## Other things to note
|
|
82
|
+
|
|
83
|
+
- You need an internet connection for this to engine to work properly. This engine tries to load the TailwindCSS package via a CDN, to handle the app styling. Your browser will cache the package after you first download it though, which is handy.
|
|
84
|
+
|
|
59
85
|
## More from me
|
|
60
86
|
|
|
61
|
-
If you like this gem, you'll probably like some of my other Ruby on Rails stuff —
|
|
87
|
+
If you like this gem, you'll probably like some of my other work (all Ruby on Rails stuff) —
|
|
62
88
|
|
|
63
89
|
- [RailsNotes, my Ruby on Rails blog](https://railsnotes.xyz)
|
|
64
90
|
- [My Ruby on Rails Newsletter](https://railsnotes.xyz/newsletter)
|
|
@@ -68,4 +94,5 @@ If you like this gem, you'll probably like some of my other Ruby on Rails stuff
|
|
|
68
94
|
If you want updates, you can also [follow me on Twitter](https://twitter.com/hrrsnbbnt)
|
|
69
95
|
|
|
70
96
|
## License
|
|
97
|
+
|
|
71
98
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
@@ -25,5 +25,33 @@ module BetterMailerPreviews
|
|
|
25
25
|
|
|
26
26
|
@url_for_mailer = "/rails/mailers/#{@mailer_name}/#{@email_type}"
|
|
27
27
|
end
|
|
28
|
+
|
|
29
|
+
def send_email
|
|
30
|
+
# mailer_name: underscore_case of base mailer name | invoice_mailer
|
|
31
|
+
# email_type: string mailer method to call on class | "round"
|
|
32
|
+
# email_address: string email address to send to | "test@t.com"
|
|
33
|
+
mailer_name = params[:mailer_name]
|
|
34
|
+
email_type = params[:email_type]
|
|
35
|
+
email_address = params[:email_address]
|
|
36
|
+
|
|
37
|
+
# Instantiate the preview class (ie: InvoiceMailerPreview),
|
|
38
|
+
# then render it's preview html into a string.
|
|
39
|
+
preview_class = mailer_name.concat("_preview").camelize.constantize
|
|
40
|
+
preview_method = email_type.to_sym
|
|
41
|
+
mail = preview_class.new.public_send(preview_method).message
|
|
42
|
+
html_content = mail.body.decoded
|
|
43
|
+
|
|
44
|
+
# Send the string we just rendered, to the email from the form submission.
|
|
45
|
+
ActionMailer::Base.mail(
|
|
46
|
+
content_type: "text/html",
|
|
47
|
+
from: "better-mailer-previews@railsnotes.xyz",
|
|
48
|
+
to: email_address,
|
|
49
|
+
subject: "#{preview_class.to_s}.#{preview_method} (via BetterMailerPreviews)",
|
|
50
|
+
body: html_content,
|
|
51
|
+
).deliver_now
|
|
52
|
+
|
|
53
|
+
flash[:notice] = "sent #{preview_class.to_s}.#{preview_method} to #{email_address} [via #{Rails.application.config.action_mailer.delivery_method}]"
|
|
54
|
+
redirect_back(fallback_location: root_path)
|
|
55
|
+
end
|
|
28
56
|
end
|
|
29
57
|
end
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
<% @urls_by_mailer = {
|
|
2
|
-
"bg_mailer" => [],
|
|
3
|
-
"invoice_mailer" => ["https://en.wikipedia.org/wiki/Game_Boy_Advance", "/rails/mailers/invoice_mailer/dark", "/rails/mailers/invoice_mailer/round", "/rails/mailers/invoice_mailer/square", "/rails/mailers/invoice_mailer/stripe"],
|
|
4
|
-
"marketing_mailer" => ["/rails/mailers/marketing_mailer/basic", "/rails/mailers/marketing_mailer/dark", "/rails/mailers/marketing_mailer/round", "/rails/mailers/marketing_mailer/square"],
|
|
5
|
-
"primary_action_mailer" => ["/rails/mailers/primary_action_mailer/basic", "/rails/mailers/primary_action_mailer/dark", "/rails/mailers/primary_action_mailer/round", "/rails/mailers/primary_action_mailer/square"],
|
|
6
|
-
"special_offers_mailer" => ["/rails/mailers/special_offers_mailer/basic", "/rails/mailers/special_offers_mailer/dark", "/rails/mailers/special_offers_mailer/round", "/rails/mailers/special_offers_mailer/square"],
|
|
7
|
-
} %>
|
|
8
1
|
<div class="max-w-7xl mx-auto">
|
|
9
2
|
<p class="text-6xl font-medium tracking-tighter">Better Mailer Previews <span class="text-xs font-light tracking-normal">v<%= BetterMailerPreviews::VERSION %></span></p>
|
|
10
3
|
<div class="mt-4 grid grid-cols-4 gap-x-4 sticky top-8 z-10 border p-2 bg-gray-50/30 backdrop-blur-md w-fit rounded-sm">
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
<
|
|
1
|
+
<div class="w-full flex justify-between items-end">
|
|
2
|
+
<h1 class="text-5xl font-medium tracking-tighter"><%= @mailer_name.titleize %> — <%= @email_type.titleize %></h1>
|
|
3
|
+
<div class="">
|
|
4
|
+
<%= form_with url: send_mailer_email_path(mailer_name: @mailer_name, email_type: @email_type),
|
|
5
|
+
method: :post,
|
|
6
|
+
local: true,
|
|
7
|
+
class: "flex items-end gap-x-2" do |form| %>
|
|
8
|
+
<div class="flex-1">
|
|
9
|
+
<%= form.text_field :email_address, placeholder: "email address...", class: "border text-sm px-1 py-0.5 bg-gray-50 rounded-sm", required: true %>
|
|
10
|
+
</div>
|
|
11
|
+
<div>
|
|
12
|
+
<%= form.submit "Send Email", class: "text-sm border px-1 py-0.5 hover:bg-gray-200 hover:cursor-pointer rounded-sm" %>
|
|
13
|
+
</div>
|
|
14
|
+
<% end %>
|
|
15
|
+
<p class="text-xs text-gray-400 mt-1 w-64"><%= flash[:notice] %></p>
|
|
16
|
+
</div>
|
|
17
|
+
</div>
|
|
2
18
|
<div class="flex my-4 py-4 border gap-x-8 items-center">
|
|
3
19
|
<div class="w-3/4 pr-12 pb-4 border-r-2 resize-x overflow-auto">
|
|
4
20
|
<div class="shrink-0 flex items-center bg-gray-950 py-2 px-4 z-10 rounded-t-lg">
|
|
@@ -10,7 +26,7 @@
|
|
|
10
26
|
</div>
|
|
11
27
|
</div>
|
|
12
28
|
<div class="bg-gray-950 px-2 rounded-b-lg pb-2">
|
|
13
|
-
<iframe src=<%= @url_for_mailer %> frameborder="0" class="w-full h-[75vh] rounded-md"></iframe>
|
|
29
|
+
<iframe src=<%= @url_for_mailer %> frameborder="0" class="w-full h-[75vh] rounded-md bg-white"></iframe>
|
|
14
30
|
</div>
|
|
15
31
|
</div>
|
|
16
32
|
<div class="w-1/4">
|
data/config/routes.rb
CHANGED
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: 0.2.
|
|
4
|
+
version: 0.2.29
|
|
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-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|