<commit_before>require 'active_support/core_ext/class/attribute_accessors'
require 'active_support/core_ext/string/output_safety'
require 'erubis'

module ActionView
  module TemplateHandlers
    class Erubis < ::Erubis::Eruby
      def add_preamble(src)
        src << "@output_buffer = ActionView::SafeBuffer.new;"
      end

      def add_text(src, text)
        src << "@output_buffer << ('" << escape_text(text) << "'.html_safe!);"
      end

      def add_expr_literal(src, code)
        src << '@output_buffer << ((' << code << ').to_s);'
      end

      def add_expr_escaped(src, code)
        src << '@output_buffer << ' << escaped_expr(code) << ';'
      end

      def add_postamble(src)
        src << '@output_buffer.to_s'
      end
    end

    class ERB < TemplateHandler
      include Compilable

      ##
      # :singleton-method:
      # Specify trim mode for the ERB compiler. Defaults to '-'.
      # See ERb documentation for suitable values.
      cattr_accessor :erb_trim_mode
      self.erb_trim_mode = '-'

      self.default_format = Mime::HTML

      def compile(template)
        magic = $1 if template.source =~ /\A(<%#.*coding[:=]\s*(\S+)\s*-?%>)/
        erb = "#{magic}<% __in_erb_template=true %>#{template.source}"
        Erubis.new(erb, :trim=>(self.class.erb_trim_mode == "-")).src
      end
    end<commit_msg>Make the erubis implementation easier for plugins to change.<commit_after>require 'active_support/core_ext/class/attribute_accessors'
require 'active_support/core_ext/string/output_safety'
require 'erubis'

module ActionView
  module TemplateHandlers
    class Erubis < ::Erubis::Eruby
      def add_preamble(src)
        src << "@output_buffer = ActionView::SafeBuffer.new;"
      end

      def add_text(src, text)
        src << "@output_buffer << ('" << escape_text(text) << "'.html_safe!);"
      end

      def add_expr_literal(src, code)
        src << '@output_buffer << ((' << code << ').to_s);'
      end

      def add_expr_escaped(src, code)
        src << '@output_buffer << ' << escaped_expr(code) << ';'
      end

      def add_postamble(src)
        src << '@output_buffer.to_s'
      end
    end

    class ERB < TemplateHandler
      include Compilable

      ##
      # :singleton-method:
      # Specify trim mode for the ERB compiler. Defaults to '-'.
      # See ERb documentation for suitable values.
      cattr_accessor :erb_trim_mode
      self.erb_trim_mode = '-'

      self.default_format = Mime::HTML
      
      cattr_accessor :erubis_implementation
      self.erubis_implementation = Erubis

      def compile(template)
        magic = $1 if template.source =~ /\A(<%#.*coding[:=]\s*(\S+)\s*-?%>)/
        erb = "#{magic}<% __in_erb_template=true %>#{template.source}"
        self.class.erubis_implementation.new(erb, :trim=>(self.class.erb_trim_mode == "-")).src
      end
    end
{'fraction_non_alphanumeric': 0.1388695045359386, 'fraction_numerical': 0.0006978367062107466, 'mean_word_length': 2.728218465539662, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 9, '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': '5006403', 'n_tokens_mistral': 978, 'n_tokens_neox': 940, 'n_words': 191}