2018-02-07 13:43:36 -05:00
|
|
|
require "rails/engine"
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2018-04-13 19:23:04 -04:00
|
|
|
initializer "action_text.active_storage_extension" do
|
2018-02-12 18:21:49 -05:00
|
|
|
require "active_storage/blob"
|
|
|
|
|
|
|
|
class ActiveStorage::Blob
|
2018-04-13 19:23:04 -04:00
|
|
|
include ActionText::Attachable
|
2018-02-12 18:21:49 -05:00
|
|
|
|
|
|
|
def previewable_attachable?
|
|
|
|
representable?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-13 19:23:04 -04:00
|
|
|
initializer "action_text.helper" do
|
2018-02-12 10:16:49 -05:00
|
|
|
ActiveSupport.on_load(:action_controller_base) do
|
2018-04-13 19:23:04 -04:00
|
|
|
helper ActionText::TagHelper
|
2018-02-12 10:16:49 -05:00
|
|
|
end
|
|
|
|
end
|
2018-02-14 09:43:49 -05:00
|
|
|
|
2018-04-13 19:23:04 -04:00
|
|
|
initializer "action_text.config" do
|
2018-02-14 09:43:49 -05:00
|
|
|
config.after_initialize do |app|
|
2018-04-13 19:23:04 -04:00
|
|
|
ActionText.renderer ||= ApplicationController.renderer
|
2018-04-13 19:09:39 -04:00
|
|
|
|
|
|
|
# FIXME: ApplicationController should have a per-request specific renderer
|
2018-04-13 19:23:04 -04:00
|
|
|
# that's been set with the request.env env, and ActionText should just piggyback off
|
2018-04-13 19:09:39 -04:00
|
|
|
# that by default rather than doing this work directly.
|
|
|
|
ApplicationController.before_action do
|
2018-04-13 19:23:04 -04:00
|
|
|
ActionText.renderer = ActionText.renderer.new(request.env)
|
2018-04-13 19:09:39 -04:00
|
|
|
end
|
2018-02-14 09:43:49 -05:00
|
|
|
end
|
|
|
|
end
|
2018-02-07 13:43:36 -05:00
|
|
|
end
|
|
|
|
end
|