Merge branch 'fix-lang-not-detected-on-fallback-pages' into 'master'
Fix lang not detected on fallback pages See merge request framasoft/mobilizon!456
This commit is contained in:
commit
503616fa60
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user