From 26f7e904c230fbfc4e6fc56904a00708abdb23c0 Mon Sep 17 00:00:00 2001 From: albert Date: Tue, 30 Oct 2012 17:58:52 -0400 Subject: [PATCH] added humanized tag strings --- app/models/post.rb | 29 ++++++++++++++++++++++++++++- app/presenters/post_presenter.rb | 24 ++++++++++++++++++++++++ app/views/posts/show.html.erb | 4 ++-- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 2dfc317de..f26599954 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -455,8 +455,32 @@ class Post < ActiveRecord::Base tag_string =~ /(?:^| )#{tag}(?:$| )/ end + def tag_categories + @tag_categories ||= Tag.categories_for(tag_array) + end + + def copyright_tags + typed_tags("copyright") + end + + def character_tags + typed_tags("character") + end + + def artist_tags + typed_tags("artist") + end + + def typed_tags(name) + @typed_tags ||= {} + @typed_tags[name] ||= begin + tag_array.select do |tag| + tag_categories[tag] == Danbooru.config.tag_category_mapping[name] + end + end + end + def essential_tag_string - tag_categories = Tag.categories_for(tag_array) tag_array.each do |tag| if tag_categories[tag] == Danbooru.config.tag_category_mapping["copyright"] return tag @@ -852,6 +876,9 @@ class Post < ActiveRecord::Base def reload(options = nil) super reset_tag_array_cache + @tag_categories = nil + @typed_tags = nil + self end end diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index 04cb4dc0c..39824e15a 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -27,6 +27,30 @@ class PostPresenter < Presenter PostPresenter.preview(@post) end + def humanized_tag_string + @post.tag_string.split(/ /).join(", ").tr("_", " ") + end + + def humanized_essential_tag_string + string = [] + + if @post.character_tags.any? + string << @post.character_tags.slice(0, 5).to_sentence + end + + if @post.copyright_tags.any? + string << "from" + string << @post.copyright_tags.slice(0, 5).to_sentence + end + + if @post.artist_tags.any? + string << "by" + string << @post.artist_tags.to_sentence + end + + string.join(" ").tr("_", " ") + end + def image_html(template) return template.content_tag("p", "This image was deleted.") if @post.is_deleted? && !CurrentUser.user.is_janitor? return template.content_tag("p", "You need a privileged account to see this image.") if !Danbooru.config.can_user_see_post?(CurrentUser.user, @post) diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index 61f02d5bf..03ff62444 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -92,8 +92,8 @@ - - + + <% end %>