 
   get "/" do
     if Enum.empty?(all_emails()) do
-      conn |> render(:ok, "no_emails.html")
+      conn |> render_no_emails
     else
-      conn |> render(:ok, "index.html", emails: all_emails(), selected_email: newest_email())
+      conn |> render_index(newest_email())
     end
   end
 
   get "/:id" do
     if email = SentEmail.get(id) do
-      conn |> render(:ok, "index.html", emails: all_emails(), selected_email: email)
+      conn |> render_index(email)
     else
-      conn |> render(:not_found, "email_not_found.html")
+      conn |> render_not_found
     end
   end
 

defmodule Bamboo.EmailPreviewPlug do
  use Plug.Router
  alias Bamboo.SentEmail

  @moduledoc """
  A plug that can be used in your router to see delivered emails.

      |> Plug.Conn.put_resp_content_type("text/html")
      |> send_resp(:ok, email.html_body || "")
    else
      conn
      |> Plug.Conn.put_resp_content_type("text/html")
      |> render_not_found
    end
  end

