Fix #4960: Cosplay wikis link to char:x instead of just x.
This commit is contained in:
@@ -15,6 +15,7 @@ class Tag < ApplicationRecord
|
|||||||
validates :name, tag_name: true, on: :name
|
validates :name, tag_name: true, on: :name
|
||||||
validates :category, inclusion: { in: TagCategory.category_ids }
|
validates :category, inclusion: { in: TagCategory.category_ids }
|
||||||
|
|
||||||
|
before_create :create_character_tag_for_cosplay_tag, if: :is_cosplay_tag?
|
||||||
after_save :update_category_cache, if: :saved_change_to_category?
|
after_save :update_category_cache, if: :saved_change_to_category?
|
||||||
after_save :update_category_post_counts, if: :saved_change_to_category?
|
after_save :update_category_post_counts, if: :saved_change_to_category?
|
||||||
|
|
||||||
@@ -344,16 +345,29 @@ class Tag < ApplicationRecord
|
|||||||
|
|
||||||
def self.automatic_tags_for(names)
|
def self.automatic_tags_for(names)
|
||||||
tags = []
|
tags = []
|
||||||
tags += names.grep(/\A(.+)_\(cosplay\)\z/i) { "char:#{TagAlias.to_aliased([$1]).first}" }
|
tags += names.grep(/\A(.+)_\(cosplay\)\z/i) { TagAlias.to_aliased([$1]).first }
|
||||||
tags << "cosplay" if names.any?(/_\(cosplay\)\z/i)
|
tags << "cosplay" if names.any?(/_\(cosplay\)\z/i)
|
||||||
tags << "school_uniform" if names.any?(/_school_uniform\z/i)
|
tags << "school_uniform" if names.any?(/_school_uniform\z/i)
|
||||||
tags << "meme" if names.any?(/_\(meme\)\z/i)
|
tags << "meme" if names.any?(/_\(meme\)\z/i)
|
||||||
tags.uniq
|
tags.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.convert_cosplay_tags(tags)
|
concerning :CosplayTagMethods do
|
||||||
cosplay_tags, other_tags = tags.partition {|tag| tag.match(/\A(.+)_\(cosplay\)\Z/) }
|
class_methods do
|
||||||
cosplay_tags.grep(/\A(.+)_\(cosplay\)\Z/) { "#{TagAlias.to_aliased([$1]).first}_(cosplay)" } + other_tags
|
def convert_cosplay_tags(tags)
|
||||||
|
cosplay_tags, other_tags = tags.partition {|tag| tag.match(/\A(.+)_\(cosplay\)\Z/) }
|
||||||
|
cosplay_tags.grep(/\A(.+)_\(cosplay\)\Z/) { "#{TagAlias.to_aliased([$1]).first}_(cosplay)" } + other_tags
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_character_tag_for_cosplay_tag
|
||||||
|
character_name = name.delete_suffix("_(cosplay)")
|
||||||
|
Tag.find_or_create_by_name("char:#{character_name}")
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_cosplay_tag?
|
||||||
|
name.end_with?("_(cosplay)")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def implied_tags
|
def implied_tags
|
||||||
|
|||||||
Reference in New Issue
Block a user