better_mailer_previews 0.2.20

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dc50335b20fd694cd623ade83f7b0217324c3713b4dba534817dfc717c43b3a8
4
+ data.tar.gz: a9d4bf8682df2cf1dd4db468b52a49d89520a04e1d4de5f02cf71883a9bb18d5
5
+ SHA512:
6
+ metadata.gz: b133c05951985fe354f83f457d8ffcea0a10fe1534c0e844c1f3c6c116c5357cc36cd7df03c65301aa6ff912db9f5bafc0a773e8af50ce6226fc39017801ba53
7
+ data.tar.gz: cbbc6793b5b47de89f1ba54c990884c367d17685fd3070cc36b9bf8e36a594744c89c4d414060d4d88b339bef8472e8fe35aafb216922644fd94a450845bfdb2
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright Harrison Broadbent
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # Better Mailer Previews — A lightweight Rails engine for improved email previews.
2
+ Better Mailer Previews is a Ruby on Rails gem that **makes previewing all your ActionMailer email templates easier.**
3
+
4
+ This gem/engine builds on top of native Rails mailer previews, with a few key enhancements like — 
5
+
6
+ - **Shows _all_ your previews _live_ on the homepage**
7
+ - **Easily resize individual mailers, for testing responsive layouts**
8
+ - **Fully compatible with, and can live alongside, native [Rails ActionMailer Previews](https://guides.rubyonrails.org/action_mailer_basics.html#previewing-emails)**
9
+
10
+ Here's a little demo I've put together ↓
11
+
12
+ <p align="center">
13
+ <kbd>
14
+ <img width=640 src="https://github.com/harrison-broadbent/better_mailer_previews/assets/5293153/07f8ee5c-2363-4d73-a3d6-00376a2d2c6e" />
15
+ </kbd>
16
+ </p>
17
+
18
+ ## Why did I build this?
19
+
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
+
22
+ This gem is my idea brought to life, and I hope you'll find it useful!
23
+
24
+ ## Getting Started
25
+ 1. Add this line to the development group in your application's Gemfile:
26
+
27
+ ```ruby
28
+ group :development do
29
+ ...
30
+ gem "better_mailer_previews"
31
+ end
32
+ ```
33
+
34
+ 2. And then execute:
35
+ ```bash
36
+ $ bundle
37
+ ```
38
+
39
+ 3. Finally, you need to mount this engine in your `routes.rb` file —
40
+
41
+ ```ruby
42
+ # routes.rb
43
+
44
+ Rails.application.routes.draw do
45
+ mount BetterMailerPreviews::Engine, at: "/better_mailer_previews" if Rails.env.development?
46
+ ...
47
+ end
48
+ ```
49
+
50
+ 4. Run your Rails app, and visit `localhost:3000/better_mailer_previews`.
51
+ 5. Profit ✨
52
+
53
+ ## How can I get previews to show up for my mailers?
54
+
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).
56
+
57
+ 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
+
59
+ ## More from me
60
+
61
+ If you like this gem, you'll probably like some of my other Ruby on Rails stuff — 
62
+
63
+ - [RailsNotes, my Ruby on Rails blog](https://railsnotes.xyz)
64
+ - [My Ruby on Rails Newsletter](https://railsnotes.xyz/newsletter)
65
+ - [RAILSG, a command builder for Rails generator commands](https://railsg.xyz)
66
+ - [RailsNotes UI, a library of ActionMailer email templates and components](https://railsnotesui.xyz)
67
+
68
+ If you want updates, you can also [follow me on Twitter](https://twitter.com/hrrsnbbnt)
69
+
70
+ ## License
71
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/setup"
2
+
3
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
5
+
6
+ load "rails/tasks/statistics.rake"
7
+
8
+ require "bundler/gem_tasks"
@@ -0,0 +1 @@
1
+ //= link_directory ../stylesheets/better_mailer_previews .css
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module BetterMailerPreviews
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,29 @@
1
+ module BetterMailerPreviews
2
+ class MailersController < ActionController::Base
3
+ layout "better_mailer_previews/application"
4
+
5
+ def index
6
+ mailer_previews = ActionMailer::Preview.all
7
+ preview_emails = mailer_previews.map do |preview|
8
+ { preview: preview, emails: preview.emails }
9
+ end
10
+
11
+ @urls_by_mailer = {}
12
+ preview_emails.each do |entry|
13
+ mailer_name = entry[:preview].name.underscore.gsub("_preview", "")
14
+ urls = entry[:emails].map do |email|
15
+ email_name = email.underscore
16
+ "/rails/mailers/#{mailer_name}/#{email_name}"
17
+ end
18
+ @urls_by_mailer[mailer_name] = urls
19
+ end
20
+ end
21
+
22
+ def show
23
+ @mailer_name = params[:mailer_name]
24
+ @email_type = params[:email_type]
25
+
26
+ @url_for_mailer = "/rails/mailers/#{@mailer_name}/#{@email_type}"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,4 @@
1
+ module BetterMailerPreviews
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module BetterMailerPreviews
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module BetterMailerPreviews
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: "from@example.com"
4
+ layout "mailer"
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module BetterMailerPreviews
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ <div class="mt-12 text-sm text-gray-400">
2
+ <p><a class="text-gray-700 hover:underline" href="https://github.com/harrison-broadbent/better_mailer_previews">better mailer previews</a> is a gem by me, <a class="text-gray-700 hover:underline" href="https://twitter.com/hrrsnbbnt">harrison broadbent.</a></p>
3
+ <p>you might like my other stuff too; a library of <a class="text-gray-700 hover:underline" href="https://railsnotesui.xyz">email templates for actionmailer</a>, or my <a class="text-gray-700 hover:underline" href="https://railsnotes.xyz">ruby on rails blog.</a></p>
4
+ </div>
@@ -0,0 +1,30 @@
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
+ <div class="max-w-7xl mx-auto">
9
+ <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
+ <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">
11
+ <% @urls_by_mailer.each do |mailer_name, urls| %>
12
+ <%= link_to "▶ #{mailer_name.titleize}", "##{mailer_name}", class: "text-sm hover:underline" unless urls.empty? %>
13
+ <% end %>
14
+ </div>
15
+ <% @urls_by_mailer.each do |mailer_name, urls| %>
16
+ <% next if urls.empty? %>
17
+ <div id=<%= mailer_name %> class="flex my-24">
18
+ <p class="text-xl font-light w-64"><%= mailer_name.titleize %></p>
19
+ <div class="border p-6 grid grid-cols-3 gap-x-8 gap-y-16">
20
+ <% urls.each do |url| %>
21
+ <div class="flex flex-col space-y-4 wrap">
22
+ <iframe src=<%= url %> frameborder="0" class="frame border border-gray-300" loading="lazy"></iframe>
23
+ <%= link_to "Preview #{url.split('/')[-2...].map { |segment| segment.split('_').map(&:capitalize).join }.join('.')} →", url.split('/')[-2...].join('/').prepend("/better_mailer_previews/"), class: "!-mt-[400px] hover:underline" %>
24
+ </div>
25
+ <% end %>
26
+ </div>
27
+ </div>
28
+ <% end %>
29
+ <%= render "footer" %>
30
+ </div>
@@ -0,0 +1,28 @@
1
+ <h1 class="text-5xl font-medium tracking-tighter"><%= @mailer_name.titleize %> — <%= @email_type.titleize %></h1>
2
+ <div class="flex my-4 py-4 border gap-x-8 items-center">
3
+ <div class="w-3/4 pr-12 pb-4 border-r-2 resize-x overflow-auto">
4
+ <div class="shrink-0 flex items-center bg-gray-950 py-2 px-4 z-10 rounded-t-lg">
5
+ <div class="hidden sm:block shrink-0 mr-2 h-4 w-4 bg-gray-600 rounded-full"></div>
6
+ <div class="hidden sm:block shrink-0 mr-2 h-4 w-4 bg-gray-600 rounded-full"></div>
7
+ <div class="hidden sm:block shrink-0 mr-2 h-4 w-4 bg-gray-600 rounded-full"></div>
8
+ <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">
9
+ <div class="truncate"><span class="font-medium text-gray-100">Mailer Preview</span> — <%= "#{@mailer_name}/#{@email_type}" %></div>
10
+ </div>
11
+ </div>
12
+ <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>
14
+ </div>
15
+ </div>
16
+ <div class="w-1/4">
17
+ <div class="relative mx-auto border-gray-800 dark:border-gray-800 bg-gray-800 border-[14px] rounded-[2.5rem] h-[640px] w-[320px] shadow-xl">
18
+ <div class="w-[148px] h-[18px] bg-gray-800 top-0 rounded-b-[1rem] left-1/2 -translate-x-1/2 absolute"></div>
19
+ <div class="h-[46px] w-[3px] bg-gray-800 absolute -start-[17px] top-[124px] rounded-s-lg"></div>
20
+ <div class="h-[46px] w-[3px] bg-gray-800 absolute -start-[17px] top-[178px] rounded-s-lg"></div>
21
+ <div class="h-[64px] w-[3px] bg-gray-800 absolute -end-[17px] top-[142px] rounded-e-lg"></div>
22
+ <div class="rounded-[2rem] overflow-hidden w-[292px] h-[612px] bg-white dark:bg-gray-800">
23
+ <iframe src=<%= @url_for_mailer %> frameborder="0" class="w-[292px] h-[612px]"></iframe>
24
+ </div>
25
+ </div>
26
+ </div>
27
+ </div>
28
+ <%= render "footer" %>
@@ -0,0 +1,21 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Better mailer previews</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+ <%= stylesheet_link_tag "better_mailer_previews/application", media: "all" %>
8
+ <script src="https://cdn.tailwindcss.com"></script>
9
+ <style>
10
+ .wrap { width: 300px; height: 450px; padding: 0; overflow: hidden; }
11
+ .frame { width: 600px; height: 900px; border: 1px solid black; }
12
+ .frame { transform: scale(0.5); transform-origin: 0 0; }
13
+ ::-webkit-resizer {
14
+ background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='currentColor' class='w-5 h-5'><path fill-rule='evenodd' d='M17 10a.75.75 0 01-.75.75H5.612l4.158 3.96a.75.75 0 11-1.04 1.08l-5.5-5.25a.75.75 0 010-1.08l5.5-5.25a.75.75 0 111.04 1.08L5.612 9.25H16.25A.75.75 0 0117 10z' clip-rule='evenodd' /></svg>");
15
+ }
16
+ </style>
17
+ </head>
18
+ <body class="w-full h-full p-12 bg-gray-50">
19
+ <%= yield %>
20
+ </body>
21
+ </html>
@@ -0,0 +1 @@
1
+ Rails.application.config.assets.precompile += %w(better_mailer_previews/application.css better_mailer_previews/application.js)
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ BetterMailerPreviews::Engine.routes.draw do
2
+ root to: 'mailers#index'
3
+
4
+ get '/:mailer_name/:email_type', to: 'mailers#show', as: :mailer_preview
5
+ end
@@ -0,0 +1,5 @@
1
+ module BetterMailerPreviews
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace BetterMailerPreviews
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module BetterMailerPreviews
2
+ VERSION = "0.2.20"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "better_mailer_previews/version"
2
+ require "better_mailer_previews/engine"
3
+
4
+ module BetterMailerPreviews
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :better_mailer_previews do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: better_mailer_previews
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.20
5
+ platform: ruby
6
+ authors:
7
+ - Harrison Broadbent
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-12-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 7.1.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 7.1.2
27
+ description: Better Mailer Previews is a Ruby on Rails gem that makes it easier to
28
+ preview ActionMailer email templates.
29
+ email:
30
+ - harrison@railsnotes.xyz
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - MIT-LICENSE
36
+ - README.md
37
+ - Rakefile
38
+ - app/assets/config/better_mailer_previews_manifest.js
39
+ - app/assets/stylesheets/better_mailer_previews/application.css
40
+ - app/controllers/better_mailer_previews/application_controller.rb
41
+ - app/controllers/better_mailer_previews/mailers_controller.rb
42
+ - app/helpers/better_mailer_previews/application_helper.rb
43
+ - app/jobs/better_mailer_previews/application_job.rb
44
+ - app/mailers/better_mailer_previews/application_mailer.rb
45
+ - app/models/better_mailer_previews/application_record.rb
46
+ - app/views/better_mailer_previews/mailers/_footer.html.erb
47
+ - app/views/better_mailer_previews/mailers/index.html.erb
48
+ - app/views/better_mailer_previews/mailers/show.html.erb
49
+ - app/views/layouts/better_mailer_previews/application.html.erb
50
+ - config/initializers/assets.rb
51
+ - config/routes.rb
52
+ - lib/better_mailer_previews.rb
53
+ - lib/better_mailer_previews/engine.rb
54
+ - lib/better_mailer_previews/version.rb
55
+ - lib/tasks/better_mailer_previews_tasks.rake
56
+ homepage: https://github.com/harrison-broadbent/better_mailer_previews
57
+ licenses:
58
+ - MIT
59
+ metadata:
60
+ homepage_uri: https://github.com/harrison-broadbent/better_mailer_previews
61
+ source_code_uri: https://github.com/harrison-broadbent/better_mailer_previews
62
+ changelog_uri: https://github.com/harrison-broadbent/better_mailer_previews
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 3.4.1
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Better Mailer Previews is a Ruby on Rails gem that makes it easier to preview
82
+ ActionMailer email templates.
83
+ test_files: []