[Wiki] Fix show for frozen string literals

Move the alias/implication list to a partial
This commit is contained in:
Earlopain 2024-02-25 15:48:52 +01:00
parent 9b59c860ff
commit 4975c1f717
No known key found for this signature in database
GPG Key ID: 48860312319ADF61
5 changed files with 37 additions and 48 deletions

View File

@ -1,8 +1,4 @@
module ArtistsHelper
def artist_alias_and_implication_list(artist)
alias_and_implication_list(artist.tag)
end
def link_to_artist(name)
artist = Artist.find_by(name: name)

View File

@ -1,36 +1,4 @@
module TagsHelper
def alias_and_implication_list(tag)
return "" if tag.nil?
html = ""
if tag.antecedent_alias
html << "<p class='hint'>This tag has been aliased to "
html << link_to_wiki_or_new(tag.antecedent_alias.consequent_name)
html << " (#{link_to "learn more", wiki_pages_path(title: "e621:tag_aliases")}).</p>"
end
if tag.consequent_aliases.present?
html << "<p class='hint'>The following tags are aliased to this tag: "
html << raw(tag.consequent_aliases.map {|x| link_to_wiki_or_new(x.antecedent_name) }.join(", "))
html << " (#{link_to "learn more", wiki_pages_path(title: "e621:tag_aliases")}).</p>"
end
if tag.antecedent_implications.present?
html << "<p class='hint'>This tag implicates "
html << raw(tag.antecedent_implications.map {|x| link_to_wiki_or_new(x.consequent_name) }.join(", "))
html << " (#{link_to "learn more", wiki_pages_path(title: "e621:tag_implications")}).</p>"
end
if tag.consequent_implications.present?
html << "<p class='hint'>The following tags implicate this tag: "
html << raw(tag.consequent_implications.map {|x| link_to_wiki_or_new(x.antecedent_name) }.join(", "))
html << " (#{link_to "learn more", wiki_pages_path(title: "e621:tag_implications")}).</p>"
end
html.html_safe
end
def format_transitive_item(transitive)
html = "<strong class=\"redtext\">#{transitive[0].to_s.titlecase}</strong> ".html_safe
if transitive[0] == :alias

View File

@ -3,21 +3,21 @@ module WikiPagesHelper
link_to(text, show_or_new_wiki_pages_path(title: tag))
end
def multiple_link_to_wiki_or_new(tags)
safe_join(tags.map { |tag| link_to_wiki_or_new(tag) }, ", ")
end
def wiki_page_alias_and_implication_list(wiki_page)
alias_and_implication_list(wiki_page.tag || Tag.new({name: wiki_page.title}))
render "tags/alias_and_implication_list", tag: wiki_page.tag || Tag.new(name: wiki_page.title)
end
def wiki_page_post_previews(wiki_page)
html = '<div id="wiki-page-posts">'
if Post.fast_count(wiki_page.title) > 0
full_link = link_to("view all", posts_path(:tags => wiki_page.title))
html << "<h2>Posts (#{full_link})</h2>"
html << wiki_page.post_set.presenter.post_previews_html(self)
tag.div(id: "wiki-page-posts") do
if Post.fast_count(wiki_page.title) > 0
view_all_link = link_to("view all", posts_path(tags: wiki_page.title))
header = tag.h2("Posts (#{view_all_link})".html_safe)
header + wiki_page.post_set.presenter.post_previews_html(self)
end
end
html << "</div>"
html.html_safe
end
end

View File

@ -12,7 +12,7 @@
<p><%= link_to_wiki_or_new "View wiki page", @artist.name %></p>
<% end %>
<%= artist_alias_and_implication_list(@artist) %>
<%= render "tags/alias_and_implication_list", tag: @artist.tag %>
<%= yield %>
<div class="recent-posts">

View File

@ -0,0 +1,25 @@
<%# locals: (tag:) -%>
<% if tag&.antecedent_alias %>
<p class="hint">
This tag has been aliased to <%= link_to_wiki_or_new(tag.antecedent_alias.consequent_name) %>
(<%= link_to "learn more", wiki_pages_path(title: "e621:tag_aliases") %>).
</p>
<% end %>
<% if tag&.consequent_aliases&.present? %>
<p class="hint">
The following tags are aliased to this tag: <%= multiple_link_to_wiki_or_new(tag.consequent_aliases.map(&:antecedent_name)) %>
(<%= link_to "learn more", wiki_pages_path(title: "e621:tag_aliases") %>).
</p>
<% end %>
<% if tag&.antecedent_implications&.present? %>
<p class="hint">
This tag implicates <%= multiple_link_to_wiki_or_new(tag.antecedent_implications.map(&:consequent_name)) %>
(<%= link_to "learn more", wiki_pages_path(title: "e621:tag_implications") %>).
</p>
<% end %>
<% if tag&.consequent_implications&.present? %>
<p class="hint">
The following tags implicate this tag: <%= multiple_link_to_wiki_or_new(tag.consequent_implications.map(&:antecedent_name)) %>
(<%= link_to "learn more", wiki_pages_path(title: "e621:tag_implications") %>).
</p>
<% end %>