2018-10-08 17:44:25 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-01-04 19:43:11 -05:00
|
|
|
require "rails"
|
|
|
|
require "action_controller/railtie"
|
|
|
|
require "active_record/railtie"
|
|
|
|
require "active_storage/engine"
|
|
|
|
|
|
|
|
require "action_text"
|
2018-02-07 13:43:36 -05:00
|
|
|
|
2018-04-13 19:23:04 -04:00
|
|
|
module ActionText
|
2018-02-07 13:43:36 -05:00
|
|
|
class Engine < Rails::Engine
|
2018-04-13 19:23:04 -04:00
|
|
|
isolate_namespace ActionText
|
|
|
|
config.eager_load_namespaces << ActionText
|
2018-02-08 15:48:45 -05:00
|
|
|
|
2021-03-05 16:57:36 -05:00
|
|
|
config.action_text = ActiveSupport::OrderedOptions.new
|
|
|
|
config.action_text.attachment_tag_name = "action-text-attachment"
|
|
|
|
|
2018-04-13 19:23:04 -04:00
|
|
|
initializer "action_text.attribute" do
|
2018-02-08 15:48:45 -05:00
|
|
|
ActiveSupport.on_load(:active_record) do
|
2018-04-13 19:23:04 -04:00
|
|
|
include ActionText::Attribute
|
2018-02-08 15:48:45 -05:00
|
|
|
end
|
|
|
|
end
|
2018-02-12 10:16:49 -05:00
|
|
|
|
2019-01-04 19:43:11 -05:00
|
|
|
initializer "action_text.attachable" do
|
2018-10-03 22:23:02 -04:00
|
|
|
ActiveSupport.on_load(:active_storage_blob) do
|
2018-04-13 19:23:04 -04:00
|
|
|
include ActionText::Attachable
|
2018-02-12 18:21:49 -05:00
|
|
|
|
|
|
|
def previewable_attachable?
|
|
|
|
representable?
|
|
|
|
end
|
2019-07-07 22:03:06 -04:00
|
|
|
|
|
|
|
def attachable_plain_text_representation(caption = nil)
|
|
|
|
"[#{caption || filename}]"
|
|
|
|
end
|
2019-12-03 05:57:36 -05:00
|
|
|
|
|
|
|
def to_trix_content_attachment_partial_path
|
|
|
|
nil
|
|
|
|
end
|
2018-02-12 18:21:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-13 19:23:04 -04:00
|
|
|
initializer "action_text.helper" do
|
2020-09-11 12:43:27 -04:00
|
|
|
%i[action_controller_base action_mailer].each do |abstract_controller|
|
|
|
|
ActiveSupport.on_load(abstract_controller) do
|
|
|
|
helper ActionText::Engine.helpers
|
|
|
|
end
|
2018-02-12 10:16:49 -05:00
|
|
|
end
|
|
|
|
end
|
2018-02-14 09:43:49 -05:00
|
|
|
|
2020-09-11 12:43:27 -04:00
|
|
|
initializer "action_text.renderer" do
|
2019-01-04 19:43:11 -05:00
|
|
|
ActiveSupport.on_load(:action_text_content) do
|
2020-12-07 16:41:44 -05:00
|
|
|
self.default_renderer = Class.new(ActionController::Base).renderer
|
2019-01-04 19:43:11 -05:00
|
|
|
end
|
2018-04-13 19:09:39 -04:00
|
|
|
|
2020-09-11 12:43:27 -04:00
|
|
|
%i[action_controller_base action_mailer].each do |abstract_controller|
|
|
|
|
ActiveSupport.on_load(abstract_controller) do
|
|
|
|
around_action do |controller, action|
|
|
|
|
ActionText::Content.with_renderer(controller, &action)
|
|
|
|
end
|
|
|
|
end
|
2018-02-14 09:43:49 -05:00
|
|
|
end
|
|
|
|
end
|
2019-05-13 12:44:06 -04:00
|
|
|
|
|
|
|
initializer "action_text.system_test_helper" do
|
|
|
|
ActiveSupport.on_load(:action_dispatch_system_test_case) do
|
|
|
|
require "action_text/system_test_helper"
|
|
|
|
include ActionText::SystemTestHelper
|
|
|
|
end
|
|
|
|
end
|
2021-03-05 16:57:36 -05:00
|
|
|
|
|
|
|
initializer "action_text.configure" do |app|
|
|
|
|
ActionText::Attachment.tag_name = app.config.action_text.attachment_tag_name
|
|
|
|
end
|
2018-02-07 13:43:36 -05:00
|
|
|
end
|
|
|
|
end
|