<commit_before>require 'redcloth'
begin
  require 'rdiscount'
  ::BlueCloth = ::RDiscount unless defined?(::BlueCloth)
rescue LoadError
  require 'bluecloth'
  warn "Using bluecloth for Markdown rendering. Install rdiscount for better performance."
end

module ActionView
  module TemplateHandlers
    class TextileTemplate < TemplateHandler
      include Compilable

      cattr_accessor :erb_trim_mode
      self.erb_trim_mode = '-'

      def compile(template)
        %{
          interpolated = ::ERB.new(template.source, nil, "#{erb_trim_mode}").result(binding)
          interpolated.sub!(/\A#coding:.*\n/, '') if RUBY_VERSION >= '1.9'
          ::RedCloth.new(interpolated).to_html
        }
      end
    end

    class MarkdownTemplate < TemplateHandler
      include Compilable

      cattr_accessor :erb_trim_mode
      self.erb_trim_mode = '-'

      def compile(template)
        %{
          interpolated = ::ERB.new(template.source, nil, "#{erb_trim_mode}").result(binding)
          interpolated.sub!(/\A#coding:.*\n/, '') if RUBY_VERSION >= '1.9'
          ::BlueCloth.new(interpolated).to_html
        }
      end
    end
  end
end<commit_msg>Extracting commonalities.<commit_after>require 'redcloth'
begin
  require 'rdiscount'
  ::BlueCloth = ::RDiscount unless defined?(::BlueCloth)
rescue LoadError
  require 'bluecloth'
  warn "Using bluecloth for Markdown rendering. Install rdiscount for better performance."
end

module ActionView
  module TemplateHandlers
    module RedClothCompiler
      def compile_with_renderer(klass, template)
        %{
          interpolated = ::ERB.new(template.source, nil, "#{erb_trim_mode}").result(binding)
          interpolated.sub!(/\A#coding:.*\n/, '') if RUBY_VERSION >= '1.9'
          ::#{klass}.new(interpolated).to_html
        }
      end
    end

    class TextileTemplate < TemplateHandler
      include Compilable
      include RedClothCompiler

      cattr_accessor :erb_trim_mode
      self.erb_trim_mode = '-'

      def compile(template)
        compile_with_renderer(RedCloth, template)
      end
    end

    class MarkdownTemplate < TemplateHandler
      include Compilable
      include RedClothCompiler

      cattr_accessor :erb_trim_mode
      self.erb_trim_mode = '-'

      def compile(template)
        compile_with_renderer(BlueCloth, template)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09881255301102629, 'fraction_numerical': 0.002544529262086514, 'mean_word_length': 2.899173553719008, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 6, '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': '1274202', 'n_tokens_mistral': 751, 'n_tokens_neox': 734, 'n_words': 152}