<commit_before>require 'gemoji'

module Middleman
  module Gemoji
    class Converter
      attr_reader :app, :options, :base_path

      def initialize(app, options)
        if !app.is_a?(Middleman::Application)
          raise "app is not Middleman::Application"
        end

        @app = app
        @options = options
        set_base_path
      end

      def convert(content)
        return content if content.blank?

        if has_body?(content)
          emojify_only_body(content)
        else
          emojify(content)
        end
      end

      def emojify(content)
        content.gsub(/:([\w+-]+):/) do |match|
          emoji = Emoji.find_by_alias($1)
          if emoji
            image = []
            image << %(alt="#{$1}")
            image << src(emoji.image_filename)
            image << size if size
            image << style if style

            %(<img class="gemoji" #{image.join(' ').strip} />)
          else
            match
          end
        end
      end

      # emojify only in the body tag
      def emojify_inner_body(content)
        pattern = /<body>(.+?)<\/body>/m
        content.gsub(pattern) do |html|
          emojify(html).gsub(pattern, '\1')
        end
      end

      def has_body?(content)
        !(/<body>.+?<\/body>/m =~ content.to_str).nil?
      end

      def src(path)
        %(src="#{File.join(@base_path, path)}")
      end

      def size
        %(width="#{@options[:size]}" height="#{@options[:size]}") if @options[:size]
      end

      def style
        %(style="#{@options[:style]}") if @options[:style]
      end
<commit_msg>fixed dropped test<commit_after>require 'gemoji'

module Middleman
  module Gemoji
    class Converter
      attr_reader :app, :options, :base_path

      def initialize(app, options)
        if !app.is_a?(Middleman::Application)
          raise "app is not Middleman::Application"
        end

        @app = app
        @options = options
        set_base_path
      end

      def convert(content)
        return content if content.blank?

        if has_body?(content)
          emojify_inner_body(content)
        else
          emojify(content)
        end
      end

      def emojify(content)
        content.to_str.gsub(/:([\w+-]+):/) do |match|
          emoji = Emoji.find_by_alias($1)
          if emoji
            image = []
            image << %(alt="#{$1}")
            image << src(emoji.image_filename)
            image << size if size
            image << style if style

            %(<img class="gemoji" #{image.join(' ').strip} />)
          else
            match
          end
        end
      end

      # emojify only in the body tag
      def emojify_inner_body(content)
        pattern = /<body>(.+?)<\/body>/m
        content.to_str.gsub(pattern) do |html|
          emojify(html).gsub(pattern, '\1')
        end
      end

      def has_body?(content)
        !(/<body>.+?<\/body>/m =~ content.to_str).nil?
      end

      def src(path)
        %(src="#{File.join(@base_path, path)}")
      end

      def size
        %(width="#{@options[:size]}" height="#{@options[:size]}") if @options[:size]
      end

      def style
        %(style="#{@options[:style]}") if @options[:style]
      end

{'fraction_non_alphanumeric': 0.13551980198019803, 'fraction_numerical': 0.0018564356435643563, 'mean_word_length': 1.737510584250635, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 13, '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': '4419722', 'n_tokens_mistral': 1011, 'n_tokens_neox': 992, 'n_words': 228}