Refactor formatter (#17828)
* Refactor formatter * Move custom emoji pre-rendering logic to view helpers * Move more methods out of Formatter * Fix code style issues * Remove Formatter * Add inline poll options to RSS feeds * Remove unused helper method * Fix code style issues * Various fixes and improvements * Fix test
This commit is contained in:
parent
2dd30804b6
commit
cefa526c6d
44 changed files with 932 additions and 1024 deletions
|
@ -2,10 +2,12 @@
|
|||
|
||||
module AccountsHelper
|
||||
def display_name(account, **options)
|
||||
str = account.display_name.presence || account.username
|
||||
|
||||
if options[:custom_emojify]
|
||||
Formatter.instance.format_display_name(account, **options)
|
||||
prerender_custom_emojis(h(str), account.emojis)
|
||||
else
|
||||
account.display_name.presence || account.username
|
||||
str
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -12,9 +12,6 @@ module Admin::Trends::StatusesHelper
|
|||
|
||||
return '' if text.blank?
|
||||
|
||||
html = Formatter.instance.send(:encode, text)
|
||||
html = Formatter.instance.send(:encode_custom_emojis, html, status.emojis, prefers_autoplay?)
|
||||
|
||||
html.html_safe # rubocop:disable Rails/OutputSafety
|
||||
prerender_custom_emojis(h(text), status.emojis)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -239,4 +239,8 @@ module ApplicationHelper
|
|||
end
|
||||
end.values
|
||||
end
|
||||
|
||||
def prerender_custom_emojis(html, custom_emojis)
|
||||
EmojiFormatter.new(html, custom_emojis, animate: prefers_autoplay?).to_s
|
||||
end
|
||||
end
|
||||
|
|
19
app/helpers/formatting_helper.rb
Normal file
19
app/helpers/formatting_helper.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module FormattingHelper
|
||||
def html_aware_format(text, local, options = {})
|
||||
HtmlAwareFormatter.new(text, local, options).to_s
|
||||
end
|
||||
|
||||
def linkify(text, options = {})
|
||||
TextFormatter.new(text, options).to_s
|
||||
end
|
||||
|
||||
def extract_plain_text(text, local)
|
||||
PlainTextFormatter.new(text, local).to_s
|
||||
end
|
||||
|
||||
def status_content_format(status)
|
||||
html_aware_format(status.text, status.local?, preloaded_accounts: [status.account] + (status.respond_to?(:active_mentions) ? status.active_mentions.map(&:account) : []))
|
||||
end
|
||||
end
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
module RoutingHelper
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
include Rails.application.routes.url_helpers
|
||||
include ActionView::Helpers::AssetTagHelper
|
||||
include Webpacker::Helper
|
||||
|
@ -22,8 +23,6 @@ module RoutingHelper
|
|||
full_asset_url(asset_pack_path(source, **options))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def use_storage?
|
||||
Rails.configuration.x.use_s3 || Rails.configuration.x.use_swift
|
||||
end
|
||||
|
|
|
@ -113,20 +113,6 @@ module StatusesHelper
|
|||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def simplified_text(text)
|
||||
text.dup.tap do |new_text|
|
||||
URI.extract(new_text).each do |url|
|
||||
new_text.gsub!(url, '')
|
||||
end
|
||||
|
||||
new_text.gsub!(Account::MENTION_RE, '')
|
||||
new_text.gsub!(Tag::HASHTAG_RE, '')
|
||||
new_text.gsub!(/\s+/, '')
|
||||
end
|
||||
end
|
||||
|
||||
def embedded_view?
|
||||
params[:controller] == EMBEDDED_CONTROLLER && params[:action] == EMBEDDED_ACTION
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue