tags: add general?, character?, copyright?, artist?, meta?, empty? helper methods.

This commit is contained in:
evazion
2020-05-10 23:28:07 -05:00
parent 49383d393a
commit e3187e0bd0
11 changed files with 37 additions and 34 deletions

View File

@@ -37,7 +37,7 @@ class DText
tag = tags.find { |tag| tag.name == name }
artist = artists.find { |artist| artist.name == name }
if tag.present? && tag.category == Tag.categories.artist
if tag.present? && tag.artist?
node["href"] = "/artists/show_or_new?name=#{CGI.escape(name)}"
if artist.blank?
@@ -45,7 +45,7 @@ class DText
node["title"] = "This artist page does not exist"
end
node["class"] += " tag-type-#{Tag.categories.artist}"
node["class"] += " tag-type-#{tag.category}"
else
if wiki.blank?
node["class"] += " dtext-wiki-does-not-exist"
@@ -57,7 +57,7 @@ class DText
elsif tag.blank?
node["class"] += " dtext-tag-does-not-exist"
node["title"] = "This wiki page does not have a tag"
elsif tag.post_count <= 0
elsif tag.empty?
node["class"] += " dtext-tag-empty"
node["title"] = "This wiki page does not have a tag"
else

View File

@@ -34,7 +34,7 @@ module PostSets
end
def artist
return nil unless tag.present? && tag.category == Tag.categories.artist
return nil unless tag.present? && tag.artist?
return nil unless tag.artist.present? && !tag.artist.is_deleted?
tag.artist
end

View File

@@ -213,7 +213,7 @@ module Sources
def translated_tags
translated_tags = normalized_tags.flat_map(&method(:translate_tag)).uniq.sort
translated_tags.reject { |tag| tag.category == Tag.categories.artist }
translated_tags.reject(&:artist?)
end
# Given a tag from the source site, should return an array of corresponding Danbooru tags.

View File

@@ -31,7 +31,7 @@ class TagNameValidator < ActiveModel::EachValidator
tag_name = TagAlias.to_aliased([$1]).first
tag = Tag.find_by_name(tag_name)
if tag.present? && tag.category != Tag.categories.character
if tag.present? && !tag.character?
record.errors[attribute] << "#{tag_name} must be a character tag"
end
end