better_mailer_previews 0.2.20 → 0.2.28

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: dc50335b20fd694cd623ade83f7b0217324c3713b4dba534817dfc717c43b3a8
4
- data.tar.gz: a9d4bf8682df2cf1dd4db468b52a49d89520a04e1d4de5f02cf71883a9bb18d5
3
+ metadata.gz: 6b55ed293faad4b003956d26224117ad77520b892e8ce53672f7fdd80d4d705b
4
+ data.tar.gz: 1ac4db58fc2d7908b6fff297b84abd78e7a5fbace0597c6770af752e2e7c1720
5
5
  SHA512:
6
- metadata.gz: b133c05951985fe354f83f457d8ffcea0a10fe1534c0e844c1f3c6c116c5357cc36cd7df03c65301aa6ff912db9f5bafc0a773e8af50ce6226fc39017801ba53
7
- data.tar.gz: cbbc6793b5b47de89f1ba54c990884c367d17685fd3070cc36b9bf8e36a594744c89c4d414060d4d88b339bef8472e8fe35aafb216922644fd94a450845bfdb2
6
+ metadata.gz: '08de5907815e0f6977a13f000f1f24caa69b6a5b0cd0622970dfcd2f4e39c47e52c9428910e68772b6576f7a9fa0300068c2714d009ee8ff23983ecfd7d9d7db'
7
+ data.tar.gz: 338158e8cb7bbb5dae4ed2d3dbb71f25525e561514c0941c24bb1908e747d2c5fcaa9b53b30a858c7bb056bcdb7ee2e40fb16175f662050974b41743c5cc122a
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,34 @@ end
50
53
  4. Run your Rails app, and visit `localhost:3000/better_mailer_previews`.
51
54
  5. Profit ✨
52
55
 
53
- ## How can I get previews to show up for my mailers?
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
- 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).
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
 
59
81
  ## More from me
60
82
 
61
- If you like this gem, you'll probably like some of my other Ruby on Rails stuff — 
83
+ If you like this gem, you'll probably like some of my other work (all Ruby on Rails stuff)
62
84
 
63
85
  - [RailsNotes, my Ruby on Rails blog](https://railsnotes.xyz)
64
86
  - [My Ruby on Rails Newsletter](https://railsnotes.xyz/newsletter)
@@ -68,4 +90,5 @@ If you like this gem, you'll probably like some of my other Ruby on Rails stuff
68
90
  If you want updates, you can also [follow me on Twitter](https://twitter.com/hrrsnbbnt)
69
91
 
70
92
  ## License
93
+
71
94
  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}"
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
- <h1 class="text-5xl font-medium tracking-tighter"><%= @mailer_name.titleize %> — <%= @email_type.titleize %></h1>
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
@@ -2,4 +2,5 @@ BetterMailerPreviews::Engine.routes.draw do
2
2
  root to: 'mailers#index'
3
3
 
4
4
  get '/:mailer_name/:email_type', to: 'mailers#show', as: :mailer_preview
5
+ post '/:mailer_name/:email_type/send', to: 'mailers#send_email', as: :send_mailer_email
5
6
  end
@@ -1,3 +1,3 @@
1
1
  module BetterMailerPreviews
2
- VERSION = "0.2.20"
2
+ VERSION = "0.2.28"
3
3
  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: 0.2.20
4
+ version: 0.2.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harrison Broadbent
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-03 00:00:00.000000000 Z
11
+ date: 2023-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 7.1.2
19
+ version: 5.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 7.1.2
26
+ version: 5.0.0
27
27
  description: Better Mailer Previews is a Ruby on Rails gem that makes it easier to
28
28
  preview ActionMailer email templates.
29
29
  email:
@@ -60,7 +60,7 @@ metadata:
60
60
  homepage_uri: https://github.com/harrison-broadbent/better_mailer_previews
61
61
  source_code_uri: https://github.com/harrison-broadbent/better_mailer_previews
62
62
  changelog_uri: https://github.com/harrison-broadbent/better_mailer_previews
63
- post_install_message:
63
+ post_install_message:
64
64
  rdoc_options: []
65
65
  require_paths:
66
66
  - lib
@@ -75,8 +75,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  requirements: []
78
- rubygems_version: 3.4.1
79
- signing_key:
78
+ rubygems_version: 3.4.10
79
+ signing_key:
80
80
  specification_version: 4
81
81
  summary: Better Mailer Previews is a Ruby on Rails gem that makes it easier to preview
82
82
  ActionMailer email templates.