diff --git a/app/helpers/artists_helper.rb b/app/helpers/artists_helper.rb index 4decd1467..0fa29ed5a 100644 --- a/app/helpers/artists_helper.rb +++ b/app/helpers/artists_helper.rb @@ -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) diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index 0ef0b70e1..45f78ac7e 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -1,36 +1,4 @@ module TagsHelper - def alias_and_implication_list(tag) - return "" if tag.nil? - - html = "" - - if tag.antecedent_alias - html << "

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")}).

" - end - - if tag.consequent_aliases.present? - html << "

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")}).

" - end - - if tag.antecedent_implications.present? - html << "

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")}).

" - end - - if tag.consequent_implications.present? - html << "

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")}).

" - end - - html.html_safe - end - def format_transitive_item(transitive) html = "#{transitive[0].to_s.titlecase} ".html_safe if transitive[0] == :alias diff --git a/app/helpers/wiki_pages_helper.rb b/app/helpers/wiki_pages_helper.rb index 0fec878d9..4bf5b91d2 100644 --- a/app/helpers/wiki_pages_helper.rb +++ b/app/helpers/wiki_pages_helper.rb @@ -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 = '
' - - if Post.fast_count(wiki_page.title) > 0 - full_link = link_to("view all", posts_path(:tags => wiki_page.title)) - html << "

Posts (#{full_link})

" - 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 << "
" - - html.html_safe end end diff --git a/app/views/artists/_show.html.erb b/app/views/artists/_show.html.erb index 3d8b8778c..857ef9b36 100644 --- a/app/views/artists/_show.html.erb +++ b/app/views/artists/_show.html.erb @@ -12,7 +12,7 @@

<%= link_to_wiki_or_new "View wiki page", @artist.name %>

<% end %> - <%= artist_alias_and_implication_list(@artist) %> + <%= render "tags/alias_and_implication_list", tag: @artist.tag %> <%= yield %>
diff --git a/app/views/tags/_alias_and_implication_list.html.erb b/app/views/tags/_alias_and_implication_list.html.erb new file mode 100644 index 000000000..fc8c418f9 --- /dev/null +++ b/app/views/tags/_alias_and_implication_list.html.erb @@ -0,0 +1,25 @@ +<%# locals: (tag:) -%> +<% if tag&.antecedent_alias %> +

+ 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") %>). +

+<% end %> +<% if tag&.consequent_aliases&.present? %> +

+ 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") %>). +

+<% end %> +<% if tag&.antecedent_implications&.present? %> +

+ 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") %>). +

+<% end %> +<% if tag&.consequent_implications&.present? %> +

+ 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") %>). +

+<% end %>