<commit_before># Copyright 2010 The Googlyscript Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


class Googly
  
  # Templates render with an instance named goog in the context.
  
  class Goog
    
    def initialize(env, sources, render_stack)
      @sources = sources
      @env = env
      @render_stack = render_stack
      @dependencies = []
    end
    
    # You can add additional files to have their mtimes scanned.
    # Perhaps you want to use a .yml file to define build options.
    # Googly::Template calls this for every render so you don't need
    # to define compiler arguments in the same template that calls compile.
    def add_dependency(dependency)
      dependency = File.expand_path dependency, @render_stack.last
      @dependencies << dependency unless @dependencies.include? dependency
    end

    # Run a compiler job.  Accepts every argument that compiler.jar supports.
    # Accepts new `--ns namespace` option which literally expands into
    # `--js filename` arguments in place to satisfy the namespace.
    # If you specify a --js_output_file then the compiler will check File.mtime
    # on every source file plus all the templates and skip the compilation
    # if the js_output_file is newest.
    # Paths are relative to the template calling #compile.
    # @example myapp.js.erb
    #   <% @response = compile(%w{
    #     --js_output_file ../public/myapp.js
    #     --ns myapp.HelloWorld
    #     --compilation_level ADVANCED_OPTIMIZATIONS
    #   }).to_response %>
    # @param [Array<String>] args
    # @return [Compilation]
    def compile(args)
      args = Array.new args
      files = []
      files_index = 0
      args_index = 0
      while args_index < args.length
        option, value = args[args_index, 2]
        if option == '--ns'
          files_for(value, files)
          replacement = []
          while files_index < files.length
            replacement.push '--js'
            replacement.push files[files_index]
            files_index = files_index + 1
          end
          args[args_index, 2] = replacement
        end
        args_index = args_index + 2
      end
      Compilation.new(args,
                      File.dirname(@render_stack.last),
                      @dependencies,
                      @env)
    end

    # Calculate files needed to satisfy a namespace.
    # This will be especially useful for module generation.
    # If you pass the filenames returned from last run,
    # additional files (if any) will be appended to satisfy
    # the new namespace.
    # @example cal_file_list.erb
    #  <%= goog.files_for %w{myapp.Calendar} %>
    # @return (Array)
    def files_for(namespace, filenames=nil)
      @sources.files_for(@env, namespace, filenames)<commit_msg>Fix for multiple namespaces<commit_after># Copyright 2010 The Googlyscript Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


class Googly
  
  # Templates render with an instance named goog in the context.
  
  class Goog
    
    def initialize(env, sources, render_stack)
      @sources = sources
      @env = env
      @render_stack = render_stack
      @dependencies = []
    end
    
    # You can add additional files to have their mtimes scanned.
    # Perhaps you want to use a .yml file to define build options.
    # Googly::Template calls this for every render so you don't need
    # to define compiler arguments in the same template that calls compile.
    def add_dependency(dependency)
      dependency = File.expand_path dependency, @render_stack.last
      @dependencies << dependency unless @dependencies.include? dependency
    end

    # Run a compiler job.  Accepts every argument that compiler.jar supports.
    # Accepts new `--ns namespace` option which literally expands into
    # `--js filename` arguments in place to satisfy the namespace.
    # If you specify a --js_output_file then the compiler will check File.mtime
    # on every source file plus all the templates and skip the compilation
    # if the js_output_file is newest.
    # Paths are relative to the template calling #compile.
    # @example myapp.js.erb
    #   <% @response = compile(%w{
    #     --js_output_file ../public/myapp.js
    #     --ns myapp.HelloWorld
    #     --compilation_level ADVANCED_OPTIMIZATIONS
    #   }).to_response %>
    # @param [Array<String>] args
    # @return [Compilation]
    def compile(args)
      args = Array.new args
      files = []
      files_index = 0
      args_index = 0
      while args_index < args.length
        option, value = args[args_index, 2]
        if option == '--ns'
          files_for(value, files)
          replacement = []
          while files_index < files.length
            replacement.push '--js'
            replacement.push files[files_index]
            files_index = files_index + 1
          end
          args[args_index, 2] = replacement
        else
          args_index = args_index + 2
        end
      end
      Compilation.new(args,
                      File.dirname(@render_stack.last),
                      @dependencies,
                      @env)
    end

    # Calculate files needed to satisfy a namespace.
    # This will be especially useful for module generation.
    # If you pass the filenames returned from last run,
    # additional files (if any) will be appended to satisfy
    # the new namespace.
    # @example cal_file_list.erb
    #  <%= goog.files_for %w{myapp.Calendar} %>
    # @return (Array)
    def files_for(namespace, filenames=nil)
      @sources.files_for(@env, namespace, filenames)
{'fraction_non_alphanumeric': 0.07517881600973976, 'fraction_numerical': 0.004261147466139096, 'mean_word_length': 2.5276435856146002, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3468510', 'n_tokens_mistral': 1820, 'n_tokens_neox': 1742, 'n_words': 683}