pattern match result

This commit is contained in:
byte[] 2019-11-11 12:35:11 -05:00
parent 0f75c973aa
commit 510abe5103
2 changed files with 9 additions and 10 deletions

View file

@ -1,4 +1,4 @@
= if !!@object.user and !@object.anonymous do = if !!@object.user and !@object.anonymous do
= anonymous_avatar(@object)
- else
= user_avatar(@object) = user_avatar(@object)
- else
= anonymous_avatar(@object)

View file

@ -16,15 +16,14 @@ defmodule PhilomenaWeb.UserAttributionView do
img_tag(Routes.static_path(PhilomenaWeb.Endpoint, "/images/no_avatar.svg"), class: class) img_tag(Routes.static_path(PhilomenaWeb.Endpoint, "/images/no_avatar.svg"), class: class)
end end
def user_avatar(object, class \\ "avatar--100px") do def user_avatar(object, class \\ "avatar--100px")
user = object.user
if user && user.avatar do def user_avatar(%{user: nil} = object, class),
img_tag(avatar_url_root() <> object.user.avatar, class: class) do: anonymous_avatar(object, class)
else def user_avatar(%{user: %{avatar: nil}} = object, class),
anonymous_avatar(object, class) do: anonymous_avatar(object, class)
end def user_avatar(%{user: %{avatar: avatar}}, class),
end do: img_tag(avatar_url_root() <> avatar, class: class)
defp avatar_url_root do defp avatar_url_root do
Application.get_env(:philomena, :avatar_url_root) Application.get_env(:philomena, :avatar_url_root)