<commit_before>module Rake::Pipeline::Web::Filters
  # A filter that converts handlebars templates to javascript
  # and stores them in a defined variable.
  #
  # @example
  #   !!!ruby
  #   Rake::Pipeline.build do
  #     input "app/assets", "**/*.handlebars"
  #     output "public"
  #
  #     # Compile each handlebars file to JS
  #     handlebars
  #   end
  class HandlebarsFilter < Rake::Pipeline::Filter

    attr_reader :options

    # @param [Hash] options
    #   options to pass to the output generator
    # @option options [Array] :target
    #   the variable to store templates in
    # @option options [Array] :compile_open
    #   the js to wrap template contents in
    # @option options [Array] :compile_close
    #   the js to wrap template contents in
    # @param [Proc] block a block to use as the Filter's
    #   {#output_name_generator}.
    def initialize(options={},&block)
      # Convert .handlebars file extensions to .js
      block ||= proc { |input| input.sub(/\.handlebars$/, '.js') }
      super(&block)
      @options = {
          :target =>'Ember.TEMPLATES',
          :compile_open => 'Ember.Handlebars.compile(',
          :compile_close => ');'
        }.merge(options)
    end

    def generate_output(inputs, output)

      inputs.each do |input|
        # The name of the template is the filename, sans extension
        name = File.basename(input.path, File.extname(input.path))

        # Read the file and escape it so it's a valid JS string
        source = input.read.to_json

        # Write out a JS file, saved to target, wrapped in compiler
        output.write "\n#{options[:target]}['#{name}']=#{options[:compile_open]}#{source}#{options[:compile_close]}\n"
      end
    end
  end
end<commit_msg>add external_dependencies and consolodate compile_open/compile_close options to wrapper_proc<commit_after>module Rake::Pipeline::Web::Filters
  # A filter that converts handlebars templates to javascript
  # and stores them in a defined variable.
  #
  # @example
  #   !!!ruby
  #   Rake::Pipeline.build do
  #     input "**/*.handlebars"
  #     output "public"
  #
  #     # Compile each handlebars file to JS
  #     handlebars
  #   end
  class HandlebarsFilter < Rake::Pipeline::Filter

    include Rake::Pipeline::Web::Filters::FilterWithDependencies

    # @return [Hash] a hash of options for generate_output
    attr_reader :options

    # @param [Hash] options
    #   options to pass to the output generator
    # @option options [Array] :target
    #   the variable to store templates in
    # @option options [Array] :compile_open
    #   the js to wrap template contents in
    # @option options [Array] :compile_close
    #   the js to wrap template contents in
    # @param [Proc] block a block to use as the Filter's
    #   {#output_name_generator}.
    def initialize(options={},&block)
      # Convert .handlebars file extensions to .js
      block ||= proc { |input| input.sub(/\.handlebars$/, '.js') }
      super(&block)
      @options = {
          :target =>'Ember.TEMPLATES',
          :wrapper_proc => proc { |source| "Ember.Handlebars.compile(#{source});" }
        }.merge(options)
    end

    def generate_output(inputs, output)

      inputs.each do |input|
        # The name of the template is the filename, sans extension
        name = File.basename(input.path, File.extname(input.path))

        # Read the file and escape it so it's a valid JS string
        source = input.read.to_json

        # Write out a JS file, saved to target, wrapped in compiler
        output.write "\n#{options[:target]}['#{name}']=#{options[:wrapper_proc].call(source)}\n"
      end
    end

    private 

    def external_dependencies
      [ 'json' ]
    end
  end
end
{'fraction_non_alphanumeric': 0.11108144192256342, 'fraction_numerical': 0.0, 'mean_word_length': 2.7422577422577423, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '5622610', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1089, 'n_words': 349}