/wiki_page_versions/diff: use SetDiff to diff other_names.

Use SetDiff instead of DiffBuilder to generate diffs for wiki page other
names. SetDiff is what we use for artist other names.
This commit is contained in:
evazion
2020-01-12 15:32:34 -06:00
parent 95dd28fc52
commit 90b94adee8
6 changed files with 24 additions and 18 deletions

View File

@@ -1,9 +1,9 @@
require 'dtext'
module ApplicationHelper
def diff_list_html(new, old, latest)
def diff_list_html(new, old, latest, ul_class: ["diff-list"], li_class: [])
diff = SetDiff.new(new, old, latest)
render "diff_list", diff: diff
render "diff_list", diff: diff, ul_class: ul_class, li_class: li_class
end
def wordbreakify(string)

View File

@@ -12,9 +12,12 @@ module WikiPageVersionsHelper
status.join(" ")
end
def wiki_other_names_diff(thispage, otherpage)
pattern = Regexp.new('\S+|\s+')
DiffBuilder.new("#{thispage.other_names}\n\n", "#{otherpage.other_names}\n\n", pattern).build
def wiki_other_names_diff(new_version, old_version)
new_names = new_version.other_names
old_names = old_version.other_names
latest_names = new_version.wiki_page.other_names
diff_list_html(new_names, old_names, latest_names, ul_class: ["wiki-other-names-diff-list list-inline"], li_class: ["wiki-other-name"])
end
def wiki_body_diff(thispage, otherpage)

View File

@@ -10,7 +10,7 @@
}
.removed, .removed a {
color: var(--dif-list-removed-color);
color: var(--diff-list-removed-color);
text-decoration: line-through;
margin-right: 0.5em;
}

View File

@@ -1,15 +1,19 @@
div#c-wiki-page-versions {
#a-diff {
del {
del, .wiki-other-names-diff-list .removed {
background: var(--wiki-page-versions-diff-del-background);
text-decoration: none;
}
ins {
ins, .wiki-other-names-diff-list .added {
background: var(--wiki-page-versions-diff-ins-background);
text-decoration: none;
}
.wiki-other-names-diff-list .obsolete {
text-decoration: dotted underline;
}
span.paragraph-mark {
opacity: 0.25;
}

View File

@@ -1,21 +1,21 @@
<%# diff %>
<%# diff, ul_class, li_class %>
<ul class="diff-list">
<%= tag.ul class: [*ul_class] do %>
<% diff.added.each do |item| %>
<%= tag.li item, class: (item.in?(diff.obsolete_added) ? "obsolete added" : "added") %>
<%= tag.li item, class: ["added", ("obsolete" if item.in?(diff.obsolete_added)), *li_class] %>
<% end %>
<% diff.removed.each do |item| %>
<%= tag.li item, class: (item.in?(diff.obsolete_removed) ? "obsolete removed" : "removed") %>
<%= tag.li item, class: ["removed", ("obsolete" if item.in?(diff.obsolete_removed)), *li_class] %>
<% end %>
<% diff.changed.each do |old, new| %>
<%= tag.li class: "changed" do %>
<%= tag.span old, class: "removed" %>→ <%= tag.span new, class: "added" %>
<%= tag.span old, class: ["removed", *li_class] %>→ <%= tag.span new, class: ["added", *li_class] %>
<% end %>
<% end %>
<% diff.unchanged.each do |item| %>
<%= tag.li item, class: "unchanged" %>
<%= tag.li item, class: ["unchanged", *li_class] %>
<% end %>
</ul>
<% end %>

View File

@@ -6,9 +6,8 @@
<% if @thispage.visible? %>
<p>Showing differences between <%= compact_time @thispage.updated_at %> (<%= link_to_user @thispage.updater %>) and <%= compact_time @otherpage.updated_at %> (<%= link_to_user @otherpage.updater %>)</p>
<div>
<%= wiki_other_names_diff(@thispage, @otherpage) %>
</div>
<%= wiki_other_names_diff(@thispage, @otherpage) %>
<div>
<%= wiki_body_diff(@thispage, @otherpage) %>
</div>