1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actiontext/lib/action_text/rendering.rb
Jonathan Hefner 614e813161
Disentangle Action Text from ApplicationController
This commit allows Action Text to be used without having an
ApplicationController defined.  In doing so, it also fixes Action Text
attachments to render the correct URL host in mailers.

It also avoids allocating an ActionController::Renderer per request.

Fixes #37183.
Fixes #35578.
Fixes #36963.
Closes #38714.

Co-authored-by: Jeremy Daer <jeremydaer@gmail.com>
2020-10-30 01:01:42 +00:00

29 lines
661 B
Ruby

# frozen_string_literal: true
require "active_support/concern"
require "active_support/core_ext/module/attribute_accessors_per_thread"
module ActionText
module Rendering #:nodoc:
extend ActiveSupport::Concern
included do
thread_cattr_accessor :renderer, instance_accessor: false
delegate :render, to: :class
end
class_methods do
def with_renderer(renderer)
previous_renderer = self.renderer
self.renderer = renderer
yield
ensure
self.renderer = previous_renderer
end
def render(*args, &block)
renderer.render_to_string(*args, &block)
end
end
end
end