Repository: rails/rails
File: actionpack/lib/action_controller/metal/renderers.rb (Ruby)

Code before:

    # A Set containing renderer names that correspond to available renderer procs.
    # Default values are `:json`, `:js`, `:xml`.
    RENDERERS = Set.new

    included do
      class_attribute :_renderers, default: Set.new.freeze
      class_attribute :escape_json_responses, instance_accessor: false, default: true

      redefine_method :escape_json_responses= do |value|
        if value
          ActionController.deprecator.warn(<<~MSG.squish)
            Setting action_controller.escape_json_responses = true is deprecated and will have no effect in Rails 8.2.
            Set it to `false`, or remove the config.
          MSG
        end
        namespaced_name = :"__class_attr_escape_json_responses"
        self.class.send(:"#{namespaced_name}=", value)
      end

      class << self
        redefine_method :escape_json_responses= do |value|
          if value
            ActionController.deprecator.warn(<<~MSG.squish)
              Setting action_controller.escape_json_responses = true is deprecated and will have no effect in Rails 8.2.
              Set it to `false` or use `config.load_defaults(8.1)`.
            MSG
          end
          namespaced_name = :"__class_attr_escape_json_responses"
          self.send(:"#{namespaced_name}=", value)
        end
      end
    end

    # Used in ActionController::Base and ActionController::API to include all
    # renderers by default.
    module All
      extend ActiveSupport::Concern
      include Renderers

      included do
        self._renderers = RENDERERS
      end
    end

    # Adds a new renderer to call within controller actions. A renderer is invoked
    # by passing its name as an option to AbstractController::Rendering#render. To
    # create a renderer pass it a name and a block. The block takes two arguments,
    # the first is the value paired with its key and the second is the remaining
    # hash of options passed to `render`.
    #

Review comment (suggestion):
```suggestion
              Set it to `false` or remove the config.
```

Code after:

    # A Set containing renderer names that correspond to available renderer procs.
    # Default values are `:json`, `:js`, `:xml`.
    RENDERERS = Set.new

    module DeprecatedEscapeJsonResponses # :nodoc:
      def escape_json_responses=(value)
        if value
          ActionController.deprecator.warn(<<~MSG.squish)
            Setting action_controller.escape_json_responses = true is deprecated and will have no effect in Rails 8.2.
            Set it to `false`, or remove the config.
          MSG
        end
        super
      end
    end

    included do
      class_attribute :_renderers, default: Set.new.freeze
      class_attribute :escape_json_responses, instance_writer: false, instance_accessor: false, default: true

      singleton_class.prepend DeprecatedEscapeJsonResponses
    end

    # Used in ActionController::Base and ActionController::API to include all
    # renderers by default.
    module All
      extend ActiveSupport::Concern
      include Renderers

      included do
        self._renderers = RENDERERS
      end
    end

    # Adds a new renderer to call within controller actions. A renderer is invoked
    # by passing its name as an option to AbstractController::Rendering#render. To
    # create a renderer pass it a name and a block. The block takes two arguments,
    # the first is the value paired with its key and the second is the remaining
    # hash of options passed to `render`.
    #
    # Create a csv renderer:
    #
    #     ActionController::Renderers.add :csv do |obj, options|
    #       filename = options[:filename] || 'data'
    #       str = obj.respond_to?(:to_csv) ? obj.to_csv : obj.to_s
    #       send_data str, type: Mime[:csv],
    #         disposition: "attachment; filename=#{filename}.csv"
    #     end
    #
    # Note that we used [Mime](:csv) for the csv mime type as it comes with Rails.