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.ex b/lib/dotcom_web.ex index d9252994e8..6a566d9574 100644 --- a/lib/dotcom_web.ex +++ b/lib/dotcom_web.ex @@ -69,6 +69,7 @@ defmodule DotcomWeb do project_path: 3, project_update_path: 3, project_update_path: 4, + static_integrity: 2, static_url: 2 ] diff --git a/lib/dotcom_web/templates/fare/proposed_sales_locations.html.heex b/lib/dotcom_web/templates/fare/proposed_sales_locations.html.heex index 142b46225c..ea01c4a062 100644 --- a/lib/dotcom_web/templates/fare/proposed_sales_locations.html.heex +++ b/lib/dotcom_web/templates/fare/proposed_sales_locations.html.heex @@ -33,7 +33,12 @@ <% else %> - <% end %> diff --git a/lib/dotcom_web/templates/fare/retail_sales_locations.html.heex b/lib/dotcom_web/templates/fare/retail_sales_locations.html.heex index e30b8dc1b1..773a752457 100644 --- a/lib/dotcom_web/templates/fare/retail_sales_locations.html.heex +++ b/lib/dotcom_web/templates/fare/retail_sales_locations.html.heex @@ -18,7 +18,12 @@ <% else %> - <% end %> 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..44d549bbad --- /dev/null +++ b/lib/dotcom_web/templates/layout/root.html.heex @@ -0,0 +1,177 @@ + + + + + + + <%= 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) %> +
+ + <%!-- Begin unnecessary scripts --%> + <%!-- React isn't even needed on most pages, but in production app.js will + somehow fail to execute unless additional scripts are included here. Let's + revisit this when we either refactor app.js or refactor how we bundle + scripts for production via Webpack. --%> + + <%!-- End unnecessary scripts --%> + + + + + + <% end %> + diff --git a/lib/dotcom_web/templates/project/index.html.eex b/lib/dotcom_web/templates/project/index.html.eex deleted file mode 100644 index 359f76fa46..0000000000 --- a/lib/dotcom_web/templates/project/index.html.eex +++ /dev/null @@ -1,31 +0,0 @@ -<%= if Application.get_env(:dotcom, :dev_server?) do %> - -<% else %> - - -<% end %> - -
-
-
-
- <%= PartialView.paragraph("paragraphs/custom-html/projects-index", @conn) %> -
-
-
-
- -
- <%= content_tag(:div, [ - DotcomWeb.PartialView.render("_search_input.html", - Map.merge(assigns, %{ - placeholder: "Enter keyword(s)", - aria_label: "Enter keywords", - prefix: "projects" - })) -], id: "projects-search", class: "hidden-no-js c-search-bar c-search-bar--embedded-large") %> -
- -<% [banner | featured] = if Enum.empty?(@featured_project_teasers) do [nil] else @featured_project_teasers end %> - -<%= render "_all_projects.html", banner: banner, projects: @project_teasers, featured_projects: featured, project_updates: @project_update_teasers, placeholder_image_url: @placeholder_image_url %> diff --git a/lib/dotcom_web/templates/project/index.html.heex b/lib/dotcom_web/templates/project/index.html.heex new file mode 100644 index 0000000000..017fa7f677 --- /dev/null +++ b/lib/dotcom_web/templates/project/index.html.heex @@ -0,0 +1,62 @@ +<%= if Application.get_env(:dotcom, :dev_server?) do %> + +<% else %> + + +<% end %> + +
+
+
+
+ <%= PartialView.paragraph("paragraphs/custom-html/projects-index", @conn) %> +
+
+
+
+ +
+ <%= content_tag( + :div, + [ + DotcomWeb.PartialView.render( + "_search_input.html", + Map.merge(assigns, %{ + placeholder: "Enter keyword(s)", + aria_label: "Enter keywords", + prefix: "projects" + }) + ) + ], + id: "projects-search", + class: "hidden-no-js c-search-bar c-search-bar--embedded-large" + ) %> +
+ +<% [banner | featured] = + if Enum.empty?(@featured_project_teasers) do + [nil] + else + @featured_project_teasers + end %> + +<%= render("_all_projects.html", + banner: banner, + projects: @project_teasers, + featured_projects: featured, + project_updates: @project_update_teasers, + placeholder_image_url: @placeholder_image_url +) %> diff --git a/lib/dotcom_web/templates/schedule/_line.html.eex b/lib/dotcom_web/templates/schedule/_line.html.eex deleted file mode 100644 index 5303c823c7..0000000000 --- a/lib/dotcom_web/templates/schedule/_line.html.eex +++ /dev/null @@ -1,42 +0,0 @@ -<% branchesEmpty? = Enum.empty?(@branches) %> - - -<% map_pdf_url = @route.type |> Routes.Route.type_atom() |> MapHelpers.map_pdf_url() %> - -<%= if display_map_link?(@route.type) do %> - -<% end %> - - - -"> -<%= if Application.get_env(:dotcom, :dev_server?) do %> - -<% else %> - - -<% end %> - -
- <%= DotcomWeb.AlertView.group(alerts: @alerts, route: @route, date_time: @date_time, priority_filter: :high) %> -
- - <%= if branchesEmpty? do%> -
-
"> - <%= render "_empty.html", date: @date, direction: Routes.Route.direction_name(@route, @direction_id), origin: nil, destination: nil, conn: @conn, error: assigns[:schedule_error] %> -
-
- <% end %> - -
-
-
diff --git a/lib/dotcom_web/templates/schedule/_line.html.heex b/lib/dotcom_web/templates/schedule/_line.html.heex new file mode 100644 index 0000000000..b61319bd4e --- /dev/null +++ b/lib/dotcom_web/templates/schedule/_line.html.heex @@ -0,0 +1,74 @@ +<% branchesEmpty? = Enum.empty?(@branches) %> + + +<% map_pdf_url = @route.type |> Routes.Route.type_atom() |> MapHelpers.map_pdf_url() %> + +<%= if display_map_link?(@route.type) do %> + +<% end %> + + + + +<%= if Application.get_env(:dotcom, :dev_server?) do %> + +<% else %> + + +<% end %> + +
+ <%= DotcomWeb.AlertView.group( + alerts: @alerts, + route: @route, + date_time: @date_time, + priority_filter: :high + ) %> +
+ <%= if branchesEmpty? do %> +
+
+ <%= render("_empty.html", + date: @date, + direction: Routes.Route.direction_name(@route, @direction_id), + origin: nil, + destination: nil, + conn: @conn, + error: assigns[:schedule_error] + ) %> +
+
+ <% end %> + +
+
+
diff --git a/lib/dotcom_web/templates/stop/show.html.eex b/lib/dotcom_web/templates/stop/show.html.eex deleted file mode 100644 index f7827f37f7..0000000000 --- a/lib/dotcom_web/templates/stop/show.html.eex +++ /dev/null @@ -1,12 +0,0 @@ -"> -
-
-
- -<%= if Application.get_env(:dotcom, :dev_server?) do %> - -<% else %> - - - -<% end %> diff --git a/lib/dotcom_web/templates/stop/show.html.heex b/lib/dotcom_web/templates/stop/show.html.heex new file mode 100644 index 0000000000..3a65cdd27a --- /dev/null +++ b/lib/dotcom_web/templates/stop/show.html.heex @@ -0,0 +1,36 @@ + +
+
+
+ +<%= if Application.get_env(:dotcom, :dev_server?) do %> + +<% else %> + + + +<% end %> diff --git a/lib/dotcom_web/templates/transit_near_me/index.html.eex b/lib/dotcom_web/templates/transit_near_me/index.html.eex deleted file mode 100644 index e59b15755c..0000000000 --- a/lib/dotcom_web/templates/transit_near_me/index.html.eex +++ /dev/null @@ -1,20 +0,0 @@ -<% error = Phoenix.Flash.get(@flash, :info) %> -<%= if error, do: DotcomWeb.PartialView.FullscreenError.render_error(error) %> -
-

Transit Near Me

- - <%= render "_input.html", location: @location, conn: @conn %> -
-"> - - -
- <%= render_react(assigns) %> -
- -<%= if Application.get_env(:dotcom, :dev_server?) do %> - -<% else %> - - -<% end %> diff --git a/lib/dotcom_web/templates/transit_near_me/index.html.heex b/lib/dotcom_web/templates/transit_near_me/index.html.heex new file mode 100644 index 0000000000..856271e9ee --- /dev/null +++ b/lib/dotcom_web/templates/transit_near_me/index.html.heex @@ -0,0 +1,42 @@ +<% error = Phoenix.Flash.get(@flash, :info) %> +<%= if error, do: DotcomWeb.PartialView.FullscreenError.render_error(error) %> +
+

Transit Near Me

+ + <%= render("_input.html", location: @location, conn: @conn) %> +
+ + + +
+ <%= render_react(assigns) %> +
+ +<%= if Application.get_env(:dotcom, :dev_server?) do %> + +<% else %> + + +<% end %> diff --git a/lib/dotcom_web/templates/trip_plan/index.html.heex b/lib/dotcom_web/templates/trip_plan/index.html.heex index e75dac3100..f31d31495c 100644 --- a/lib/dotcom_web/templates/trip_plan/index.html.heex +++ b/lib/dotcom_web/templates/trip_plan/index.html.heex @@ -3,7 +3,12 @@
<%= render("_sidebar.html", assigns) %>
- + <%= case assigns[:query] do %> <% %{itineraries: {:ok, _}} -> %>

<% else %> - - <% end %> <% _ -> %> @@ -46,7 +61,12 @@ - +

<%= if Application.get_env(:dotcom, :dev_server?) do %> <% else %> - - <% end %> <% 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