Move ActsAsTaggableOn::Tag overrides to initializer
This is to prepare for zeitwerk autoloader, and the old file couldn't be autoloaded anyway, so the easiest is to just move it out of the models folder.
This commit is contained in:
parent
429aa8f374
commit
14e27a65ae
4 changed files with 25 additions and 28 deletions
|
|
@ -43,7 +43,7 @@
|
||||||
|
|
||||||
var hashtagPlugin = window.markdownitHashtag;
|
var hashtagPlugin = window.markdownitHashtag;
|
||||||
md.use(hashtagPlugin, {
|
md.use(hashtagPlugin, {
|
||||||
// compare tag_text_regexp in app/models/acts_as_taggable_on-tag.rb
|
// compare tag_text_regexp in config/initializers/acts_as_taggable_on.rb
|
||||||
hashtagRegExp: "[" + PosixBracketExpressions.word +
|
hashtagRegExp: "[" + PosixBracketExpressions.word +
|
||||||
"\\u055b" + // Armenian emphasis mark
|
"\\u055b" + // Armenian emphasis mark
|
||||||
"\\u055c" + // Armenian exclamation mark
|
"\\u055c" + // Armenian exclamation mark
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ app.views.TagFollowingList = app.views.Base.extend({
|
||||||
if(evt){ evt.preventDefault(); }
|
if(evt){ evt.preventDefault(); }
|
||||||
|
|
||||||
var name = this.$(".tag_input").val();
|
var name = this.$(".tag_input").val();
|
||||||
// compare tag_text_regexp in app/models/acts_as_taggable_on-tag.rb
|
// compare tag_text_regexp in config/initializers/acts_as_taggable_on.rb
|
||||||
var normalizedName = (name === "<3" ? name : name.replace(
|
var normalizedName = (name === "<3" ? name : name.replace(
|
||||||
new RegExp("[^" + PosixBracketExpressions.alnum + "_\\-]+", "gi"), "").toLowerCase());
|
new RegExp("[^" + PosixBracketExpressions.alnum + "_\\-]+", "gi"), "").toLowerCase());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
module ActsAsTaggableOn
|
|
||||||
class Tag
|
|
||||||
|
|
||||||
self.include_root_in_json = false
|
|
||||||
|
|
||||||
def self.tag_text_regexp
|
|
||||||
@tag_text_regexp ||= "[[:word:]]\u055b\u055c\u055e\u058a_-"
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.autocomplete(name)
|
|
||||||
where("name LIKE ?", "#{name.downcase}%").order("name ASC")
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.normalize(name)
|
|
||||||
if name =~ /^#?<3/
|
|
||||||
# Special case for love, because the world needs more love.
|
|
||||||
'<3'
|
|
||||||
elsif name
|
|
||||||
name.gsub(/[^#{self.tag_text_regexp}]/, '').downcase
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
@ -1,4 +1,26 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'models/acts_as_taggable_on-tag'
|
module ActsAsTaggableOn
|
||||||
|
class Tag
|
||||||
|
self.include_root_in_json = false
|
||||||
|
|
||||||
|
def self.tag_text_regexp
|
||||||
|
@tag_text_regexp ||= "[[:word:]]\u055b\u055c\u055e\u058a_-"
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.autocomplete(name)
|
||||||
|
where("name LIKE ?", "#{name.downcase}%").order("name ASC")
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.normalize(name)
|
||||||
|
if name =~ /^#?<3/
|
||||||
|
# Special case for love, because the world needs more love.
|
||||||
|
"<3"
|
||||||
|
elsif name
|
||||||
|
name.gsub(/[^#{tag_text_regexp}]/, "").downcase
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
ActsAsTaggableOn.force_lowercase = true
|
ActsAsTaggableOn.force_lowercase = true
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue