tag_set_presenter: refactor split_tag_list_html.
* Make category headers optional. * Make category order configurable. * Clean up code.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
class PostPresenter < Presenter
|
class PostPresenter < Presenter
|
||||||
attr_reader :pool, :next_post_in_pool
|
attr_reader :pool, :next_post_in_pool
|
||||||
|
delegate :tag_list_html, :split_tag_list_html, :inline_tag_list_html, :split_inline_tag_list_html, to: :tag_set_presenter
|
||||||
|
|
||||||
def self.preview(post, options = {})
|
def self.preview(post, options = {})
|
||||||
if post.nil?
|
if post.nil?
|
||||||
@@ -162,10 +163,6 @@ class PostPresenter < Presenter
|
|||||||
categorized_tag_groups.join(" \n")
|
categorized_tag_groups.join(" \n")
|
||||||
end
|
end
|
||||||
|
|
||||||
def humanized_categorized_tag_string
|
|
||||||
categorized_tag_groups.flatten.slice(0, 25).join(", ").tr("_", " ")
|
|
||||||
end
|
|
||||||
|
|
||||||
def safe_mode_message(template)
|
def safe_mode_message(template)
|
||||||
html = ["This image is unavailable on safe mode (#{Danbooru.config.app_name}). Go to "]
|
html = ["This image is unavailable on safe mode (#{Danbooru.config.app_name}). Go to "]
|
||||||
html << template.link_to("Danbooru", "http://danbooru.donmai.us") # XXX don't hardcode.
|
html << template.link_to("Danbooru", "http://danbooru.donmai.us") # XXX don't hardcode.
|
||||||
@@ -193,18 +190,6 @@ class PostPresenter < Presenter
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_list_html(template, options = {})
|
|
||||||
tag_set_presenter.tag_list_html(template, options.merge(:show_extra_links => CurrentUser.user.is_gold?))
|
|
||||||
end
|
|
||||||
|
|
||||||
def split_tag_list_html(template, options = {})
|
|
||||||
tag_set_presenter.split_tag_list_html(template, options.merge(:show_extra_links => CurrentUser.user.is_gold?))
|
|
||||||
end
|
|
||||||
|
|
||||||
def inline_tag_list_html(template)
|
|
||||||
tag_set_presenter.inline_tag_list(template)
|
|
||||||
end
|
|
||||||
|
|
||||||
def has_nav_links?(template)
|
def has_nav_links?(template)
|
||||||
has_sequential_navigation?(template.params) || @post.pools.undeleted.any? || @post.favorite_groups(active_id=template.params[:favgroup_id]).any?
|
has_sequential_navigation?(template.params) || @post.pools.undeleted.any? || @post.favorite_groups(active_id=template.params[:favgroup_id]).any?
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -22,16 +22,16 @@ class TagSetPresenter < Presenter
|
|||||||
html.html_safe
|
html.html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
def split_tag_list_html(template, options = {})
|
def split_tag_list_html(template, category_list: TagCategory.split_header_list, headers: true, **options)
|
||||||
html = ""
|
html = ""
|
||||||
|
|
||||||
TagCategory.split_header_list.each do |category|
|
category_list.each do |category|
|
||||||
typetags = typed_tags(category)
|
typetags = typed_tags(category)
|
||||||
if typetags.any?
|
if typetags.any?
|
||||||
html << TagCategory.header_mapping[category]
|
html << TagCategory.header_mapping[category] if headers
|
||||||
html << %{<ul class="#{category}-tag-list">}
|
html << %{<ul class="#{category}-tag-list">}
|
||||||
typetags.each do |tag|
|
typetags.each do |tag|
|
||||||
html << build_list_item(tag, template, options)
|
html << build_list_item(tag, template, **options)
|
||||||
end
|
end
|
||||||
html << "</ul>"
|
html << "</ul>"
|
||||||
end
|
end
|
||||||
@@ -41,7 +41,7 @@ class TagSetPresenter < Presenter
|
|||||||
end
|
end
|
||||||
|
|
||||||
# compact (horizontal) list, as seen in the /comments index.
|
# compact (horizontal) list, as seen in the /comments index.
|
||||||
def inline_tag_list(template)
|
def inline_tag_list_html(template)
|
||||||
@tags.map do |tag_name|
|
@tags.map do |tag_name|
|
||||||
<<-EOS
|
<<-EOS
|
||||||
<span class="category-#{categories[tag_name]}">
|
<span class="category-#{categories[tag_name]}">
|
||||||
@@ -51,7 +51,8 @@ class TagSetPresenter < Presenter
|
|||||||
end.join.html_safe
|
end.join.html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def typed_tags(name)
|
def typed_tags(name)
|
||||||
@typed_tags ||= {}
|
@typed_tags ||= {}
|
||||||
@typed_tags[name] ||= begin
|
@typed_tags[name] ||= begin
|
||||||
@@ -72,34 +73,33 @@ private
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_list_item(tag, template, options)
|
def build_list_item(tag, template, name_only: false, humanize_tags: true, show_extra_links: CurrentUser.is_gold?)
|
||||||
html = ""
|
html = ""
|
||||||
html << %{<li class="category-#{categories[tag]}">}
|
html << %{<li class="category-#{categories[tag]}">}
|
||||||
current_query = template.params[:tags] || ""
|
current_query = template.params[:tags] || ""
|
||||||
|
|
||||||
unless options[:name_only]
|
unless name_only
|
||||||
if categories[tag] == Tag.categories.artist
|
if categories[tag] == Tag.categories.artist
|
||||||
html << %{<a class="wiki-link" href="/artists/show_or_new?name=#{u(tag)}">?</a> }
|
html << %{<a class="wiki-link" href="/artists/show_or_new?name=#{u(tag)}">?</a> }
|
||||||
else
|
else
|
||||||
html << %{<a class="wiki-link" href="/wiki_pages/show_or_new?title=#{u(tag)}">?</a> }
|
html << %{<a class="wiki-link" href="/wiki_pages/show_or_new?title=#{u(tag)}">?</a> }
|
||||||
end
|
end
|
||||||
|
|
||||||
if CurrentUser.user.is_gold? && current_query.present?
|
if show_extra_links && current_query.present?
|
||||||
html << %{<a rel="nofollow" href="/posts?tags=#{u(current_query)}+#{u(tag)}" class="search-inc-tag">+</a> }
|
html << %{<a rel="nofollow" href="/posts?tags=#{u(current_query)}+#{u(tag)}" class="search-inc-tag">+</a> }
|
||||||
html << %{<a rel="nofollow" href="/posts?tags=#{u(current_query)}+-#{u(tag)}" class="search-exl-tag">–</a> }
|
html << %{<a rel="nofollow" href="/posts?tags=#{u(current_query)}+-#{u(tag)}" class="search-exl-tag">–</a> }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
humanized_tag = tag.tr("_", " ")
|
humanized_tag = humanize_tags ? tag.tr("_", " ") : tag
|
||||||
path = options[:path_prefix] || "/posts"
|
|
||||||
if categories[tag] == Tag.categories.artist
|
if categories[tag] == Tag.categories.artist
|
||||||
itemprop = 'itemprop="author"'
|
itemprop = 'itemprop="author"'
|
||||||
else
|
else
|
||||||
itemprop = nil
|
itemprop = nil
|
||||||
end
|
end
|
||||||
html << %{<a class="search-tag" #{itemprop} href="#{path}?tags=#{u(tag)}">#{h(humanized_tag)}</a> }
|
html << %{<a class="search-tag" #{itemprop} href="/posts?tags=#{u(tag)}">#{h(humanized_tag)}</a> }
|
||||||
|
|
||||||
unless options[:name_only]
|
unless name_only
|
||||||
if counts[tag].to_i >= 10_000
|
if counts[tag].to_i >= 10_000
|
||||||
post_count = "#{counts[tag].to_i / 1_000}k"
|
post_count = "#{counts[tag].to_i / 1_000}k"
|
||||||
elsif counts[tag].to_i >= 1_000
|
elsif counts[tag].to_i >= 1_000
|
||||||
|
|||||||
@@ -49,7 +49,7 @@
|
|||||||
|
|
||||||
<span class="info">
|
<span class="info">
|
||||||
<strong>Tags</strong>
|
<strong>Tags</strong>
|
||||||
<%= TagSetPresenter.new(upload.tag_string.split).inline_tag_list(self) %>
|
<%= TagSetPresenter.new(upload.tag_string.split).inline_tag_list_html(self) %>
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
Reference in New Issue
Block a user