2019-10-06 23:31:48 +02:00
|
|
|
defmodule PhilomenaWeb.PostView do
|
2019-11-27 02:45:57 +01:00
|
|
|
alias Philomena.Attribution
|
|
|
|
alias Textile.Parser
|
|
|
|
|
2019-10-06 23:31:48 +02:00
|
|
|
use PhilomenaWeb, :view
|
2019-11-27 02:45:57 +01:00
|
|
|
|
|
|
|
def textile_safe_author(object) do
|
|
|
|
author_name = author_name(object)
|
|
|
|
|
|
|
|
Parser.parse(%Parser{image_transform: & &1}, author_name)
|
|
|
|
|> case do
|
|
|
|
[{:text, ^author_name}] ->
|
|
|
|
author_name
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
# Cover *all* possibilities.
|
|
|
|
literal =
|
|
|
|
author_name
|
|
|
|
|> String.replace("==]", "==]==][==")
|
|
|
|
|
|
|
|
"[==#{literal}==]"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defp author_name(object) do
|
2019-11-27 05:52:49 +01:00
|
|
|
cond do
|
|
|
|
Attribution.anonymous?(object) || !object.user ->
|
|
|
|
PhilomenaWeb.UserAttributionView.anonymous_name(object)
|
|
|
|
|
|
|
|
true ->
|
|
|
|
object.user.name
|
2019-11-27 02:45:57 +01:00
|
|
|
end
|
|
|
|
end
|
2019-10-06 23:31:48 +02:00
|
|
|
end
|