Reduce tag config variables co-dependency
This commit is contained in:
@@ -27,7 +27,7 @@ class Tag < ApplicationRecord
|
|||||||
|
|
||||||
class CategoryMapping
|
class CategoryMapping
|
||||||
Danbooru.config.reverse_tag_category_mapping.each do |value, category|
|
Danbooru.config.reverse_tag_category_mapping.each do |value, category|
|
||||||
define_method(category.downcase) do
|
define_method(category) do
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -124,7 +124,7 @@ class Tag < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def category_name
|
def category_name
|
||||||
Danbooru.config.reverse_tag_category_mapping[category]
|
Danbooru.config.reverse_tag_category_mapping[category].capitalize
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_category_cache_for_all
|
def update_category_cache_for_all
|
||||||
|
|||||||
@@ -214,44 +214,49 @@ module Danbooru
|
|||||||
"albert"
|
"albert"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#Full tag configuration info for all tags
|
||||||
|
def full_tag_config_info
|
||||||
|
@full_tag_category_mapping ||= {
|
||||||
|
"general" => {
|
||||||
|
"category" => 0,
|
||||||
|
"short" => "gen",
|
||||||
|
"extra" => []
|
||||||
|
},
|
||||||
|
"character" => {
|
||||||
|
"category" => 4,
|
||||||
|
"short" => "char",
|
||||||
|
"extra" => ["ch"]
|
||||||
|
},
|
||||||
|
"copyright" => {
|
||||||
|
"category" => 3,
|
||||||
|
"short" => "copy",
|
||||||
|
"extra" => ["co"]
|
||||||
|
},
|
||||||
|
"artist" => {
|
||||||
|
"category" => 1,
|
||||||
|
"short" => "art",
|
||||||
|
"extra" => []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
# Returns a hash mapping various tag categories to a numerical value.
|
# Returns a hash mapping various tag categories to a numerical value.
|
||||||
# Be sure to update the reverse_tag_category_mapping also.
|
|
||||||
def tag_category_mapping
|
def tag_category_mapping
|
||||||
@tag_category_mapping ||= {
|
@tag_category_mapping ||= Hash[
|
||||||
"general" => 0,
|
full_tag_config_info.map {|k,v| v["extra"].map {|y| [y,v["category"]]}}
|
||||||
"gen" => 0,
|
.reduce([],:+)]
|
||||||
|
.update(Hash[full_tag_config_info.map {|k,v| [v["short"],v["category"]]}])
|
||||||
"artist" => 1,
|
.update( Hash[full_tag_config_info.map {|k,v| [k,v["category"]]}])
|
||||||
"art" => 1,
|
|
||||||
|
|
||||||
"copyright" => 3,
|
|
||||||
"copy" => 3,
|
|
||||||
"co" => 3,
|
|
||||||
|
|
||||||
"character" => 4,
|
|
||||||
"char" => 4,
|
|
||||||
"ch" => 4
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns a hash mapping more suited for views
|
||||||
def canonical_tag_category_mapping
|
def canonical_tag_category_mapping
|
||||||
@canonical_tag_category_mapping ||= {
|
@canonical_tag_category_mapping ||= Hash[full_tag_config_info.map {|k,v| [k.capitalize,v["category"]]}]
|
||||||
"General" => 0,
|
|
||||||
"Artist" => 1,
|
|
||||||
"Copyright" => 3,
|
|
||||||
"Character" => 4
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a hash maping numerical category values to their
|
# Returns a hash mapping numerical category values to their string equivalent.
|
||||||
# string equivalent. Be sure to update the tag_category_mapping also.
|
|
||||||
def reverse_tag_category_mapping
|
def reverse_tag_category_mapping
|
||||||
@reverse_tag_category_mapping ||= {
|
@reverse_tag_category_mapping ||= Hash[full_tag_config_info.map {|k,v| [v["category"],k]}]
|
||||||
0 => "General",
|
|
||||||
1 => "Artist",
|
|
||||||
3 => "Copyright",
|
|
||||||
4 => "Character"
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# If enabled, users must verify their email addresses.
|
# If enabled, users must verify their email addresses.
|
||||||
|
|||||||
Reference in New Issue
Block a user