discourse/app/serializers/watched_word_serializer.rb
Régis Hanol 1eec8c3fa6 FEATURE: add HTML replacements
This adds support for Watched Words to allow replacement with HTML content rather than always replacing with text.

Can be useful when automatically replacing with the '<abbr>' tag for example.

Discussion - https://meta.discourse.org/t/replace-text-with-more-than-just-links/305672
2024-05-14 10:41:27 +02:00

29 lines
579 B
Ruby

# frozen_string_literal: true
class WatchedWordSerializer < ApplicationSerializer
attributes :id,
:word,
:regexp,
:replacement,
:action,
:case_sensitive,
:watched_word_group_id,
:html
def regexp
WordWatcher.word_to_regexp(word, engine: :js)
end
def action
WatchedWord.actions[object.action]
end
def include_replacement?
WatchedWord.has_replacement?(action)
end
def include_html?
object.action == WatchedWord.actions[:replace] && object.html
end
end