<commit_before>require 'sprockets/processor'

module Ngannotate
  class Processor < Sprockets::Processor
    def self.name
      'Ngannotate::Processor'
    end

    def prepare
      ngannotate_source = File.open(File.join(File.dirname(__FILE__), '../../vendor/ngannotate.js')).read
      @context = ExecJS.compile "window = {};" + ngannotate_source
    end

    def evaluate(context, locals)
      r = @context.call 'window.annotate', data, { add: true }
      r['src']
    end
  end
end<commit_msg>ISSUE#3: Allow passing options to ng-annotate - FIX: added NG_OPT env var<commit_after>require 'sprockets/processor'

module Ngannotate
  class Processor < Sprockets::Processor
    def self.name
      'Ngannotate::Processor'
    end

    def prepare
      ngannotate_source = File.open(File.join(File.dirname(__FILE__), '../../vendor/ngannotate.js')).read
      @context = ExecJS.compile "window = {};" + ngannotate_source
    end

    def evaluate(context, locals)
      opt = { add: true }.merge(parse_opt)
      r = @context.call 'window.annotate', data, opt
      r['src']
    end

    def parse_opt
      opt = {}
      opt_str = ENV['NG_OPT']
      if opt_str
        opt = Hash[opt_str.split(',').map { |e| e.split('=') }]
      end
      opt
    end
  end
end
{'fraction_non_alphanumeric': 0.13012618296529968, 'fraction_numerical': 0.0007886435331230284, 'mean_word_length': 2.7994011976047903, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4198445', 'n_tokens_mistral': 425, 'n_tokens_neox': 419, 'n_words': 94}