2018-10-08 21:44:25 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-01-05 00:43:11 +00:00
|
|
|
require "rails"
|
|
|
|
require "action_controller/railtie"
|
|
|
|
require "active_record/railtie"
|
|
|
|
require "active_storage/engine"
|
|
|
|
|
|
|
|
require "action_text"
|
2018-02-07 18:43:36 +00:00
|
|
|
|
2018-04-13 23:23:04 +00:00
|
|
|
module ActionText
|
2018-02-07 18:43:36 +00:00
|
|
|
class Engine < Rails::Engine
|
2018-04-13 23:23:04 +00:00
|
|
|
isolate_namespace ActionText
|
|
|
|
config.eager_load_namespaces << ActionText
|
2018-02-08 20:48:45 +00:00
|
|
|
|
2021-03-05 21:57:36 +00:00
|
|
|
config.action_text = ActiveSupport::OrderedOptions.new
|
|
|
|
config.action_text.attachment_tag_name = "action-text-attachment"
|
2021-03-07 21:34:54 +00:00
|
|
|
config.autoload_once_paths = %W(
|
|
|
|
#{root}/app/helpers
|
|
|
|
#{root}/app/models
|
|
|
|
)
|
2021-03-05 21:57:36 +00:00
|
|
|
|
2018-04-13 23:23:04 +00:00
|
|
|
initializer "action_text.attribute" do
|
2018-02-08 20:48:45 +00:00
|
|
|
ActiveSupport.on_load(:active_record) do
|
2018-04-13 23:23:04 +00:00
|
|
|
include ActionText::Attribute
|
2021-03-12 21:59:24 +00:00
|
|
|
prepend ActionText::Encryption
|
2018-02-08 20:48:45 +00:00
|
|
|
end
|
|
|
|
end
|
2018-02-12 15:16:49 +00:00
|
|
|
|
2021-07-26 22:57:42 +00:00
|
|
|
initializer "action_text.asset" do
|
|
|
|
if Rails.application.config.respond_to?(:assets)
|
2021-07-28 19:34:59 +00:00
|
|
|
Rails.application.config.assets.precompile += %w( actiontext.js trix.js trix.css )
|
2021-07-26 22:57:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-05 00:43:11 +00:00
|
|
|
initializer "action_text.attachable" do
|
2018-10-04 02:23:02 +00:00
|
|
|
ActiveSupport.on_load(:active_storage_blob) do
|
2018-04-13 23:23:04 +00:00
|
|
|
include ActionText::Attachable
|
2018-02-12 23:21:49 +00:00
|
|
|
|
|
|
|
def previewable_attachable?
|
|
|
|
representable?
|
|
|
|
end
|
2019-07-08 02:03:06 +00:00
|
|
|
|
|
|
|
def attachable_plain_text_representation(caption = nil)
|
|
|
|
"[#{caption || filename}]"
|
|
|
|
end
|
2019-12-03 10:57:36 +00:00
|
|
|
|
|
|
|
def to_trix_content_attachment_partial_path
|
|
|
|
nil
|
|
|
|
end
|
2018-02-12 23:21:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-13 23:23:04 +00:00
|
|
|
initializer "action_text.helper" do
|
2020-09-11 16:43:27 +00: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 15:16:49 +00:00
|
|
|
end
|
|
|
|
end
|
2018-02-14 14:43:49 +00:00
|
|
|
|
2020-09-11 16:43:27 +00:00
|
|
|
initializer "action_text.renderer" do
|
2019-01-05 00:43:11 +00:00
|
|
|
ActiveSupport.on_load(:action_text_content) do
|
2020-12-07 21:41:44 +00:00
|
|
|
self.default_renderer = Class.new(ActionController::Base).renderer
|
2019-01-05 00:43:11 +00:00
|
|
|
end
|
2018-04-13 23:09:39 +00:00
|
|
|
|
2020-09-11 16:43:27 +00: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 14:43:49 +00:00
|
|
|
end
|
|
|
|
end
|
2019-05-13 16:44:06 +00: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 21:57:36 +00:00
|
|
|
|
|
|
|
initializer "action_text.configure" do |app|
|
|
|
|
ActionText::Attachment.tag_name = app.config.action_text.attachment_tag_name
|
|
|
|
end
|
2018-02-07 18:43:36 +00:00
|
|
|
end
|
|
|
|
end
|