<commit_before>module Wanko
  module ActionView
    module Helpers
      module RenderingHelper
        def render(options = {}, locals = {}, &block)
          if (Hash === options) && options.key?(:extension)
            ext_name = options[:extension][/[^\/]*/]
            if ext_name.classify.constantize::Engine.active? controller
              return view_renderer.render(self, options, &block)
            else
              return capture(&block)
            end
          end
          super
        end
      end
    end

    module Renderer
      def render(context, options, &block)
        if options.key? :extension
          render_extension(context, options, &block)
        else
          super
        end
      end

      def render_extension(context, options, &block)
        partial_name = options.delete :extension
        Wanko::ExtensionRenderer.new(@lookup_context).render(context, options.merge(partial: partial_name), block)
      end
    end
  end

  class ExtensionRenderer < ::ActionView::PartialRenderer
    def render(context, options, block)
      super
    rescue => e
      ext_name = options[:partial][/[^\/]*/]
      (ext_name.classify.constantize::Engine.on_error || Wanko.config.on_error).call(e)
      context.capture(&block)
    end
  end
end

ActionView::Base.prepend Wanko::ActionView::Helpers::RenderingHelper
ActionView::Renderer.prepend Wanko::ActionView::Renderer<commit_msg>AMCing AV::Base#render for now<commit_after>ActionView::Base.class_eval do
  #FIXME FIXHAML AMCing here because prepending on `render` causes infinite loop when Haml is bundled
  def render_with_wanko(options = {}, locals = {}, &block)
    if (Hash === options) && options.key?(:extension)
      ext_name = options[:extension][/[^\/]*/]
      if ext_name.classify.constantize::Engine.active? controller
        return view_renderer.render(self, options, &block)
      else
        return capture(&block)
      end
    end
    render_without_wanko options, locals, &block
  end

  alias_method_chain :render, :wanko
end

module Wanko
  module ActionView
    module Renderer
      def render(context, options, &block)
        if options.key? :extension
          render_extension(context, options, &block)
        else
          super
        end
      end

      def render_extension(context, options, &block)
        partial_name = options.delete :extension
        Wanko::ExtensionRenderer.new(@lookup_context).render(context, options.merge(partial: partial_name), block)
      end
    end
  end

  class ExtensionRenderer < ::ActionView::PartialRenderer
    def render(context, options, block)
      super
    rescue => e
      ext_name = options[:partial][/[^\/]*/]
      (ext_name.classify.constantize::Engine.on_error || Wanko.config.on_error).call(e)
      context.capture(&block)
    end
  end
end

ActionView::Renderer.prepend Wanko::ActionView::Renderer
{'fraction_non_alphanumeric': 0.10613943808532779, 'fraction_numerical': 0.0, 'mean_word_length': 2.840213049267643, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6780955', 'n_tokens_mistral': 827, 'n_tokens_neox': 819, 'n_words': 190}