From 79fb98a722f77783f32c7120fc4f88ea1034e81c Mon Sep 17 00:00:00 2001 From: Mitchell Hanberg Date: Wed, 20 Apr 2022 00:00:11 -0400 Subject: [PATCH] Remove phx generator templates --- priv/templates/temple.gen.html/controller.ex | 62 ---------- .../temple.gen.html/controller_test.exs | 89 -------------- priv/templates/temple.gen.html/edit.html.exs | 7 -- priv/templates/temple.gen.html/form.html.exs | 15 --- priv/templates/temple.gen.html/index.html.exs | 27 ----- priv/templates/temple.gen.html/new.html.exs | 7 -- priv/templates/temple.gen.html/show.html.exs | 16 --- priv/templates/temple.gen.html/view.ex | 3 - priv/templates/temple.gen.layout/app.html.eex | 36 ------ .../temple.gen.live/form_component.ex | 55 --------- .../temple.gen.live/form_component.html.lexs | 13 --- priv/templates/temple.gen.live/index.ex | 46 -------- .../templates/temple.gen.live/index.html.lexs | 35 ------ .../templates/temple.gen.live/live_helpers.ex | 23 ---- priv/templates/temple.gen.live/live_test.exs | 110 ------------------ .../temple.gen.live/modal_component.ex | 27 ----- priv/templates/temple.gen.live/show.ex | 21 ---- priv/templates/temple.gen.live/show.html.lexs | 22 ---- 18 files changed, 614 deletions(-) delete mode 100644 priv/templates/temple.gen.html/controller.ex delete mode 100644 priv/templates/temple.gen.html/controller_test.exs delete mode 100644 priv/templates/temple.gen.html/edit.html.exs delete mode 100644 priv/templates/temple.gen.html/form.html.exs delete mode 100644 priv/templates/temple.gen.html/index.html.exs delete mode 100644 priv/templates/temple.gen.html/new.html.exs delete mode 100644 priv/templates/temple.gen.html/show.html.exs delete mode 100644 priv/templates/temple.gen.html/view.ex delete mode 100644 priv/templates/temple.gen.layout/app.html.eex delete mode 100644 priv/templates/temple.gen.live/form_component.ex delete mode 100644 priv/templates/temple.gen.live/form_component.html.lexs delete mode 100644 priv/templates/temple.gen.live/index.ex delete mode 100644 priv/templates/temple.gen.live/index.html.lexs delete mode 100644 priv/templates/temple.gen.live/live_helpers.ex delete mode 100644 priv/templates/temple.gen.live/live_test.exs delete mode 100644 priv/templates/temple.gen.live/modal_component.ex delete mode 100644 priv/templates/temple.gen.live/show.ex delete mode 100644 priv/templates/temple.gen.live/show.html.lexs diff --git a/priv/templates/temple.gen.html/controller.ex b/priv/templates/temple.gen.html/controller.ex deleted file mode 100644 index a5cc457..0000000 --- a/priv/templates/temple.gen.html/controller.ex +++ /dev/null @@ -1,62 +0,0 @@ -defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Controller do - use <%= inspect context.web_module %>, :controller - - alias <%= inspect context.module %> - alias <%= inspect schema.module %> - - def index(conn, _params) do - <%= schema.plural %> = <%= inspect context.alias %>.list_<%= schema.plural %>() - render(conn, "index.html", <%= schema.plural %>: <%= schema.plural %>) - end - - def new(conn, _params) do - changeset = <%= inspect context.alias %>.change_<%= schema.singular %>(%<%= inspect schema.alias %>{}) - render(conn, "new.html", changeset: changeset) - end - - def create(conn, %{<%= inspect schema.singular %> => <%= schema.singular %>_params}) do - case <%= inspect context.alias %>.create_<%= schema.singular %>(<%= schema.singular %>_params) do - {:ok, <%= schema.singular %>} -> - conn - |> put_flash(:info, "<%= schema.human_singular %> created successfully.") - |> redirect(to: Routes.<%= schema.route_helper %>_path(conn, :show, <%= schema.singular %>)) - - {:error, %Ecto.Changeset{} = changeset} -> - render(conn, "new.html", changeset: changeset) - end - end - - def show(conn, %{"id" => id}) do - <%= schema.singular %> = <%= inspect context.alias %>.get_<%= schema.singular %>!(id) - render(conn, "show.html", <%= schema.singular %>: <%= schema.singular %>) - end - - def edit(conn, %{"id" => id}) do - <%= schema.singular %> = <%= inspect context.alias %>.get_<%= schema.singular %>!(id) - changeset = <%= inspect context.alias %>.change_<%= schema.singular %>(<%= schema.singular %>) - render(conn, "edit.html", <%= schema.singular %>: <%= schema.singular %>, changeset: changeset) - end - - def update(conn, %{"id" => id, <%= inspect schema.singular %> => <%= schema.singular %>_params}) do - <%= schema.singular %> = <%= inspect context.alias %>.get_<%= schema.singular %>!(id) - - case <%= inspect context.alias %>.update_<%= schema.singular %>(<%= schema.singular %>, <%= schema.singular %>_params) do - {:ok, <%= schema.singular %>} -> - conn - |> put_flash(:info, "<%= schema.human_singular %> updated successfully.") - |> redirect(to: Routes.<%= schema.route_helper %>_path(conn, :show, <%= schema.singular %>)) - - {:error, %Ecto.Changeset{} = changeset} -> - render(conn, "edit.html", <%= schema.singular %>: <%= schema.singular %>, changeset: changeset) - end - end - - def delete(conn, %{"id" => id}) do - <%= schema.singular %> = <%= inspect context.alias %>.get_<%= schema.singular %>!(id) - {:ok, _<%= schema.singular %>} = <%= inspect context.alias %>.delete_<%= schema.singular %>(<%= schema.singular %>) - - conn - |> put_flash(:info, "<%= schema.human_singular %> deleted successfully.") - |> redirect(to: Routes.<%= schema.route_helper %>_path(conn, :index)) - end -end diff --git a/priv/templates/temple.gen.html/controller_test.exs b/priv/templates/temple.gen.html/controller_test.exs deleted file mode 100644 index 6e7c93d..0000000 --- a/priv/templates/temple.gen.html/controller_test.exs +++ /dev/null @@ -1,89 +0,0 @@ -defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>ControllerTest do - use <%= inspect context.web_module %>.ConnCase - - alias <%= inspect context.module %> - - @create_attrs <%= inspect schema.params.create %> - @update_attrs <%= inspect schema.params.update %> - @invalid_attrs <%= inspect for {key, _} <- schema.params.create, into: %{}, do: {key, nil} %> - - def fixture(:<%= schema.singular %>) do - {:ok, <%= schema.singular %>} = <%= inspect context.alias %>.create_<%= schema.singular %>(@create_attrs) - <%= schema.singular %> - end - - describe "index" do - test "lists all <%= schema.plural %>", %{conn: conn} do - conn = get(conn, Routes.<%= schema.route_helper %>_path(conn, :index)) - assert html_response(conn, 200) =~ "Listing <%= schema.human_plural %>" - end - end - - describe "new <%= schema.singular %>" do - test "renders form", %{conn: conn} do - conn = get(conn, Routes.<%= schema.route_helper %>_path(conn, :new)) - assert html_response(conn, 200) =~ "New <%= schema.human_singular %>" - end - end - - describe "create <%= schema.singular %>" do - test "redirects to show when data is valid", %{conn: conn} do - conn = post(conn, Routes.<%= schema.route_helper %>_path(conn, :create), <%= schema.singular %>: @create_attrs) - - assert %{id: id} = redirected_params(conn) - assert redirected_to(conn) == Routes.<%= schema.route_helper %>_path(conn, :show, id) - - conn = get(conn, Routes.<%= schema.route_helper %>_path(conn, :show, id)) - assert html_response(conn, 200) =~ "Show <%= schema.human_singular %>" - end - - test "renders errors when data is invalid", %{conn: conn} do - conn = post(conn, Routes.<%= schema.route_helper %>_path(conn, :create), <%= schema.singular %>: @invalid_attrs) - assert html_response(conn, 200) =~ "New <%= schema.human_singular %>" - end - end - - describe "edit <%= schema.singular %>" do - setup [:create_<%= schema.singular %>] - - test "renders form for editing chosen <%= schema.singular %>", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do - conn = get(conn, Routes.<%= schema.route_helper %>_path(conn, :edit, <%= schema.singular %>)) - assert html_response(conn, 200) =~ "Edit <%= schema.human_singular %>" - end - end - - describe "update <%= schema.singular %>" do - setup [:create_<%= schema.singular %>] - - test "redirects when data is valid", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do - conn = put(conn, Routes.<%= schema.route_helper %>_path(conn, :update, <%= schema.singular %>), <%= schema.singular %>: @update_attrs) - assert redirected_to(conn) == Routes.<%= schema.route_helper %>_path(conn, :show, <%= schema.singular %>) - - conn = get(conn, Routes.<%= schema.route_helper %>_path(conn, :show, <%= schema.singular %>))<%= if schema.string_attr do %> - assert html_response(conn, 200) =~ <%= inspect Mix.Phoenix.Schema.default_param(schema, :update) %><% else %> - assert html_response(conn, 200)<% end %> - end - - test "renders errors when data is invalid", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do - conn = put(conn, Routes.<%= schema.route_helper %>_path(conn, :update, <%= schema.singular %>), <%= schema.singular %>: @invalid_attrs) - assert html_response(conn, 200) =~ "Edit <%= schema.human_singular %>" - end - end - - describe "delete <%= schema.singular %>" do - setup [:create_<%= schema.singular %>] - - test "deletes chosen <%= schema.singular %>", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do - conn = delete(conn, Routes.<%= schema.route_helper %>_path(conn, :delete, <%= schema.singular %>)) - assert redirected_to(conn) == Routes.<%= schema.route_helper %>_path(conn, :index) - assert_error_sent 404, fn -> - get(conn, Routes.<%= schema.route_helper %>_path(conn, :show, <%= schema.singular %>)) - end - end - end - - defp create_<%= schema.singular %>(_) do - <%= schema.singular %> = fixture(:<%= schema.singular %>) - {:ok, <%= schema.singular %>: <%= schema.singular %>} - end -end diff --git a/priv/templates/temple.gen.html/edit.html.exs b/priv/templates/temple.gen.html/edit.html.exs deleted file mode 100644 index 7d1077a..0000000 --- a/priv/templates/temple.gen.html/edit.html.exs +++ /dev/null @@ -1,7 +0,0 @@ -h1 do: "Edit <%= schema.human_singular %>" - -render("form.html", Map.put(assigns, :action, Routes.<%= schema.route_helper %>_path(@conn, :update, @<%= schema.singular %>))) - -span do - link "Back", to: Routes.<%= schema.route_helper %>_path(@conn, :index) -end diff --git a/priv/templates/temple.gen.html/form.html.exs b/priv/templates/temple.gen.html/form.html.exs deleted file mode 100644 index 9c45859..0000000 --- a/priv/templates/temple.gen.html/form.html.exs +++ /dev/null @@ -1,15 +0,0 @@ -form_for @changeset, @action, fn f -> - if @changeset.action do - div class: "alert alert-danger" do - p do: "Oops, something went wrong! Please check the errors below." - end - end <%= for {label, input, error} <- inputs, input do %> - <%= label %> - <%= input %> - <%= error %> - <% end %> - - div do - submit "Save" - end -end diff --git a/priv/templates/temple.gen.html/index.html.exs b/priv/templates/temple.gen.html/index.html.exs deleted file mode 100644 index 3c2e8be..0000000 --- a/priv/templates/temple.gen.html/index.html.exs +++ /dev/null @@ -1,27 +0,0 @@ -h1 do: "Listing <%= schema.human_plural %>" - -table do - thead do - tr do <%= for {k, _} <- schema.attrs do %> - th do: "<%= Phoenix.Naming.humanize(Atom.to_string(k)) %>"<% end %> - th() - end - tbody do - for <%= schema.singular %> <- @<%= schema.plural %> do - tr do <%= for {k, _} <- schema.attrs do %> - td do: <%= schema.singular %>.<%= k %> <% end %> - td do - link "Show", to: Routes.<%= schema.route_helper %>_path(@conn, :show, <%= schema.singular %>) - link "Edit", to: Routes.<%= schema.route_helper %>_path(@conn, :edit, <%= schema.singular %>) - link "Delete", to: Routes.<%= schema.route_helper %>_path(@conn, :delete, <%= schema.singular %>), - method: :delete, data: [confirm: "Are you sure?"] - end - end - end - end - end -end - -span do - link "New <%= schema.human_singular %>", to: Routes.<%= schema.route_helper %>_path(@conn, :new) -end diff --git a/priv/templates/temple.gen.html/new.html.exs b/priv/templates/temple.gen.html/new.html.exs deleted file mode 100644 index cae1fab..0000000 --- a/priv/templates/temple.gen.html/new.html.exs +++ /dev/null @@ -1,7 +0,0 @@ -h1 do: "New <%= schema.human_singular %>" - -render("form.html", Map.put(assigns, :action, Routes.<%= schema.route_helper %>_path(@conn, :create))) - -span do - link "Back", to: Routes.<%= schema.route_helper %>_path(@conn, :index) -end diff --git a/priv/templates/temple.gen.html/show.html.exs b/priv/templates/temple.gen.html/show.html.exs deleted file mode 100644 index 3793797..0000000 --- a/priv/templates/temple.gen.html/show.html.exs +++ /dev/null @@ -1,16 +0,0 @@ -h1 do: "Show <%= schema.human_singular %>" - -ul do <%= for {k, _} <- schema.attrs do %> - li do - strong do: "<%= Phoenix.Naming.humanize(Atom.to_string(k)) %>" - @<%= schema.singular %>.<%= k %> - end <% end %> - - span do - link "Edit", to: Routes.<%= schema.route_helper %>_path(@conn, :edit, @<%= schema.singular %>) - end - - span do - link "Back", to: Routes.<%= schema.route_helper %>_path(@conn, :index) - end -end diff --git a/priv/templates/temple.gen.html/view.ex b/priv/templates/temple.gen.html/view.ex deleted file mode 100644 index e828b07..0000000 --- a/priv/templates/temple.gen.html/view.ex +++ /dev/null @@ -1,3 +0,0 @@ -defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>View do - use <%= inspect context.web_module %>, :view -end diff --git a/priv/templates/temple.gen.layout/app.html.eex b/priv/templates/temple.gen.layout/app.html.eex deleted file mode 100644 index b89cf13..0000000 --- a/priv/templates/temple.gen.layout/app.html.eex +++ /dev/null @@ -1,36 +0,0 @@ -html lang: "en" do - head do - meta charset: "utf-8" - meta http_equiv: "X-UA-Compatible", content: "IE=edge" - meta name: "viewport", content: "width=device-width, initial-scale=1.0" - title "<%= application_module %> ยท Phoenix Framework" - - link rel: "stylesheet", href: Routes.static_path(@conn, "/css/app.css") - end - - body do - header do - section class: "container" do - nav role: "navigation" do - ul do - li do: a("Get Started", href: "https://hexdocs.pm/phoenix/overview.html") - end - end - - a href: "http://phoenixframework.org/", class: "phx-logo" do - img src: Routes.static_path(@conn, "/images/phoenix.png"), - alt: "Phoenix Framework Logo" - end - end - end - - main role: "main", class: "container" do - p get_flash(@conn, :info), class: "alert alert-info", role: "alert" - p get_flash(@conn, :error), class: "alert alert-danger", role: "alert" - - @inner_content - end - - script type: "text/javascript", src: Routes.static_path(@conn, "/js/app.js") - end -end diff --git a/priv/templates/temple.gen.live/form_component.ex b/priv/templates/temple.gen.live/form_component.ex deleted file mode 100644 index 6957239..0000000 --- a/priv/templates/temple.gen.live/form_component.ex +++ /dev/null @@ -1,55 +0,0 @@ -defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.FormComponent do - use <%= inspect context.web_module %>, :live_component - - alias <%= inspect context.module %> - - @impl true - def update(%{<%= schema.singular %>: <%= schema.singular %>} = assigns, socket) do - changeset = <%= inspect context.alias %>.change_<%= schema.singular %>(<%= schema.singular %>) - - {:ok, - socket - |> assign(assigns) - |> assign(:changeset, changeset)} - end - - @impl true - def handle_event("validate", %{"<%= schema.singular %>" => <%= schema.singular %>_params}, socket) do - changeset = - socket.assigns.<%= schema.singular %> - |> <%= inspect context.alias %>.change_<%= schema.singular %>(<%= schema.singular %>_params) - |> Map.put(:action, :validate) - - {:noreply, assign(socket, :changeset, changeset)} - end - - def handle_event("save", %{"<%= schema.singular %>" => <%= schema.singular %>_params}, socket) do - save_<%= schema.singular %>(socket, socket.assigns.action, <%= schema.singular %>_params) - end - - defp save_<%= schema.singular %>(socket, :edit, <%= schema.singular %>_params) do - case <%= inspect context.alias %>.update_<%= schema.singular %>(socket.assigns.<%= schema.singular %>, <%= schema.singular %>_params) do - {:ok, _<%= schema.singular %>} -> - {:noreply, - socket - |> put_flash(:info, "<%= schema.human_singular %> updated successfully") - |> push_redirect(to: socket.assigns.return_to)} - - {:error, %Ecto.Changeset{} = changeset} -> - {:noreply, assign(socket, :changeset, changeset)} - end - end - - defp save_<%= schema.singular %>(socket, :new, <%= schema.singular %>_params) do - case <%= inspect context.alias %>.create_<%= schema.singular %>(<%= schema.singular %>_params) do - {:ok, _<%= schema.singular %>} -> - {:noreply, - socket - |> put_flash(:info, "<%= schema.human_singular %> created successfully") - |> push_redirect(to: socket.assigns.return_to)} - - {:error, %Ecto.Changeset{} = changeset} -> - {:noreply, assign(socket, changeset: changeset)} - end - end -end diff --git a/priv/templates/temple.gen.live/form_component.html.lexs b/priv/templates/temple.gen.live/form_component.html.lexs deleted file mode 100644 index 44a3fdc..0000000 --- a/priv/templates/temple.gen.live/form_component.html.lexs +++ /dev/null @@ -1,13 +0,0 @@ -h2 do: @title - -f = form_for @changeset, "#", id: "<%= schema.singular %>-form", - phx_target: @myself, - phx_change: "validate", - phx_submit: "save" -<%= for {label, input, error} <- inputs, input do %> - <%= label %> - <%= input %> - <%= error %> -<% end %> - submit "Save", phx_disable_with: "Saving..." -"" diff --git a/priv/templates/temple.gen.live/index.ex b/priv/templates/temple.gen.live/index.ex deleted file mode 100644 index f46c53b..0000000 --- a/priv/templates/temple.gen.live/index.ex +++ /dev/null @@ -1,46 +0,0 @@ -defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.Index do - use <%= inspect context.web_module %>, :live_view - - alias <%= inspect context.module %> - alias <%= inspect schema.module %> - - @impl true - def mount(_params, _session, socket) do - {:ok, assign(socket, :<%= schema.collection %>, list_<%= schema.plural %>())} - end - - @impl true - def handle_params(params, _url, socket) do - {:noreply, apply_action(socket, socket.assigns.live_action, params)} - end - - defp apply_action(socket, :edit, %{"id" => id}) do - socket - |> assign(:page_title, "Edit <%= schema.human_singular %>") - |> assign(:<%= schema.singular %>, <%= inspect context.alias %>.get_<%= schema.singular %>!(id)) - end - - defp apply_action(socket, :new, _params) do - socket - |> assign(:page_title, "New <%= schema.human_singular %>") - |> assign(:<%= schema.singular %>, %<%= inspect schema.alias %>{}) - end - - defp apply_action(socket, :index, _params) do - socket - |> assign(:page_title, "Listing <%= schema.human_plural %>") - |> assign(:<%= schema.singular %>, nil) - end - - @impl true - def handle_event("delete", %{"id" => id}, socket) do - <%= schema.singular %> = <%= inspect context.alias %>.get_<%= schema.singular %>!(id) - {:ok, _} = <%= inspect context.alias %>.delete_<%= schema.singular %>(<%= schema.singular %>) - - {:noreply, assign(socket, :<%= schema.collection %>, list_<%=schema.plural %>())} - end - - defp list_<%= schema.plural %> do - <%= inspect context.alias %>.list_<%= schema.plural %>() - end -end diff --git a/priv/templates/temple.gen.live/index.html.lexs b/priv/templates/temple.gen.live/index.html.lexs deleted file mode 100644 index c0ba217..0000000 --- a/priv/templates/temple.gen.live/index.html.lexs +++ /dev/null @@ -1,35 +0,0 @@ -h1 do: "Listing <%= schema.human_plural %>" - -if @live_action in [:new, :edit] do - live_modal @socket, <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.FormComponent, - id: @<%= schema.singular %>.id || :new, - title: @page_title, - action: @live_action, - <%= schema.singular %>: @<%= schema.singular %>, - return_to: Routes.<%= schema.route_helper %>_index_path(@socket, :index) -end - -table do - thead do - tr do -<%= for {k, _} <- schema.attrs do %> th do: "<%= Phoenix.Naming.humanize(Atom.to_string(k)) %>" -<% end %> - th - end - end - tbody id: "<%= schema.plural %>" do - for <%= schema.singular %> <- @<%= schema.collection %> do - tr id: "<%= schema.singular %>-<%%= <%= schema.singular %>.id %>" do -<%= for {k, _} <- schema.attrs do %> td do: <%= schema.singular %>.<%= k %> -<% end %> - td do - span do: live_redirect "Show", to: Routes.<%= schema.route_helper %>_show_path(@socket, :show, <%= schema.singular %>) - span do: live_patch "Edit", to: Routes.<%= schema.route_helper %>_index_path(@socket, :edit, <%= schema.singular %>) - span do: link "Delete", to: "#", phx_click: "delete", phx_value_id: <%= schema.singular %>.id, data: [confirm: "Are you sure?"] - end - end - end - end -end - -span do: live_patch "New <%= schema.human_singular %>", to: Routes.<%= schema.route_helper %>_index_path(@socket, :new) diff --git a/priv/templates/temple.gen.live/live_helpers.ex b/priv/templates/temple.gen.live/live_helpers.ex deleted file mode 100644 index 91f0a5d..0000000 --- a/priv/templates/temple.gen.live/live_helpers.ex +++ /dev/null @@ -1,23 +0,0 @@ -defmodule <%= inspect context.web_module %>.LiveHelpers do - import Phoenix.LiveView.Helpers - - @doc """ - Renders a component inside the `<%= inspect context.web_module %>.ModalComponent` component. - - The rendered modal receives a `:return_to` option to properly update - the URL when the modal is closed. - - ## Examples - - <%%= live_modal @socket, <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.FormComponent, - id: @<%= schema.singular %>.id || :new, - action: @live_action, - <%= schema.singular %>: @<%= schema.singular %>, - return_to: Routes.<%= schema.singular %>_index_path(@socket, :index) %> - """ - def live_modal(socket, component, opts) do - path = Keyword.fetch!(opts, :return_to) - modal_opts = [id: :modal, return_to: path, component: component, opts: opts] - live_component(socket, <%= inspect context.web_module %>.ModalComponent, modal_opts) - end -end diff --git a/priv/templates/temple.gen.live/live_test.exs b/priv/templates/temple.gen.live/live_test.exs deleted file mode 100644 index 2c5609e..0000000 --- a/priv/templates/temple.gen.live/live_test.exs +++ /dev/null @@ -1,110 +0,0 @@ -defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>LiveTest do - use <%= inspect context.web_module %>.ConnCase - - import Phoenix.LiveViewTest - import <%= inspect context.module %>Fixtures - - @create_attrs <%= inspect schema.params.create %> - @update_attrs <%= inspect schema.params.update %> - @invalid_attrs <%= inspect for {key, _} <- schema.params.create, into: %{}, do: {key, nil} %> - - defp create_<%= schema.singular %>(_) do - <%= schema.singular %> = <%= schema.singular %>_fixture() - %{<%= schema.singular %>: <%= schema.singular %>} - end - - describe "Index" do - setup [:create_<%= schema.singular %>] - - test "lists all <%= schema.plural %>", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do - {:ok, _index_live, html} = live(conn, Routes.<%= schema.route_helper %>_index_path(conn, :index)) - - assert html =~ "Listing <%= schema.human_plural %>"<%= if schema.string_attr do %> - assert html =~ <%= schema.singular %>.<%= schema.string_attr %><% end %> - end - - test "saves new <%= schema.singular %>", %{conn: conn} do - {:ok, index_live, _html} = live(conn, Routes.<%= schema.route_helper %>_index_path(conn, :index)) - - assert index_live |> element("a", "New <%= schema.human_singular %>") |> render_click() =~ - "New <%= schema.human_singular %>" - - assert_patch(index_live, Routes.<%= schema.route_helper %>_index_path(conn, :new)) - - assert index_live - |> form("#<%= schema.singular %>-form", <%= schema.singular %>: @invalid_attrs) - |> render_change() =~ "can't be blank" - - {:ok, _, html} = - index_live - |> form("#<%= schema.singular %>-form", <%= schema.singular %>: @create_attrs) - |> render_submit() - |> follow_redirect(conn, Routes.<%= schema.route_helper %>_index_path(conn, :index)) - - assert html =~ "<%= schema.human_singular %> created successfully"<%= if schema.string_attr do %> - assert html =~ "some <%= schema.string_attr %>"<% end %> - end - - test "updates <%= schema.singular %> in listing", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do - {:ok, index_live, _html} = live(conn, Routes.<%= schema.route_helper %>_index_path(conn, :index)) - - assert index_live |> element("#<%= schema.singular %>-#{<%= schema.singular %>.id} a", "Edit") |> render_click() =~ - "Edit <%= schema.human_singular %>" - - assert_patch(index_live, Routes.<%= schema.route_helper %>_index_path(conn, :edit, <%= schema.singular %>)) - - assert index_live - |> form("#<%= schema.singular %>-form", <%= schema.singular %>: @invalid_attrs) - |> render_change() =~ "can't be blank" - - {:ok, _, html} = - index_live - |> form("#<%= schema.singular %>-form", <%= schema.singular %>: @update_attrs) - |> render_submit() - |> follow_redirect(conn, Routes.<%= schema.route_helper %>_index_path(conn, :index)) - - assert html =~ "<%= schema.human_singular %> updated successfully"<%= if schema.string_attr do %> - assert html =~ "some updated <%= schema.string_attr %>"<% end %> - end - - test "deletes <%= schema.singular %> in listing", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do - {:ok, index_live, _html} = live(conn, Routes.<%= schema.route_helper %>_index_path(conn, :index)) - - assert index_live |> element("#<%= schema.singular %>-#{<%= schema.singular %>.id} a", "Delete") |> render_click() - refute has_element?(index_live, "#<%= schema.singular %>-#{<%= schema.singular %>.id}") - end - end - - describe "Show" do - setup [:create_<%= schema.singular %>] - - test "displays <%= schema.singular %>", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do - {:ok, _show_live, html} = live(conn, Routes.<%= schema.route_helper %>_show_path(conn, :show, <%= schema.singular %>)) - - assert html =~ "Show <%= schema.human_singular %>"<%= if schema.string_attr do %> - assert html =~ <%= schema.singular %>.<%= schema.string_attr %><% end %> - end - - test "updates <%= schema.singular %> within modal", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do - {:ok, show_live, _html} = live(conn, Routes.<%= schema.route_helper %>_show_path(conn, :show, <%= schema.singular %>)) - - assert show_live |> element("a", "Edit") |> render_click() =~ - "Edit <%= schema.human_singular %>" - - assert_patch(show_live, Routes.<%= schema.route_helper %>_show_path(conn, :edit, <%= schema.singular %>)) - - assert show_live - |> form("#<%= schema.singular %>-form", <%= schema.singular %>: @invalid_attrs) - |> render_change() =~ "can't be blank" - - {:ok, _, html} = - show_live - |> form("#<%= schema.singular %>-form", <%= schema.singular %>: @update_attrs) - |> render_submit() - |> follow_redirect(conn, Routes.<%= schema.route_helper %>_show_path(conn, :show, <%= schema.singular %>)) - - assert html =~ "<%= schema.human_singular %> updated successfully"<%= if schema.string_attr do %> - assert html =~ "some updated <%= schema.string_attr %>"<% end %> - end - end -end diff --git a/priv/templates/temple.gen.live/modal_component.ex b/priv/templates/temple.gen.live/modal_component.ex deleted file mode 100644 index f41de57..0000000 --- a/priv/templates/temple.gen.live/modal_component.ex +++ /dev/null @@ -1,27 +0,0 @@ -defmodule <%= inspect context.web_module %>.ModalComponent do - use <%= inspect context.web_module %>, :live_component - - @impl true - def render(assigns) do - live_temple do - div id: @id, - class: "phx-modal", - phx_capture_click: "close", - phx_window_keydown: "close", - phx_key: "escape", - phx_target: "##{@id}", - phx_page_loading: true do - - div class: "phx-modal-content" do - live_patch raw("×"), to: @return_to, class: "phx-modal-close" - live_component @socket, @component, @opts - end - end - end - end - - @impl true - def handle_event("close", _, socket) do - {:noreply, push_patch(socket, to: socket.assigns.return_to)} - end -end diff --git a/priv/templates/temple.gen.live/show.ex b/priv/templates/temple.gen.live/show.ex deleted file mode 100644 index b75bade..0000000 --- a/priv/templates/temple.gen.live/show.ex +++ /dev/null @@ -1,21 +0,0 @@ -defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.Show do - use <%= inspect context.web_module %>, :live_view - - alias <%= inspect context.module %> - - @impl true - def mount(_params, _session, socket) do - {:ok, socket} - end - - @impl true - def handle_params(%{"id" => id}, _, socket) do - {:noreply, - socket - |> assign(:page_title, page_title(socket.assigns.live_action)) - |> assign(:<%= schema.singular %>, <%= inspect context.alias %>.get_<%= schema.singular %>!(id))} - end - - defp page_title(:show), do: "Show <%= schema.human_singular %>" - defp page_title(:edit), do: "Edit <%= schema.human_singular %>" -end diff --git a/priv/templates/temple.gen.live/show.html.lexs b/priv/templates/temple.gen.live/show.html.lexs deleted file mode 100644 index 9058a42..0000000 --- a/priv/templates/temple.gen.live/show.html.lexs +++ /dev/null @@ -1,22 +0,0 @@ -h1 do: "Show <%= schema.human_singular %>" - -if @live_action in [:edit] do - live_modal @socket, <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.FormComponent, - id: @<%= schema.singular %>.id, - title: @page_title, - action: @live_action, - <%= schema.singular %>: @<%= schema.singular %>, - return_to: Routes.<%= schema.route_helper %>_show_path(@socket, :show, @<%= schema.singular %>) -end - -ul do -<%= for {k, _} <- schema.attrs do %> - li do - strong do: "<%= Phoenix.Naming.humanize(Atom.to_string(k)) %>:" - @<%= schema.singular %>.<%= k %> - end -<% end %> -end - -span do: live_patch "Edit", to: Routes.<%= schema.route_helper %>_show_path(@socket, :edit, @<%= schema.singular %>), class: "button" -span do: live_redirect "Back", to: Routes.<%= schema.route_helper %>_index_path(@socket, :index)