mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 22:27:59 +01:00
fix various things
This commit is contained in:
parent
9fc04b9b71
commit
0c976851ed
4 changed files with 19 additions and 11 deletions
|
@ -24,8 +24,7 @@ defmodule Philomena.Versions do
|
||||||
|
|
||||||
{versions, _last_body} =
|
{versions, _last_body} =
|
||||||
versions
|
versions
|
||||||
|> Enum.reverse()
|
|> Enum.map_reduce(parent.body, fn version, previous_body ->
|
||||||
|> Enum.map_reduce(nil, fn version, previous_body ->
|
|
||||||
yaml = YamlElixir.read_from_string!(version.object || "")
|
yaml = YamlElixir.read_from_string!(version.object || "")
|
||||||
body = yaml["body"] || ""
|
body = yaml["body"] || ""
|
||||||
edit_reason = yaml["edit_reason"]
|
edit_reason = yaml["edit_reason"]
|
||||||
|
@ -37,16 +36,16 @@ defmodule Philomena.Versions do
|
||||||
user: users[version.whodunnit],
|
user: users[version.whodunnit],
|
||||||
body: body,
|
body: body,
|
||||||
edit_reason: edit_reason,
|
edit_reason: edit_reason,
|
||||||
difference: difference(previous_body, body)
|
difference: difference(body, previous_body)
|
||||||
}
|
}
|
||||||
|
|
||||||
{v, body}
|
{v, body}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Enum.reverse(versions)
|
versions
|
||||||
end
|
end
|
||||||
|
|
||||||
defp difference(nil, next), do: [eq: next]
|
defp difference(previous, nil), do: [eq: previous]
|
||||||
defp difference(previous, next), do: String.myers_difference(previous, next)
|
defp difference(previous, next), do: String.myers_difference(previous, next)
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
|
|
@ -10,7 +10,7 @@ defmodule PhilomenaWeb.Image.Comment.HistoryController do
|
||||||
|
|
||||||
plug PhilomenaWeb.CanaryMapPlug, index: :show
|
plug PhilomenaWeb.CanaryMapPlug, index: :show
|
||||||
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
|
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
|
||||||
plug :load_and_authorize_resource, model: Comment, id_name: "comment_id", persisted: true, preload: [:user, :image]
|
plug :load_and_authorize_resource, model: Comment, id_name: "comment_id", persisted: true, preload: [:image, user: [awards: :badge]]
|
||||||
|
|
||||||
def index(conn, _params) do
|
def index(conn, _params) do
|
||||||
comment = conn.assigns.comment
|
comment = conn.assigns.comment
|
||||||
|
|
|
@ -22,13 +22,13 @@ h1
|
||||||
= for edit <- version.difference do
|
= for edit <- version.difference do
|
||||||
= case edit do
|
= case edit do
|
||||||
- {:eq, value} ->
|
- {:eq, value} ->
|
||||||
= text_to_html(value)
|
= escape_nl2br(value)
|
||||||
|
|
||||||
- {:ins, value} ->
|
- {:ins, value} ->
|
||||||
ins.differ = text_to_html(value)
|
ins.differ = escape_nl2br(value)
|
||||||
|
|
||||||
- {:del, value} ->
|
- {:del, value} ->
|
||||||
del.differ = text_to_html(value)
|
del.differ = escape_nl2br(value)
|
||||||
|
|
||||||
.block__content.communication__options
|
.block__content.communication__options
|
||||||
.flex.flex--wrap.flex--spaced-out
|
.flex.flex--wrap.flex--spaced-out
|
||||||
|
@ -41,6 +41,6 @@ h1
|
||||||
|
|
||||||
.flex__right
|
.flex__right
|
||||||
' Edited
|
' Edited
|
||||||
= pretty_time(version.created_at)
|
=> pretty_time(version.created_at)
|
||||||
' by
|
' by
|
||||||
= render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @version, conn: @conn
|
=> render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: version, conn: @conn
|
|
@ -93,6 +93,15 @@ defmodule PhilomenaWeb.AppView do
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def escape_nl2br(text) do
|
||||||
|
text
|
||||||
|
|> String.split("\n")
|
||||||
|
|> Enum.map(&html_escape/1)
|
||||||
|
|> Enum.map(&safe_to_string/1)
|
||||||
|
|> Enum.join("<br/>")
|
||||||
|
|> raw()
|
||||||
|
end
|
||||||
|
|
||||||
defp datetime_string(time) do
|
defp datetime_string(time) do
|
||||||
:io_lib.format("~2..0B:~2..0B:~2..0B, ~s ~B, ~B", [
|
:io_lib.format("~2..0B:~2..0B:~2..0B, ~s ~B, ~B", [
|
||||||
time.hour,
|
time.hour,
|
||||||
|
|
Loading…
Reference in a new issue