     all_emails() |> List.first
   end
 
-  defp render(conn, status, template_name, assigns \\ []) do
-    path = Path.join(__DIR__, template_name <> ".eex")
-    assigns = Keyword.merge(assigns, conn: conn, base_path: base_path(conn))
-    rendered_template = EEx.eval_file(path, assigns: assigns)
-    send_resp(conn, status, rendered_template)
+  defp render_no_emails(conn) do
+    send_resp(conn, :ok, no_emails())
+  end
+
+  defp render_not_found(conn) do
+    assigns = %{base_path: base_path(conn)}
+    send_resp(conn, :not_found, not_found(assigns))
+  end
+
+  defp render_index(conn, email) do
+    assigns = %{
+      conn: conn,
+      base_path: base_path(conn),
+      emails: all_emails(),
+      selected_email: email,
+    }
+    send_resp(conn, :ok, index(assigns))
   end
 
   defp base_path(%{script_name: []}), do: ""

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

