<commit_before>require "json"

module Temple
  module CoffeeScript
    class Generator < Temple::Generator
      define_options :indent => 0

      def call(exp)
        @indent = options[:indent]
        compile [:multi,
                 [:code, "#{buffer} = []"],
                 exp,
                 [:code, "#{buffer}.join('')"]]
      end

      def on_multi(*exp)
        exp.map {|e| compile(e) }.join("\n")
      end

      def on_static(text)
        concat(JSON.generate(text, :quirks_mode => true))
      end

      def on_dynamic(code)
        concat(code)
      end

      def on_code(code)
        indent(code)
      end

      def on_indent(exp)
        @indent += 1
        compile(exp)
      ensure
        @indent -= 1
      end

      def on_capture(name, exp)
        self.class.new(:buffer => name, :indent => @indent).call(exp)
      end

      def concat(str)
        indent("#{buffer}.push(#{str})")
      end

      def indent(str, indent = @indent)
        "  " * indent + str
      end
    end
  end
end<commit_msg>Replace array buffer with string buffer<commit_after>require "json"

module Temple
  module CoffeeScript
    class Generator < Temple::Generator
      define_options :indent => 0

      def call(exp)
        @indent = options[:indent]
        compile [:multi, [:code, "#{buffer} = '';"], exp]
      end

      def on_multi(*exp)
        exp.map {|e| compile(e) }.join("\n")
      end

      def on_static(text)
        concat(JSON.generate(text, :quirks_mode => true))
      end

      def on_dynamic(code)
        concat(code)
      end

      def on_code(code)
        indent(code)
      end

      def on_indent(exp)
        @indent += 1
        compile(exp)
      ensure
        @indent -= 1
      end

      def on_capture(name, exp)
        self.class.new(:buffer => name, :indent => @indent).call(exp)
      end

      def concat(str)
        indent "#{buffer} += #{str};"
      end

      def indent(str, indent = @indent)
        "  " * indent + str
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.1270935960591133, 'fraction_numerical': 0.002955665024630542, 'mean_word_length': 1.7670299727520435, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '510626', 'n_tokens_mistral': 652, 'n_tokens_neox': 623, 'n_words': 156}