<commit_before>require 'rubygems'
require 'execjs'
require 'json'
require 'yaml'
require 'erb'

module Isotope
  APP_ROOT = File.expand_path((defined?(Rails) && Rails.root.to_s.length > 0) ? Rails.root : ".") unless defined?(APP_ROOT)
  DEFAULT_CONFIG_PATH = File.join(APP_ROOT, 'config', 'isotope.yml')
  DEFAULT_CONFIG = {}
  PUBLIC_DIR_PREFIX = %r[^/?public]

  @@_template_cache = {}
  
  @@cache_templates = true
  
  def self.cache_templates
    !dev_env && @@cache_templates
  end

  def self.cache_templates=(value)
    if !value
      @@_template_cache.clear
    end
    
    @@cache_templates = value
  end
  
  def self.reset_cache
    @@_template_cache.clear
  end
  
  def self.render_partial(view_file, options = {})
    if options[:collection] && options[:collection].kind_of?(Enumerable)
      return render_partial_collection(view_file, options)
    end
    
    isotope_file_path = File.join(File.dirname(__FILE__), "isotope.js")
    
    view_file_content = template_file_content(view_file)

    context = ExecJS.compile(included_scripts_source + " " + IO.read(isotope_file_path))
    script = "Isotope(#{view_file_content.to_json}, #{options[:locals].to_json})"
    output = context.eval(script)

    output
  end
  
  def self.render_partial_collection(view_file, options = {})
    s = []
    
    options.delete(:collection).each { |item|
      item_options = options.dup
      item_options[:locals] ||= {}
      item_options[:locals][options[:local_name] || :item] = item

      s << render_partial(view_file, item_options)
    }<commit_msg>Handle the case where there are no included scripts<commit_after>require 'rubygems'
require 'execjs'
require 'json'
require 'yaml'
require 'erb'

module Isotope
  APP_ROOT = File.expand_path((defined?(Rails) && Rails.root.to_s.length > 0) ? Rails.root : ".") unless defined?(APP_ROOT)
  DEFAULT_CONFIG_PATH = File.join(APP_ROOT, 'config', 'isotope.yml')
  DEFAULT_CONFIG = {}
  PUBLIC_DIR_PREFIX = %r[^/?public]

  @@_template_cache = {}
  
  @@cache_templates = true
  
  def self.cache_templates
    !dev_env && @@cache_templates
  end

  def self.cache_templates=(value)
    if !value
      @@_template_cache.clear
    end
    
    @@cache_templates = value
  end
  
  def self.reset_cache
    @@_template_cache.clear
  end
  
  def self.render_partial(view_file, options = {})
    if options[:collection] && options[:collection].kind_of?(Enumerable)
      return render_partial_collection(view_file, options)
    end
    
    isotope_file_path = File.join(File.dirname(__FILE__), "isotope.js")
    
    view_file_content = template_file_content(view_file)
    
    initial_script = included_scripts_source || ""
    initial_script += IO.read(isotope_file_path)

    context = ExecJS.compile(initial_script)
    script = "Isotope(#{view_file_content.to_json}, #{options[:locals].to_json})"
    output = context.eval(script)

    output
  end
  
  def self.render_partial_collection(view_file, options = {})
    s = []
    
    options.delete(:collection).each { |item|
      item_options = options.dup
      item_options[:locals] ||= {}
      item_options[:locals][options[:local_name] || :item] = item

      s << render_partial(view_file, item_options)
    }
{'fraction_non_alphanumeric': 0.12550356368143786, 'fraction_numerical': 0.0006197706848466068, 'mean_word_length': 3.7964338781575035, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '4973924', 'n_tokens_mistral': 1110, 'n_tokens_neox': 1069, 'n_words': 185}