From 8cb8294ffd811cba884202a50c53f9ffee4d0a29 Mon Sep 17 00:00:00 2001 From: shibao Date: Thu, 17 Feb 2022 21:47:37 -0500 Subject: [PATCH] add dev email preview route --- .../controllers/email_controller.ex | 23 +++++++++++++++++++ lib/cannery_web/router.ex | 4 ++++ .../templates/layout/empty.html.heex | 1 + 3 files changed, 28 insertions(+) create mode 100644 lib/cannery_web/controllers/email_controller.ex create mode 100644 lib/cannery_web/templates/layout/empty.html.heex diff --git a/lib/cannery_web/controllers/email_controller.ex b/lib/cannery_web/controllers/email_controller.ex new file mode 100644 index 0000000..6b8da4e --- /dev/null +++ b/lib/cannery_web/controllers/email_controller.ex @@ -0,0 +1,23 @@ +defmodule CanneryWeb.EmailController do + @moduledoc """ + A dev controller used to develop on emails + """ + + use CanneryWeb, :controller + alias Cannery.Accounts.User + + plug :put_layout, {CanneryWeb.LayoutView, :email} + + @sample_assigns %{ + email: %{subject: "Example subject"}, + url: "https://cannery.bubbletea.dev/sample_url", + user: %User{email: "sample@email.com"} + } + + @doc """ + Debug route used to preview emails + """ + def preview(conn, %{"id" => template}) do + render(conn, "#{template |> to_string()}.html", @sample_assigns) + end +end diff --git a/lib/cannery_web/router.ex b/lib/cannery_web/router.ex index 1c84ffb..347d729 100644 --- a/lib/cannery_web/router.ex +++ b/lib/cannery_web/router.ex @@ -114,5 +114,9 @@ defmodule CanneryWeb.Router do forward "/mailbox", Plug.Swoosh.MailboxPreview end + + scope "/dev" do + get "/preview/:id", CanneryWeb.EmailController, :preview + end end end diff --git a/lib/cannery_web/templates/layout/empty.html.heex b/lib/cannery_web/templates/layout/empty.html.heex new file mode 100644 index 0000000..0543398 --- /dev/null +++ b/lib/cannery_web/templates/layout/empty.html.heex @@ -0,0 +1 @@ +<%= @inner_content %>