From 90515145a049bebd248b3d288f8459403049abf8 Mon Sep 17 00:00:00 2001 From: Cristen Jones Date: Thu, 21 Nov 2024 17:10:13 -0500 Subject: [PATCH] chore: convert root template to .heex --- lib/dotcom/body_tag.ex | 12 +- lib/dotcom_web/templates/layout/root.html.eex | 111 -------------- .../templates/layout/root.html.heex | 138 ++++++++++++++++++ test/dotcom/body_tag_test.exs | 11 +- 4 files changed, 144 insertions(+), 128 deletions(-) delete mode 100644 lib/dotcom_web/templates/layout/root.html.eex create mode 100644 lib/dotcom_web/templates/layout/root.html.heex diff --git a/lib/dotcom/body_tag.ex b/lib/dotcom/body_tag.ex index 27c473b4c6..ae1a50d93f 100644 --- a/lib/dotcom/body_tag.ex +++ b/lib/dotcom/body_tag.ex @@ -9,17 +9,7 @@ defmodule Dotcom.BodyTag do UI elements. """ - alias PhoenixHTMLHelpers.Tag - - @spec render(Plug.Conn.t()) :: Phoenix.HTML.Safe.t() - def render(conn) do - Tag.tag( - :body, - class: class_name(conn) - ) - end - - defp class_name(conn) do + def class_name(conn) do [ javascript_class(), mticket_class(conn), diff --git a/lib/dotcom_web/templates/layout/root.html.eex b/lib/dotcom_web/templates/layout/root.html.eex deleted file mode 100644 index cbd1103ce8..0000000000 --- a/lib/dotcom_web/templates/layout/root.html.eex +++ /dev/null @@ -1,111 +0,0 @@ - - - - - - - <%= csrf_meta_tag() %> - <% meta_description = assigns[:meta_description] || "Official website of the MBTA -- schedules, maps, and fare information for Greater Boston's public transportation system, including subway, commuter rail, bus routes, and boat lines." %> - - - - - <%= # hide any page in /org directory from search engines - if @conn.request_path == "/org" || String.slice(@conn.request_path, 0..4) == "/org/" do %> - - <% end %> - <%= # hide any page in /charlie directory from search engines - if @conn.request_path == "/charlie" || String.slice(@conn.request_path, 0..8) == "/charlie/" do %> - - <% end %> - <%= # hide any page in /policies/terms-use-charlie directory from search engines - if @conn.request_path == "/policies/terms-use-charlie" || String.slice(@conn.request_path, 0..26) == "/policies/terms-use-charlie" do %> - - <% end %> - <% title = if Phoenix.Controller.view_template(@conn) == "404.html", do: "Page Not Found | MBTA - Massachusetts Bay Transportation Authority", else: title_breadcrumbs(@conn) %> - <%= title %> - " type="image/png"> - " sizes="32x32" type="image/png"> - " sizes="16x16" type="image/vnd.microsoft.icon"> - - - <%= if google_tag_manager_id() do %> - - <% end %> - - - - <%= if Application.get_env(:sentry, :js_dsn) do %> - - <% end %> - - <%= if Application.get_env(:dotcom, :dev_server?) do %> - "> - "> - - - <% else %> - "> - "> - - - <% end %> - - <%= Dotcom.BodyTag.render(@conn) %> -
- Skip to main content - <%= DotcomWeb.PartialView.render "_hidden_icons.html", conn: @conn %> - <%= render "_new_header.html", @conn |> Plug.Conn.assign(:page, get_page_classes(Phoenix.Controller.view_module(@conn), Phoenix.Controller.view_template(@conn))) |> forward_assigns %> - <%= if assigns[:banner_template] do %> -
-
- <%= render __MODULE__, @banner_template, assigns %> -
-
- <% end %> - <%= if assigns[:breadcrumbs] do %> - - <% end %> - <%= if assigns[:search_header?] do %> - <%= render "_searchbar.html", assigns %> - <% end %> -
- <%= content_tag :main, @inner_content, id: "main", tabindex: -1 %> -
<%# /container %> - <%= render __MODULE__, "_footer.html", conn: @conn %> - - <%# Show a warning when browser is Internet Explorer %> - <%= if Application.get_env(:dotcom, :dev_server?) do %> - - <% else %> - - - <% end %> -
-
- - <%= if google_tag_manager_id() do %> - - - - - - - <% end %> - - diff --git a/lib/dotcom_web/templates/layout/root.html.heex b/lib/dotcom_web/templates/layout/root.html.heex new file mode 100644 index 0000000000..cb217fc977 --- /dev/null +++ b/lib/dotcom_web/templates/layout/root.html.heex @@ -0,0 +1,138 @@ + + + + + + + <%= csrf_meta_tag() %> + <% meta_description = + assigns[:meta_description] || + "Official website of the MBTA -- schedules, maps, and fare information for Greater Boston's public transportation system, including subway, commuter rail, bus routes, and boat lines." %> + + + + + <%= # hide any page in /org directory from search engines + if @conn.request_path == "/org" || String.slice(@conn.request_path, 0..4) == "/org/" do %> + + <% end %> + <%= # hide any page in /charlie directory from search engines + if @conn.request_path == "/charlie" || String.slice(@conn.request_path, 0..8) == "/charlie/" do %> + + <% end %> + <%= # hide any page in /policies/terms-use-charlie directory from search engines + if @conn.request_path == "/policies/terms-use-charlie" || String.slice(@conn.request_path, 0..26) == "/policies/terms-use-charlie" do %> + + <% end %> + <% title = + if Phoenix.Controller.view_template(@conn) == "404.html", + do: "Page Not Found | MBTA - Massachusetts Bay Transportation Authority", + else: title_breadcrumbs(@conn) %> + <%= title %> + + + + + + + + + + + <% dev_server? = Application.get_env(:dotcom, :dev_server?) + webpack_path = Application.get_env(:dotcom, :webpack_path) %> + + + + + + + + + + + + <%= content_tag(:body, class: Dotcom.BodyTag.class_name(@conn)) do %> +
+ Skip to main content + <%= DotcomWeb.PartialView.render("_hidden_icons.html", conn: @conn) %> + <%= render( + "_new_header.html", + @conn + |> Plug.Conn.assign( + :page, + get_page_classes( + Phoenix.Controller.view_module(@conn), + Phoenix.Controller.view_template(@conn) + ) + ) + |> forward_assigns + ) %> +
+
+ <%= render(__MODULE__, @banner_template, assigns) %> +
+
+ + <%= if assigns[:search_header?], do: render("_searchbar.html", assigns) %> +
+ <%= content_tag(:main, @inner_content, id: "main", tabindex: -1) %> +
+ <%= render(__MODULE__, "_footer.html", conn: @conn) %> +
+ + + + + + <% end %> + diff --git a/test/dotcom/body_tag_test.exs b/test/dotcom/body_tag_test.exs index d060494fc3..a9a39ca00e 100644 --- a/test/dotcom/body_tag_test.exs +++ b/test/dotcom/body_tag_test.exs @@ -2,34 +2,33 @@ defmodule Dotcom.BodyTagTest do use ExUnit.Case, async: true import Dotcom.BodyTag import Phoenix.ConnTest, only: [build_conn: 0] - import Phoenix.HTML, only: [safe_to_string: 1] import Plug.Conn, only: [put_req_header: 3] - describe "render/1" do + describe "class_name/1" do test "returns mticket if the requisite header is present" do conn = build_conn() |> put_req_header(Application.get_env(:dotcom, Dotcom.BodyTag)[:mticket_header], "") - assert safe_to_string(render(conn)) =~ "no-js mticket" + assert class_name(conn) =~ "no-js mticket" end test "returns mticket if the site is called as mticket.mbtace.com" do conn = %{build_conn() | host: "mticket.mbtace.com"} - assert safe_to_string(render(conn)) =~ "no-js mticket" + assert class_name(conn) =~ "no-js mticket" end test "returns 'cms-preview' if page is loaded with CMS ?preview params" do conn = %{build_conn() | query_params: %{"preview" => nil, "vid" => "latest", "nid" => "6"}} - assert safe_to_string(render(conn)) =~ "no-js cms-preview" + assert class_name(conn) =~ "no-js cms-preview" end test "does not set 'cms-preview' class if page is loaded with missing CMS &nid param" do conn = %{build_conn() | query_params: %{"preview" => nil, "vid" => "latest"}} - refute safe_to_string(render(conn)) =~ "no-js cms-preview" + refute class_name(conn) =~ "no-js cms-preview" end end end