<commit_before>require 'action_view'
require 'action_view/mustache'
require 'mustache'

module ActionView
  class Mustache < ::Mustache
    # Public: Compiles tokens from Mustache::Parser into evaluatable
    # Ruby code.
    #
    # The code generate targets Rails output buffer and must be
    # evaluated inside an ActionView::Base instance.
    #
    # See Mustache::Generator for more info.
    class Generator
      # Public: Convert tokens to plain old Ruby.
      #
      # exp - Array of tokens produced by Mustache::Parser
      #
      # Returns String of compiled Ruby code.
      def compile(exp)
        src = ""
        src << "@output_buffer = output_buffer || ActionView::OutputBuffer.new;\n"
        src << compile!(exp)
        src << "@output_buffer.to_s;"
        src
      end

      # Internal: Recursively compile token expression.
      #
      # exp - Token Array structure
      #
      # Returns String.
      def compile!(exp)
        case exp.first
        when :multi
          exp[1..-1].map { |e| compile!(e) }.join
        when :static
          str(exp[1])
        when :mustache
          send("on_#{exp[1]}", *exp[2..-1])
        else
          raise "Unhandled exp: #{exp.first}"
        end
      end

      # Internal: Compile section.
      #
      # name    - String of section name
      # content - Array of section content tokens
      #
      # Returns String.
      def on_section(name, content, _, _)
        code = compile!(content)

        <<-RUBY
        if v = #{compile!(name)}
          if v == true
            #{code}
          elsif v.is_a?(Proc)
            @output_buffer.concat(v.call {
              capture {
                #{code}
              }
            }.to_s)
          else
            v = [v] unless v.is_a?(Array) || defined?(Enumerator) && v.is_a?(Enumerator)
            for h in v
              ctx.push(h);
              #{code}
              ctx.pop;
            end
          end
        end
        RUBY
      end

      # Internal: Compile inverted section.
      #
      # name    - String of section name
      # content - Array of section content tokens
      #
      # Returns String.
      def on_inverted_section(name, content, _, _)
        code = compile!(content)

        <<-RUBY
        v = #{compile!(name)}
        if v.nil? || v == false || v.respond_to?(:empty?) && v.empty?
          #{code}
        end
        RUBY
      end

      # Internal: Compile partial render call.
      #
      # name        - String of partial name
      # indentation - String of indentation level
      #
      # Returns String.<commit_msg>Old ruby doesn't like duplicate arg names<commit_after>require 'action_view'
require 'action_view/mustache'
require 'mustache'

module ActionView
  class Mustache < ::Mustache
    # Public: Compiles tokens from Mustache::Parser into evaluatable
    # Ruby code.
    #
    # The code generate targets Rails output buffer and must be
    # evaluated inside an ActionView::Base instance.
    #
    # See Mustache::Generator for more info.
    class Generator
      # Public: Convert tokens to plain old Ruby.
      #
      # exp - Array of tokens produced by Mustache::Parser
      #
      # Returns String of compiled Ruby code.
      def compile(exp)
        src = ""
        src << "@output_buffer = output_buffer || ActionView::OutputBuffer.new;\n"
        src << compile!(exp)
        src << "@output_buffer.to_s;"
        src
      end

      # Internal: Recursively compile token expression.
      #
      # exp - Token Array structure
      #
      # Returns String.
      def compile!(exp)
        case exp.first
        when :multi
          exp[1..-1].map { |e| compile!(e) }.join
        when :static
          str(exp[1])
        when :mustache
          send("on_#{exp[1]}", *exp[2..-1])
        else
          raise "Unhandled exp: #{exp.first}"
        end
      end

      # Internal: Compile section.
      #
      # name    - String of section name
      # content - Array of section content tokens
      #
      # Returns String.
      def on_section(name, content, raw, delims)
        code = compile!(content)

        <<-RUBY
        if v = #{compile!(name)}
          if v == true
            #{code}
          elsif v.is_a?(Proc)
            @output_buffer.concat(v.call {
              capture {
                #{code}
              }
            }.to_s)
          else
            v = [v] unless v.is_a?(Array) || defined?(Enumerator) && v.is_a?(Enumerator)
            for h in v
              ctx.push(h);
              #{code}
              ctx.pop;
            end
          end
        end
        RUBY
      end

      # Internal: Compile inverted section.
      #
      # name    - String of section name
      # content - Array of section content tokens
      #
      # Returns String.
      def on_inverted_section(name, content, raw, delims)
        code = compile!(content)

        <<-RUBY
        v = #{compile!(name)}
        if v.nil? || v == false || v.respond_to?(:empty?) && v.empty?
          #{code}
        end
        RUBY
      end

      # Internal: Compile partial render call.
      #
      # name        - String of partial name
      # indentation - String of indentation level
      #
      # Returns String.
{'fraction_non_alphanumeric': 0.10204468004543733, 'fraction_numerical': 0.002271866717152594, 'mean_word_length': 1.5608337372758119, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 3, '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': '958843', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1488, 'n_words': 441}