<commit_before>require "coffee_script"
require "source"
require "execjs"

module Eco
  module Source
    def self.path
      @path ||= ENV["ECO_SOURCE_PATH"] || bundled_path
    end

    def self.path=(path)
      @contents = @version = @context = nil
      @path = path
    end

    def self.contents
      @contents ||= File.read(path)
    end

    def self.combined_contents
      [CoffeeScript::Source.contents, contents].join(";\n")
    end

    def self.version
      @version ||= contents[/Eco Compiler v(.*?)\s/, 1]
    end

    def self.context
      @context ||= ExecJS.compile(combined_contents)
    end
  end

  class << self
    def version
      Source.version
    end

    def compile(template)
      template = template.read if template.respond_to?(:read)
      Source.context.call("eco.precompile", template)
    end

    def context_for(template)
      ExecJS.compile("var render = #{compile(template)}")
    end

    def render(template, locals = {})
      context_for(template).call("render", locals)
    end
  end
end<commit_msg>Strip empty lines and unnecessary line breaks in template output.<commit_after>require "coffee_script"
require "source"
require "execjs"

module Eco
  module Source
    def self.path
      @path ||= ENV["ECO_SOURCE_PATH"] || bundled_path
    end

    def self.path=(path)
      @contents = @version = @context = nil
      @path = path
    end

    def self.contents
      @contents ||= File.read(path)
    end

    def self.combined_contents
      [CoffeeScript::Source.contents, contents].join(";\n")
    end

    def self.version
      @version ||= contents[/Eco Compiler v(.*?)\s/, 1]
    end

    def self.context
      @context ||= ExecJS.compile(combined_contents)
    end
  end

  class << self
    def version
      Source.version
    end

    def compile(template)
      template = template.read if template.respond_to?(:read)
      Source.context.call("eco.precompile", template)
        # Contiamo improvement (we don't care about line breaks in generated html)
        .gsub(/__out\.push\('\s*\\n\s*'\);/, "")
        .gsub(/\s*\\n\s*/, "\n\s")
        .gsub(/\s+/, "\s")
        .gsub(/\\n/, "")
    end

    def context_for(template)
      ExecJS.compile("var render = #{compile(template)}")
    end

    def render(template, locals = {})
      context_for(template).call("render", locals)
    end
  end
end
{'fraction_non_alphanumeric': 0.13285533530156052, 'fraction_numerical': 0.0008435259384226065, 'mean_word_length': 2.5455904334828103, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6453829', 'n_tokens_mistral': 775, 'n_tokens_neox': 741, 'n_words': 181}