From ecbc5993c478f926328d62d84b62e7eb95c3b61b Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 9 Jun 2020 16:08:03 +0200 Subject: [PATCH] Fix lang not detected on fallback pages Signed-off-by: Thomas Citharel --- lib/web/views/error_view.ex | 13 +++++-------- lib/web/views/page_view.ex | 2 +- test/web/views/error_view_test.exs | 8 ++++++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/web/views/error_view.ex b/lib/web/views/error_view.ex index f5ad17bd6..2eadfa4e0 100644 --- a/lib/web/views/error_view.ex +++ b/lib/web/views/error_view.ex @@ -3,11 +3,12 @@ defmodule Mobilizon.Web.ErrorView do View for errors """ use Mobilizon.Web, :view + alias Mobilizon.Service.Metadata.Instance + alias Mobilizon.Web.PageView - def render("404.html", _assigns) do - with {:ok, index_content} <- File.read(index_file_path()) do - {:safe, index_content} - end + def render("404.html", %{conn: conn}) do + tags = Instance.build_tags() + PageView.inject_tags(conn, tags) end def render("404.json", _assigns) do @@ -48,8 +49,4 @@ defmodule Mobilizon.Web.ErrorView do Logger.warn("Template #{inspect(template)} not found") render("500.html", assigns) end - - defp index_file_path do - Path.join(Application.app_dir(:mobilizon, "priv/static"), "index.html") - end end diff --git a/lib/web/views/page_view.ex b/lib/web/views/page_view.ex index 72e91e189..4dd2b36dc 100644 --- a/lib/web/views/page_view.ex +++ b/lib/web/views/page_view.ex @@ -60,7 +60,7 @@ defmodule Mobilizon.Web.PageView do end @spec inject_tags(Conn.t(), List.t()) :: {:safe, String.t()} - defp inject_tags(conn, tags) do + def inject_tags(conn, tags) do with {:ok, index_content} <- File.read(index_file_path()) do locale = get_locale(conn) diff --git a/test/web/views/error_view_test.exs b/test/web/views/error_view_test.exs index 2efa8570d..8cb250bbb 100644 --- a/test/web/views/error_view_test.exs +++ b/test/web/views/error_view_test.exs @@ -6,9 +6,13 @@ defmodule Mobilizon.Web.ErrorViewTest do alias Mobilizon.Web.ErrorView - test "renders 404.html" do + test "renders 404.html", %{conn: conn} do # Produced HTML might have new lines inside - assert Regex.replace(~r/(\r\n|\n|\r) +/, render_to_string(ErrorView, "404.html", []), " ") =~ + assert Regex.replace( + ~r/(\r\n|\n|\r) +/, + render_to_string(ErrorView, "404.html", %{conn: conn}), + " " + ) =~ "We're sorry but mobilizon doesn't work properly without JavaScript enabled. Please enable it to continue." end