summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-10 04:41:54 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-10 04:41:54 +0200
commit30ed9fd9a8bffb44e6ab91dfedb8c0e33837769a (patch)
tree38ed0ff848d7995951b0e9f0f3b00f2e4f52cea1 /app
parent644744183602c68508abb02dbb9f1f321a63f88f (diff)
Include assets, tags and template in diff between revisions
Diffstat (limited to 'app')
-rw-r--r--app/models/page.rb33
-rw-r--r--app/views/revisions/diff.html.erb27
2 files changed, 47 insertions, 13 deletions
diff --git a/app/models/page.rb b/app/models/page.rb
index ea04cd6..740d42e 100644
--- a/app/models/page.rb
+++ b/app/models/page.rb
@@ -176,19 +176,26 @@ class Page < ApplicationRecord
176 end 176 end
177 177
178 def diff_against other, view: :inline 178 def diff_against other, view: :inline
179 if view == :side_by_side 179 text_diffs =
180 { 180 if view == :side_by_side
181 title: HtmlWordDiff.side_by_side(other.title.to_s, title.to_s), 181 {
182 abstract: HtmlWordDiff.side_by_side(other.abstract.to_s, abstract.to_s), 182 title: HtmlWordDiff.side_by_side(other.title.to_s, title.to_s),
183 body: HtmlWordDiff.side_by_side(other.body.to_s, body.to_s) 183 abstract: HtmlWordDiff.side_by_side(other.abstract.to_s, abstract.to_s),
184 } 184 body: HtmlWordDiff.side_by_side(other.body.to_s, body.to_s)
185 else 185 }
186 { 186 else
187 title: HtmlWordDiff.inline(other.title.to_s, title.to_s), 187 {
188 abstract: HtmlWordDiff.inline(other.abstract.to_s, abstract.to_s), 188 title: HtmlWordDiff.inline(other.title.to_s, title.to_s),
189 body: HtmlWordDiff.inline(other.body.to_s, body.to_s) 189 abstract: HtmlWordDiff.inline(other.abstract.to_s, abstract.to_s),
190 } 190 body: HtmlWordDiff.inline(other.body.to_s, body.to_s)
191 end 191 }
192 end
193
194 text_diffs.merge(
195 tags: { added: tag_list.to_a - other.tag_list.to_a, removed: other.tag_list.to_a - tag_list.to_a },
196 template_name: { from: other.template_name, to: template_name, changed: template_name != other.template_name },
197 assets: { added: assets.to_a - other.assets.to_a, removed: other.assets.to_a - assets.to_a }
198 )
192 end 199 end
193 200
194 def public? 201 def public?
diff --git a/app/views/revisions/diff.html.erb b/app/views/revisions/diff.html.erb
index d70503c..b9ce6bd 100644
--- a/app/views/revisions/diff.html.erb
+++ b/app/views/revisions/diff.html.erb
@@ -85,4 +85,31 @@
85 <h3>Body</h3> 85 <h3>Body</h3>
86 <%= raw @diff[:body] %> 86 <%= raw @diff[:body] %>
87 <% end %> 87 <% end %>
88
89 <h3>Tags</h3>
90 <% if @diff[:tags][:added].empty? && @diff[:tags][:removed].empty? %>
91 <p class="diff_unchanged">No change.</p>
92 <% else %>
93 <ul class="diff_set_list">
94 <% @diff[:tags][:added].each do |tag| %><li><ins><%= tag %></ins></li><% end %>
95 <% @diff[:tags][:removed].each do |tag| %><li><del><%= tag %></del></li><% end %>
96 </ul>
97 <% end %>
98
99 <h3>Template</h3>
100 <% if @diff[:template_name][:changed] %>
101 <p><del><%= @diff[:template_name][:from] || '(none)' %></del> <ins><%= @diff[:template_name][:to] || '(none)' %></ins></p>
102 <% else %>
103 <p class="diff_unchanged">No change.</p>
104 <% end %>
105
106 <h3>Assets</h3>
107 <% if @diff[:assets][:added].empty? && @diff[:assets][:removed].empty? %>
108 <p class="diff_unchanged">No change.</p>
109 <% else %>
110 <ul class="diff_set_list">
111 <% @diff[:assets][:added].each do |asset| %><li><ins><%= asset.upload_file_name %></ins></li><% end %>
112 <% @diff[:assets][:removed].each do |asset| %><li><del><%= asset.upload_file_name %></del></li><% end %>
113 </ul>
114 <% end %>
88</div> 115</div>