[PostVersions] Fix index for frozen string literals

This commit is contained in:
Earlopain 2024-02-25 13:19:35 +01:00
parent 930b4b905c
commit 2352bf54f6
No known key found for this signature in database
GPG Key ID: 48860312319ADF61
2 changed files with 27 additions and 44 deletions

View File

@ -12,12 +12,6 @@ module ApplicationHelper
render "diff_list", diff: diff
end
def wordbreakify(string)
lines = string.scan(/.{1,10}/)
wordbreaked_string = lines.map{|str| h(str)}.join("<wbr>")
raw(wordbreaked_string)
end
def nav_link_to(text, url, **options)
klass = options.delete(:class)

View File

@ -1,70 +1,59 @@
module PostVersionsHelper
def post_source_diff(post_version)
diff = post_version.diff_sources(post_version.previous)
html = '<span class="diff-list">'
changes = []
diff[:added_sources].each do |source|
prefix = '<div><ins>+'
html << prefix + wordbreakify(source) + '</ins></div>'
html << " "
changes << tag.div(tag.ins(wordbreak_source("+#{source}")))
end
diff[:removed_sources].each do |source|
prefix = '<div><del>-'
html << prefix + wordbreakify(source) + '</del></div>'
html << " "
changes << tag.div(tag.del(wordbreak_source("-#{source}")))
end
diff[:unchanged_sources].each do |source|
html << '<div>' + wordbreakify(source) + '</div>'
html << " "
changes << tag.div(wordbreak_source(source))
end
html << "</span>"
html.html_safe
tag.span(safe_join(changes, " "), class: "diff-list")
end
def wordbreak_source(string)
lines = string.scan(/.{1,10}/)
safe_join(lines, tag.wbr)
end
def post_version_diff(post_version)
diff = post_version.diff(post_version.previous)
html = '<span class="diff-list">'
changes = []
diff[:added_tags].each do |tag|
prefix = diff[:obsolete_added_tags].include?(tag) ? '<ins class="obsolete">+' : '<ins>+'
html << prefix + link_to(tag, posts_path(:tags => tag)) + '</ins>'
html << " "
diff[:added_tags].each do |tag_name|
classes = diff[:obsolete_added_tags].include?(tag_name) ? "obsolete" : ""
changes << tag.ins(link_to("+#{tag_name}", posts_path(tags: tag_name), class: classes))
end
diff[:removed_tags].each do |tag|
prefix = diff[:obsolete_removed_tags].include?(tag) ? '<del class="obsolete">-' : '<del>-'
html << prefix + link_to(tag, posts_path(:tags => tag)) + '</del>'
html << " "
diff[:removed_tags].each do |tag_name|
classes = diff[:obsolete_removed_tags].include?(tag_name) ? "obsolete" : ""
changes << tag.del(link_to("-#{tag_name}", posts_path(tags: tag_name), class: classes))
end
diff[:unchanged_tags].each do |tag|
html << '<span>' + link_to(tag, posts_path(:tags => tag)) + '</span>'
html << " "
diff[:unchanged_tags].each do |tag_name|
changes << tag.span(link_to(tag_name, posts_path(tags: tag_name)))
end
html << "</span>"
html.html_safe
tag.span(safe_join(changes, " "), class: "diff-list")
end
def post_version_locked_diff(post_version)
diff = post_version.diff(post_version.previous)
html = '<span class="diff-list">'
changes = []
diff[:added_locked_tags].each do |tag|
prefix = '<ins>+'
html << prefix + link_to(tag, posts_path(:tags => tag)) + '</ins>'
html << " "
diff[:added_locked_tags].each do |tag_name|
changes << tag.ins(link_to("+#{tag_name}", posts_path(tags: tag_name)))
end
diff[:removed_locked_tags].each do |tag|
prefix = '<del>-'
html << prefix + link_to(tag, posts_path(:tags => tag)) + '</del>'
html << " "
diff[:removed_locked_tags].each do |tag_name|
changes << tag.del(link_to("-#{tag_name}", posts_path(tags: tag_name)))
end
diff[:unchanged_locked_tags].each do |tag|
html << '<span>' + link_to(tag, posts_path(:tags => tag)) + '</span>'
html << " "
changes << tag.span(link_to(tag_name, posts_path(tags: tag_name)))
end
html << "</span>"
html.html_safe
tag.span(safe_join(changes, " "), class: "diff-list")
end
end