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[:filesize], "posts.file_size", relation)
|
||||||
relation = add_range_relation(q[:date], "posts.created_at", relation)
|
relation = add_range_relation(q[:date], "posts.created_at", relation)
|
||||||
relation = add_range_relation(q[:age], "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)
|
relation = add_range_relation(q["#{category}_tag_count".to_sym], "posts.tag_count_#{category}", relation)
|
||||||
end
|
end
|
||||||
relation = add_range_relation(q[:post_tag_count], "posts.tag_count", relation)
|
relation = add_range_relation(q[:post_tag_count], "posts.tag_count", relation)
|
||||||
@@ -511,11 +511,11 @@ class PostQueryBuilder
|
|||||||
when "tagcount_asc"
|
when "tagcount_asc"
|
||||||
relation = relation.order("posts.tag_count ASC")
|
relation = relation.order("posts.tag_count ASC")
|
||||||
|
|
||||||
when /(#{Danbooru.config.short_tag_name_mapping.keys.join("|")})tags(?:\Z|_desc)/
|
when /(#{TagCategory.short_name_regex})tags(?:\Z|_desc)/
|
||||||
relation = relation.order("posts.tag_count_#{Danbooru.config.short_tag_name_mapping[$1]} DESC")
|
relation = relation.order("posts.tag_count_#{TagCategory.short_name_mapping[$1]} DESC")
|
||||||
|
|
||||||
when /(#{Danbooru.config.short_tag_name_mapping.keys.join("|")})tags_asc/
|
when /(#{TagCategory.short_name_regex})tags_asc/
|
||||||
relation = relation.order("posts.tag_count_#{Danbooru.config.short_tag_name_mapping[$1]} ASC")
|
relation = relation.order("posts.tag_count_#{TagCategory.short_name_mapping[$1]} ASC")
|
||||||
|
|
||||||
when "rank"
|
when "rank"
|
||||||
relation = relation.order("log(3, posts.score) + (extract(epoch from posts.created_at) - extract(epoch from timestamp '2005-05-24')) / 35000 DESC")
|
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
|
||||||
@@ -626,11 +626,11 @@ class Post < ApplicationRecord
|
|||||||
|
|
||||||
def set_tag_counts
|
def set_tag_counts
|
||||||
self.tag_count = 0
|
self.tag_count = 0
|
||||||
Danbooru.config.full_tag_config_info.each_key {|x| set_tag_count(x,0)}
|
TagCategory.categories {|x| set_tag_count(x,0)}
|
||||||
categories = Tag.categories_for(tag_array, :disable_caching => true)
|
categories = Tag.categories_for(tag_array, :disable_caching => true)
|
||||||
categories.each_value do |category|
|
categories.each_value do |category|
|
||||||
self.tag_count += 1
|
self.tag_count += 1
|
||||||
inc_tag_count(Danbooru.config.reverse_tag_category_mapping[category])
|
inc_tag_count(TagCategory.reverse_mapping[category])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -913,7 +913,7 @@ class Post < ApplicationRecord
|
|||||||
@typed_tags ||= {}
|
@typed_tags ||= {}
|
||||||
@typed_tags[name] ||= begin
|
@typed_tags[name] ||= begin
|
||||||
tag_array.select do |tag|
|
tag_array.select do |tag|
|
||||||
tag_categories[tag] == Danbooru.config.tag_category_mapping[name]
|
tag_categories[tag] == TagCategory.mapping[name]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -926,20 +926,19 @@ class Post < ApplicationRecord
|
|||||||
@humanized_essential_tag_string ||= Cache.get("hets-#{id}", 1.hour.to_i) do
|
@humanized_essential_tag_string ||= Cache.get("hets-#{id}", 1.hour.to_i) do
|
||||||
string = []
|
string = []
|
||||||
|
|
||||||
Danbooru.config.humanized_tag_category_list.each do |category|
|
TagCategory.humanized_list.each do |category|
|
||||||
humanizeddata = Danbooru.config.full_tag_config_info[category]["humanized"]
|
typetags = typed_tags(category) - TagCategory.humanized_mapping[category]["exclusion"]
|
||||||
typetags = typed_tags(category) - humanizeddata["exclusion"]
|
if TagCategory.humanized_mapping[category]["slice"] > 0
|
||||||
if humanizeddata["slice"] > 0
|
typetags = typetags.slice(0,TagCategory.humanized_mapping[category]["slice"]) + (typetags.length > TagCategory.humanized_mapping[category]["slice"] ? ["others"] : [])
|
||||||
typetags = typetags.slice(0,humanizeddata["slice"]) + (typetags.length > humanizeddata["slice"] ? ["others"] : [])
|
|
||||||
end
|
end
|
||||||
if humanizeddata["regexmap"] != //
|
if TagCategory.humanized_mapping[category]["regexmap"] != //
|
||||||
typetags = typetags.map do |tag|
|
typetags = typetags.map do |tag|
|
||||||
tag.match(humanizeddata["regexmap"])[1]
|
tag.match(TagCategory.humanized_mapping[category]["regexmap"])[1]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if typetags.any?
|
if typetags.any?
|
||||||
if category != "copyright" || typed_tags("character").any?
|
if category != "copyright" || typed_tags("character").any?
|
||||||
string << humanizeddata["formatstr"] % typetags.to_sentence
|
string << TagCategory.humanized_mapping[category]["formatstr"] % typetags.to_sentence
|
||||||
else
|
else
|
||||||
string << typetags.to_sentence
|
string << typetags.to_sentence
|
||||||
end
|
end
|
||||||
@@ -949,7 +948,7 @@ class Post < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Danbooru.config.full_tag_config_info.each_key do |category|
|
TagCategory.categories.each do |category|
|
||||||
define_method("tag_string_#{category}") do
|
define_method("tag_string_#{category}") do
|
||||||
typed_tags(category).join(" ")
|
typed_tags(category).join(" ")
|
||||||
end
|
end
|
||||||
@@ -1140,7 +1139,7 @@ class Post < ApplicationRecord
|
|||||||
module CountMethods
|
module CountMethods
|
||||||
def fix_post_counts(post)
|
def fix_post_counts(post)
|
||||||
post.set_tag_counts
|
post.set_tag_counts
|
||||||
args = Hash[Danbooru.config.full_tag_config_info.keys.map {|x| ["tag_count_#{x}",post.send("tag_count_#{x}")]}].update(:tag_count => post.tag_count)
|
args = Hash[TagCategory.categories.map {|x| ["tag_count_#{x}",post.send("tag_count_#{x}")]}].update(:tag_count => post.tag_count)
|
||||||
post.update_columns(args)
|
post.update_columns(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1523,7 +1522,7 @@ class Post < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def method_attributes
|
def method_attributes
|
||||||
list = super + [:uploader_name, :has_large, :has_visible_children, :children_ids] + Danbooru.config.full_tag_config_info.keys.map {|x| "tag_string_#{x}".to_sym}
|
list = super + [:uploader_name, :has_large, :has_visible_children, :children_ids] + TagCategory.categories.map {|x| "tag_string_#{x}".to_sym}
|
||||||
if visible?
|
if visible?
|
||||||
list += [:file_url, :large_file_url, :preview_file_url]
|
list += [:file_url, :large_file_url, :preview_file_url]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
class Tag < ApplicationRecord
|
class Tag < ApplicationRecord
|
||||||
COSINE_SIMILARITY_RELATED_TAG_THRESHOLD = 1000
|
COSINE_SIMILARITY_RELATED_TAG_THRESHOLD = 1000
|
||||||
METATAGS = "-user|user|-approver|approver|commenter|comm|noter|noteupdater|artcomm|-pool|pool|ordpool|-favgroup|favgroup|-fav|fav|ordfav|md5|-rating|rating|-locked|locked|width|height|mpixels|ratio|score|favcount|filesize|source|-source|id|-id|date|age|order|limit|-status|status|tagcount|parent|-parent|child|pixiv_id|pixiv|search|upvote|downvote|filetype|-filetype|flagger|-flagger|appealer|-appealer|" +
|
METATAGS = "-user|user|-approver|approver|commenter|comm|noter|noteupdater|artcomm|-pool|pool|ordpool|-favgroup|favgroup|-fav|fav|ordfav|md5|-rating|rating|-locked|locked|width|height|mpixels|ratio|score|favcount|filesize|source|-source|id|-id|date|age|order|limit|-status|status|tagcount|parent|-parent|child|pixiv_id|pixiv|search|upvote|downvote|filetype|-filetype|flagger|-flagger|appealer|-appealer|" +
|
||||||
Danbooru.config.short_tag_name_mapping.keys.map {|x| "#{x}tags"}.join("|")
|
TagCategory.short_name_list.map {|x| "#{x}tags"}.join("|")
|
||||||
SUBQUERY_METATAGS = "commenter|comm|noter|noteupdater|artcomm|flagger|-flagger|appealer|-appealer"
|
SUBQUERY_METATAGS = "commenter|comm|noter|noteupdater|artcomm|flagger|-flagger|appealer|-appealer"
|
||||||
attr_accessible :category, :as => [:moderator, :gold, :platinum, :member, :anonymous, :default, :builder, :admin]
|
attr_accessible :category, :as => [:moderator, :gold, :platinum, :member, :anonymous, :default, :builder, :admin]
|
||||||
attr_accessible :is_locked, :as => [:moderator, :admin]
|
attr_accessible :is_locked, :as => [:moderator, :admin]
|
||||||
@@ -27,18 +27,18 @@ class Tag < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
class CategoryMapping
|
class CategoryMapping
|
||||||
Danbooru.config.reverse_tag_category_mapping.each do |value, category|
|
TagCategory.reverse_mapping.each do |value, category|
|
||||||
define_method(category) do
|
define_method(category) do
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def regexp
|
def regexp
|
||||||
@regexp ||= Regexp.compile(Danbooru.config.tag_category_mapping.keys.sort_by {|x| -x.size}.join("|"))
|
@regexp ||= Regexp.compile(TagCategory.mapping.keys.sort_by {|x| -x.size}.join("|"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def value_for(string)
|
def value_for(string)
|
||||||
Danbooru.config.tag_category_mapping[string.to_s.downcase] || 0
|
TagCategory.mapping[string.to_s.downcase] || 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -125,7 +125,7 @@ class Tag < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def category_name
|
def category_name
|
||||||
Danbooru.config.reverse_tag_category_mapping[category].capitalize
|
TagCategory.reverse_mapping[category].capitalize
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_category_cache_for_all
|
def update_category_cache_for_all
|
||||||
@@ -141,7 +141,7 @@ class Tag < ApplicationRecord
|
|||||||
Post.raw_tag_match(name).where("true /* Tag#update_category_post_counts */").find_each do |post|
|
Post.raw_tag_match(name).where("true /* Tag#update_category_post_counts */").find_each do |post|
|
||||||
post.reload
|
post.reload
|
||||||
post.set_tag_counts
|
post.set_tag_counts
|
||||||
args = Hash[Danbooru.config.full_tag_config_info.keys.map {|x| ["tag_count_#{x}",post.send("tag_count_#{x}")]}].update(:tag_count => post.tag_count)
|
args = Hash[TagCategory.categories {|x| ["tag_count_#{x}",post.send("tag_count_#{x}")]}].update(:tag_count => post.tag_count)
|
||||||
Post.where(:id => post.id).update_all(args)
|
Post.where(:id => post.id).update_all(args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -177,7 +177,7 @@ class Tag < ApplicationRecord
|
|||||||
counts = counts.to_a.select {|x| x[1] > trending_count_limit}
|
counts = counts.to_a.select {|x| x[1] > trending_count_limit}
|
||||||
counts = counts.map do |tag_name, recent_count|
|
counts = counts.map do |tag_name, recent_count|
|
||||||
tag = Tag.find_or_create_by_name(tag_name)
|
tag = Tag.find_or_create_by_name(tag_name)
|
||||||
if tag.category == Danbooru.config.tag_category_mapping["artist"]
|
if tag.category == Tag.categories.artist
|
||||||
# we're not interested in artists in the trending list
|
# we're not interested in artists in the trending list
|
||||||
[tag_name, 0]
|
[tag_name, 0]
|
||||||
else
|
else
|
||||||
@@ -666,8 +666,8 @@ class Tag < ApplicationRecord
|
|||||||
when "tagcount"
|
when "tagcount"
|
||||||
q[:post_tag_count] = parse_helper(g2)
|
q[:post_tag_count] = parse_helper(g2)
|
||||||
|
|
||||||
when /(#{Danbooru.config.short_tag_name_mapping.keys.join("|")})tags/
|
when /(#{TagCategory.short_name_regex})tags/
|
||||||
q["#{Danbooru.config.short_tag_name_mapping[$1]}_tag_count".to_sym] = parse_helper(g2)
|
q["#{TagCategory.short_name_mapping[$1]}_tag_count".to_sym] = parse_helper(g2)
|
||||||
|
|
||||||
when "parent"
|
when "parent"
|
||||||
q[:parent] = g2.downcase
|
q[:parent] = g2.downcase
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ class PostPresenter < Presenter
|
|||||||
def categorized_tag_groups
|
def categorized_tag_groups
|
||||||
string = []
|
string = []
|
||||||
|
|
||||||
Danbooru.config.categorized_tag_list.each do |category|
|
TagCategory.categorized_list.each do |category|
|
||||||
if @post.typed_tags(category).any?
|
if @post.typed_tags(category).any?
|
||||||
string << @post.typed_tags(category).join(" ")
|
string << @post.typed_tags(category).join(" ")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -25,10 +25,10 @@ class TagSetPresenter < Presenter
|
|||||||
def split_tag_list_html(template, options = {})
|
def split_tag_list_html(template, options = {})
|
||||||
html = ""
|
html = ""
|
||||||
|
|
||||||
Danbooru.config.split_tag_header_list.each do |category|
|
TagCategory.split_header_list.each do |category|
|
||||||
typetags = typed_tags(category)
|
typetags = typed_tags(category)
|
||||||
if typetags.any?
|
if typetags.any?
|
||||||
html << Danbooru.config.full_tag_config_info[category]["header"]
|
html << TagCategory.header_mapping[category]
|
||||||
html << "<ul>"
|
html << "<ul>"
|
||||||
typetags.each do |tag|
|
typetags.each do |tag|
|
||||||
html << build_list_item(tag, template, options)
|
html << build_list_item(tag, template, options)
|
||||||
@@ -56,7 +56,7 @@ private
|
|||||||
@typed_tags ||= {}
|
@typed_tags ||= {}
|
||||||
@typed_tags[name] ||= begin
|
@typed_tags[name] ||= begin
|
||||||
@tags.select do |tag|
|
@tags.select do |tag|
|
||||||
categories[tag] == Danbooru.config.tag_category_mapping[name]
|
categories[tag] == TagCategory.mapping[name]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,8 +8,8 @@
|
|||||||
<% unless cookies[:dm] %>
|
<% unless cookies[:dm] %>
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||||
<% end %>
|
<% end %>
|
||||||
<meta name="tag-category-names" content="<%= Danbooru.config.tag_category_mapping.keys %>">
|
<meta name="tag-category-names" content="<%= TagCategory.categories %>">
|
||||||
<meta name="short-tag-category-names" content="<%= Danbooru.config.short_tag_name_mapping.keys %>">
|
<meta name="short-tag-category-names" content="<%= TagCategory.short_name_list %>">
|
||||||
<meta name="current-user-name" content="<%= CurrentUser.name %>">
|
<meta name="current-user-name" content="<%= CurrentUser.name %>">
|
||||||
<meta name="current-user-id" content="<%= CurrentUser.id %>">
|
<meta name="current-user-id" content="<%= CurrentUser.id %>">
|
||||||
<meta name="current-user-can-approve-posts" content="<%= CurrentUser.can_approve_posts? %>">
|
<meta name="current-user-can-approve-posts" content="<%= CurrentUser.can_approve_posts? %>">
|
||||||
|
|||||||
@@ -78,8 +78,8 @@
|
|||||||
|
|
||||||
<%= button_tag "Related tags", :id => "related-tags-button", :type => "button", :class => "ui-button ui-widget ui-corner-all sub gradient" %>
|
<%= button_tag "Related tags", :id => "related-tags-button", :type => "button", :class => "ui-button ui-widget ui-corner-all sub gradient" %>
|
||||||
|
|
||||||
<% Danbooru.config.related_tag_button_list.each do |category| %>
|
<% TagCategory.related_button_list.each do |category| %>
|
||||||
<%= button_tag "#{Danbooru.config.full_tag_config_info[category]["relatedtag"]}", :id => "related-#{category}-button", :type => "button", :class => "ui-button ui-widget ui-corner-all sub gradient" %>
|
<%= button_tag "#{TagCategory.related_button_mapping[category]}", :id => "related-#{category}-button", :type => "button", :class => "ui-button ui-widget ui-corner-all sub gradient" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -153,7 +153,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% content_for(:html_header) do %>
|
<% content_for(:html_header) do %>
|
||||||
<meta name="related-tag-button-list" content="<%= Danbooru.config.related_tag_button_list %>">
|
<meta name="related-tag-button-list" content="<%= TagCategory.related_button_list %>">
|
||||||
<meta name="description" content="<%= @post.presenter.humanized_tag_string %>">
|
<meta name="description" content="<%= @post.presenter.humanized_tag_string %>">
|
||||||
<meta name="tags" content="<%= @post.tag_string %>">
|
<meta name="tags" content="<%= @post.tag_string %>">
|
||||||
<meta name="favorites" content="<%= @post.fav_string %>">
|
<meta name="favorites" content="<%= @post.fav_string %>">
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<section>
|
<section>
|
||||||
<%= form_tag(related_tag_path, :method => :get) do %>
|
<%= form_tag(related_tag_path, :method => :get) do %>
|
||||||
<%= text_field_tag "query", params[:query], :data => { :autocomplete => "tag" } %>
|
<%= text_field_tag "query", params[:query], :data => { :autocomplete => "tag" } %>
|
||||||
<%= select_tag "category", options_for_select([""] + Danbooru.config.canonical_tag_category_mapping.map{|x| [x.first, x.first.downcase]}, params[:category]) %>
|
<%= select_tag "category", options_for_select([""] + TagCategory.canonical_mapping.map{|x| [x.first, x.first.downcase]}, params[:category]) %>
|
||||||
<%= submit_tag "Show"%>
|
<%= submit_tag "Show"%>
|
||||||
<% end %>
|
<% end %>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<%= simple_form_for(:search, method: :get, url: tag_aliases_path, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
<%= simple_form_for(:search, method: :get, url: tag_aliases_path, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||||
<%= f.input :name_matches, label: "Name", input_html: { value: params[:search][:name_matches], data: { autocomplete: "tag" } } %>
|
<%= f.input :name_matches, label: "Name", input_html: { value: params[:search][:name_matches], data: { autocomplete: "tag" } } %>
|
||||||
<%= f.input :status, label: "Status", collection: ["", "Approved", "Pending"], selected: params[:search][:status] %>
|
<%= f.input :status, label: "Status", collection: ["", "Approved", "Pending"], selected: params[:search][:status] %>
|
||||||
<%= f.input :category, label: "Category", collection: Danbooru.config.canonical_tag_category_mapping.to_a, include_blank: true, selected: params[:search][:category] %>
|
<%= f.input :category, label: "Category", collection: TagCategory.canonical_mapping.to_a, include_blank: true, selected: params[:search][:category] %>
|
||||||
<%= f.input :order, label: "Order", collection: [%w[Status status], %w[Recently\ created created_at], %w[Recently\ updated updated_at], %w[Name name], %w[Tag\ count tag_count]], selected: params[:search][:order] %>
|
<%= f.input :order, label: "Order", collection: [%w[Status status], %w[Recently\ created created_at], %w[Recently\ updated updated_at], %w[Name name], %w[Tag\ count tag_count]], selected: params[:search][:order] %>
|
||||||
<%= f.submit "Search" %>
|
<%= f.submit "Search" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<%= simple_form_for(:search, method: :get, url: tag_implications_path, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
<%= simple_form_for(:search, method: :get, url: tag_implications_path, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||||
<%= f.input :name_matches, label: "Name", input_html: { value: params[:search][:name_matches], data: { autocomplete: "tag" } } %>
|
<%= f.input :name_matches, label: "Name", input_html: { value: params[:search][:name_matches], data: { autocomplete: "tag" } } %>
|
||||||
<%= f.input :status, label: "Status", collection: ["", "Approved", "Pending"], selected: params[:search][:status] %>
|
<%= f.input :status, label: "Status", collection: ["", "Approved", "Pending"], selected: params[:search][:status] %>
|
||||||
<%= f.input :category, label: "Category", collection: Danbooru.config.canonical_tag_category_mapping.to_a, include_blank: true, selected: params[:search][:category] %>
|
<%= f.input :category, label: "Category", collection: TagCategory.canonical_mapping.to_a, include_blank: true, selected: params[:search][:category] %>
|
||||||
<%= f.input :order, label: "Order", collection: [%w[Status status], %w[Recently\ created created_at], %w[Recently\ updated updated_at], %w[Name name], %w[Tag\ count tag_count]], selected: params[:search][:order] %>
|
<%= f.input :order, label: "Order", collection: [%w[Status status], %w[Recently\ created created_at], %w[Recently\ updated updated_at], %w[Name name], %w[Tag\ count tag_count]], selected: params[:search][:order] %>
|
||||||
<%= f.submit "Search" %>
|
<%= f.submit "Search" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<%= simple_form_for(:search, url: tags_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
<%= simple_form_for(:search, url: tags_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||||
<%= f.input :name_matches, label: "Name", hint: "Use * for wildcard", input_html: { value: params[:search][:name_matches], data: { autocomplete: "tag" } } %>
|
<%= f.input :name_matches, label: "Name", hint: "Use * for wildcard", input_html: { value: params[:search][:name_matches], data: { autocomplete: "tag" } } %>
|
||||||
<%= f.input :category, label: "Category", collection: Danbooru.config.canonical_tag_category_mapping.to_a, include_blank: true,selected: params[:search][:category] %>
|
<%= f.input :category, label: "Category", collection: TagCategory.canonical_mapping.to_a, include_blank: true,selected: params[:search][:category] %>
|
||||||
<%= f.input :order, collection: [%w[Newest date], %w[Count count], %w[Name name]], include_blank: false, selected: params[:search][:order] %>
|
<%= f.input :order, collection: [%w[Newest date], %w[Count count], %w[Name name]], include_blank: false, selected: params[:search][:order] %>
|
||||||
<%= f.input :hide_empty, label: "Hide empty?", collection: %w[yes no], selected: params[:search][:hide_empty] %>
|
<%= f.input :hide_empty, label: "Hide empty?", collection: %w[yes no], selected: params[:search][:hide_empty] %>
|
||||||
<%= f.input :has_wiki, label: "Has wiki?", collection: %w[yes no], include_blank: true, selected: params[:search][:has_wiki] %>
|
<%= f.input :has_wiki, label: "Has wiki?", collection: %w[yes no], include_blank: true, selected: params[:search][:has_wiki] %>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<% if @tag.is_locked? %>
|
<% if @tag.is_locked? %>
|
||||||
<p>This tag is category locked</p>
|
<p>This tag is category locked</p>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= f.input :category, :collection => Danbooru.config.canonical_tag_category_mapping.to_a, :include_blank => false %>
|
<%= f.input :category, :collection => TagCategory.canonical_mapping.to_a, :include_blank => false %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if CurrentUser.is_moderator? %>
|
<% if CurrentUser.is_moderator? %>
|
||||||
|
|||||||
@@ -110,9 +110,9 @@
|
|||||||
|
|
||||||
<%= button_tag "Related tags", :id => "related-tags-button", :type => "button", :class => "ui-button ui-widget ui-corner-all sub gradient" %>
|
<%= button_tag "Related tags", :id => "related-tags-button", :type => "button", :class => "ui-button ui-widget ui-corner-all sub gradient" %>
|
||||||
|
|
||||||
<% Danbooru.config.related_tag_button_list.each do |category| %>
|
<% TagCategory.related_button_list.each do |category| %>
|
||||||
<%= button_tag "#{Danbooru.config.full_tag_config_info[category]["relatedtag"]}", :id => "related-#{category}-button", :type => "button", :class => "ui-button ui-widget ui-corner-all sub gradient" %>
|
<%= button_tag "#{TagCategory.related_button_mapping[category]}", :id => "related-#{category}-button", :type => "button", :class => "ui-button ui-widget ui-corner-all sub gradient" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="input">
|
<div class="input">
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ module Danbooru
|
|||||||
"extra" => [],
|
"extra" => [],
|
||||||
"header" => "<h1>Tags</h1>",
|
"header" => "<h1>Tags</h1>",
|
||||||
"humanized" => nil,
|
"humanized" => nil,
|
||||||
"relatedtag" => "General"
|
"relatedbutton" => "General"
|
||||||
},
|
},
|
||||||
"character" => {
|
"character" => {
|
||||||
"category" => 4,
|
"category" => 4,
|
||||||
@@ -238,7 +238,7 @@ module Danbooru
|
|||||||
"regexmap" => /^(.+?)(?:_\(.+\))?$/,
|
"regexmap" => /^(.+?)(?:_\(.+\))?$/,
|
||||||
"formatstr" => "%s"
|
"formatstr" => "%s"
|
||||||
},
|
},
|
||||||
"relatedtag" => "Characters"
|
"relatedbutton" => "Characters"
|
||||||
},
|
},
|
||||||
"copyright" => {
|
"copyright" => {
|
||||||
"category" => 3,
|
"category" => 3,
|
||||||
@@ -251,7 +251,7 @@ module Danbooru
|
|||||||
"regexmap" => //,
|
"regexmap" => //,
|
||||||
"formatstr" => "(%s)"
|
"formatstr" => "(%s)"
|
||||||
},
|
},
|
||||||
"relatedtag" => "Copyrights"
|
"relatedbutton" => "Copyrights"
|
||||||
},
|
},
|
||||||
"artist" => {
|
"artist" => {
|
||||||
"category" => 1,
|
"category" => 1,
|
||||||
@@ -264,7 +264,7 @@ module Danbooru
|
|||||||
"regexmap" => //,
|
"regexmap" => //,
|
||||||
"formatstr" => "drawn by %s"
|
"formatstr" => "drawn by %s"
|
||||||
},
|
},
|
||||||
"relatedtag" => "Artists"
|
"relatedbutton" => "Artists"
|
||||||
},
|
},
|
||||||
"meta" => {
|
"meta" => {
|
||||||
"category" => 5,
|
"category" => 5,
|
||||||
@@ -272,37 +272,11 @@ module Danbooru
|
|||||||
"extra" => [],
|
"extra" => [],
|
||||||
"header" => "<h2>Meta</h2>",
|
"header" => "<h2>Meta</h2>",
|
||||||
"humanized" => nil,
|
"humanized" => nil,
|
||||||
"relatedtag" => nil
|
"relatedbutton" => nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
#TAG MAPPINGS
|
|
||||||
|
|
||||||
# Returns a hash mapping various tag categories to a numerical value.
|
|
||||||
def tag_category_mapping
|
|
||||||
@tag_category_mapping ||= Hash[
|
|
||||||
full_tag_config_info.map {|k,v| v["extra"].map {|y| [y,v["category"]]}}
|
|
||||||
.reduce([],:+)]
|
|
||||||
.update(Hash[full_tag_config_info.map {|k,v| [v["short"],v["category"]]}])
|
|
||||||
.update( Hash[full_tag_config_info.map {|k,v| [k,v["category"]]}])
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns a hash mapping more suited for views
|
|
||||||
def canonical_tag_category_mapping
|
|
||||||
@canonical_tag_category_mapping ||= Hash[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_tag_category_mapping
|
|
||||||
@reverse_tag_category_mapping ||= Hash[full_tag_config_info.map {|k,v| [v["category"],k]}]
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns a hash mapping for the short name usage in metatags
|
|
||||||
def short_tag_name_mapping
|
|
||||||
@short_tag_name_mapping ||= Hash[full_tag_config_info.map {|k,v| [v["short"],k] }]
|
|
||||||
end
|
|
||||||
|
|
||||||
#TAG ORDERS
|
#TAG ORDERS
|
||||||
|
|
||||||
#Sets the order of the humanized essential tag string (models/post.rb)
|
#Sets the order of the humanized essential tag string (models/post.rb)
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ class TagTest < ActiveSupport::TestCase
|
|||||||
should_not allow_value("café").for(:name).on(:create)
|
should_not allow_value("café").for(:name).on(:create)
|
||||||
should_not allow_value("東方").for(:name).on(:create)
|
should_not allow_value("東方").for(:name).on(:create)
|
||||||
|
|
||||||
metatags = Tag::METATAGS.split("|") + Tag::SUBQUERY_METATAGS.split("|") + Danbooru.config.tag_category_mapping.keys
|
metatags = Tag::METATAGS.split("|") + Tag::SUBQUERY_METATAGS.split("|") + TagCategory.mapping.keys
|
||||||
metatags.split("|").each do |metatag|
|
metatags.split("|").each do |metatag|
|
||||||
should_not allow_value("#{metatag}:foo").for(:name).on(:create)
|
should_not allow_value("#{metatag}:foo").for(:name).on(:create)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user