Moved non-config tag category info to its own class
This commit is contained in:
@@ -118,7 +118,7 @@ class PostQueryBuilder
|
||||
relation = add_range_relation(q[:filesize], "posts.file_size", relation)
|
||||
relation = add_range_relation(q[:date], "posts.created_at", relation)
|
||||
relation = add_range_relation(q[:age], "posts.created_at", relation)
|
||||
Danbooru.config.full_tag_config_info.each_key do |category|
|
||||
TagCategory.categories.each do |category|
|
||||
relation = add_range_relation(q["#{category}_tag_count".to_sym], "posts.tag_count_#{category}", relation)
|
||||
end
|
||||
relation = add_range_relation(q[:post_tag_count], "posts.tag_count", relation)
|
||||
@@ -511,11 +511,11 @@ class PostQueryBuilder
|
||||
when "tagcount_asc"
|
||||
relation = relation.order("posts.tag_count ASC")
|
||||
|
||||
when /(#{Danbooru.config.short_tag_name_mapping.keys.join("|")})tags(?:\Z|_desc)/
|
||||
relation = relation.order("posts.tag_count_#{Danbooru.config.short_tag_name_mapping[$1]} DESC")
|
||||
when /(#{TagCategory.short_name_regex})tags(?:\Z|_desc)/
|
||||
relation = relation.order("posts.tag_count_#{TagCategory.short_name_mapping[$1]} DESC")
|
||||
|
||||
when /(#{Danbooru.config.short_tag_name_mapping.keys.join("|")})tags_asc/
|
||||
relation = relation.order("posts.tag_count_#{Danbooru.config.short_tag_name_mapping[$1]} ASC")
|
||||
when /(#{TagCategory.short_name_regex})tags_asc/
|
||||
relation = relation.order("posts.tag_count_#{TagCategory.short_name_mapping[$1]} ASC")
|
||||
|
||||
when "rank"
|
||||
relation = relation.order("log(3, posts.score) + (extract(epoch from posts.created_at) - extract(epoch from timestamp '2005-05-24')) / 35000 DESC")
|
||||
|
||||
78
app/logical/tag_category.rb
Normal file
78
app/logical/tag_category.rb
Normal file
@@ -0,0 +1,78 @@
|
||||
class TagCategory
|
||||
module Mappings
|
||||
# Returns a hash mapping various tag categories to a numerical value.
|
||||
def mapping
|
||||
@@mapping ||= Hash[
|
||||
Danbooru.config.full_tag_config_info.map {|k,v| v["extra"].map {|y| [y,v["category"]]}}
|
||||
.reduce([],:+)]
|
||||
.update(Hash[Danbooru.config.full_tag_config_info.map {|k,v| [v["short"],v["category"]]}])
|
||||
.update( Hash[Danbooru.config.full_tag_config_info.map {|k,v| [k,v["category"]]}])
|
||||
end
|
||||
|
||||
# Returns a hash mapping more suited for views
|
||||
def canonical_mapping
|
||||
@@canonical_mapping ||= Hash[Danbooru.config.full_tag_config_info.map {|k,v| [k.capitalize,v["category"]]}]
|
||||
end
|
||||
|
||||
# Returns a hash mapping numerical category values to their string equivalent.
|
||||
def reverse_mapping
|
||||
@@reverse_mapping ||= Hash[Danbooru.config.full_tag_config_info.map {|k,v| [v["category"],k]}]
|
||||
end
|
||||
|
||||
# Returns a hash mapping for the short name usage in metatags
|
||||
def short_name_mapping
|
||||
@@short_name_mapping ||= Hash[Danbooru.config.full_tag_config_info.map {|k,v| [v["short"],k]}]
|
||||
end
|
||||
|
||||
# Returns a hash mapping for humanized_essential_tag_string (models/post.rb)
|
||||
def humanized_mapping
|
||||
@@humanized_mapping ||= Hash[Danbooru.config.full_tag_config_info.map {|k,v| [k,v["humanized"]]}]
|
||||
end
|
||||
|
||||
# Returns a hash mapping for humanized_essential_tag_string (models/post.rb)
|
||||
def header_mapping
|
||||
@@header_mapping ||= Hash[Danbooru.config.full_tag_config_info.map {|k,v| [k,v["header"]]}]
|
||||
end
|
||||
|
||||
# Returns a hash mapping for related tag buttons (javascripts/related_tag.js)
|
||||
def related_button_mapping
|
||||
@@related_button_mapping ||= Hash[Danbooru.config.full_tag_config_info.map {|k,v| [k,v["relatedbutton"]]}]
|
||||
end
|
||||
end
|
||||
|
||||
module Lists
|
||||
def categories
|
||||
@@categories ||= Danbooru.config.full_tag_config_info.keys
|
||||
end
|
||||
|
||||
def short_name_list
|
||||
@@short_name_list ||= short_name_mapping.keys
|
||||
end
|
||||
|
||||
def humanized_list
|
||||
Danbooru.config.humanized_tag_category_list
|
||||
end
|
||||
|
||||
def split_header_list
|
||||
Danbooru.config.split_tag_header_list
|
||||
end
|
||||
|
||||
def categorized_list
|
||||
Danbooru.config.categorized_tag_list
|
||||
end
|
||||
|
||||
def related_button_list
|
||||
Danbooru.config.related_tag_button_list
|
||||
end
|
||||
end
|
||||
|
||||
module Regexes
|
||||
def short_name_regex
|
||||
@@short_name_regex ||= short_name_list.join("|")
|
||||
end
|
||||
end
|
||||
|
||||
extend Mappings
|
||||
extend Lists
|
||||
extend Regexes
|
||||
end
|
||||
Reference in New Issue
Block a user