<commit_before>$LOAD_PATH.push File.expand_path(File.dirname(__FILE__))

# @Jammit@ is the central namespace for all Jammit classes, and provides access
# to all of the configuration options.
module Jammit

  VERSION                       = "0.7.1"

  ROOT                          = File.expand_path(File.dirname(__FILE__) + '/..')

  ASSET_ROOT                    = File.expand_path((defined?(Rails) && Rails.root.to_s.length > 0) ? Rails.root : ENV['RAILS_ROOT'] || ".") unless defined?(ASSET_ROOT)

  DEFAULT_PUBLIC_ROOT           = (defined?(Rails) && Rails.public_path.to_s.length > 0) ? Rails.public_path.to_s : File.join(ASSET_ROOT, 'public') unless defined?(PUBLIC_ROOT)

  DEFAULT_CONFIG_PATH           = File.join(ASSET_ROOT, 'config', 'assets.yml')

  DEFAULT_PACKAGE_PATH          = "assets"

  DEFAULT_JST_SCRIPT            = File.join(ROOT, 'lib/jammit/jst.js')

  DEFAULT_JST_COMPILER          = "template"

  DEFAULT_JST_NAMESPACE         = "window.JST"

  JAVASCRIPT_COMPRESSORS        = [:jsmin, :yui, :closure, :uglifier]

  DEFAULT_JAVASCRIPT_COMPRESSOR = :jsmin

  CSS_COMPRESSORS               = [:cssmin, :yui, :sass]

  DEFAULT_CSS_COMPRESSOR        = :cssmin

  # Extension matchers for JavaScript and JST, which need to be disambiguated.
  JS_EXTENSION          = /\.js\Z/
  DEFAULT_JST_EXTENSION = "jst"

  # Jammit raises a @PackageNotFound@ exception when a non-existent package is
  # requested by a browser -- rendering a 404.
  class PackageNotFound < NameError; end

  # Jammit raises a MissingConfiguration exception when you try to load the
  # configuration of an assets.yml file that doesn't exist, or are missing
  # a piece of required configuration.
  class MissingConfiguration < NameError; end

  # Jammit raises an OutputNotWritable exception if the output directory for
  # cached packages is locked.
  class OutputNotWritable < StandardError; end

  # Jammit raises a DeprecationError if you try to use an outdated feature.
  class DeprecationError < StandardError; end

  class << self
    attr_reader   :configuration, :template_function, :template_namespace,
                  :embed_assets, :package_assets, :compress_assets, :gzip_assets,
                  :package_path, :mhtml_enabled, :include_jst_script, :config_path,
                  :javascript_compressor, :compressor_options, :css_compressor,
                  :css_compressor_options, :template_extension,
                  :template_extension_matcher, :allow_debugging,
                  :rewrite_relative_paths, :public_root
    attr_accessor :javascript_compressors, :css_compressors
  end

  # The minimal required configuration.
  @configuration  = {}
  @public_root    = DEFAULT_PUBLIC_ROOT
  @package_path   = DEFAULT_PACKAGE_PATH

  @javascript_compressors = JAVASCRIPT_COMPRESSORS
  @css_compressors        = CSS_COMPRESSORS

  # Load the complete asset configuration from the specified @config_path@.
  # If we're loading softly, don't let missing configuration error out.
  def self.load_configuration(config_path, soft=false)
    exists = config_path && File.exists?(config_path)
    return false if soft && !exists
    raise MissingConfiguration, "could not find the \"#{config_path}\" configuration file" unless exists
    conf = YAML.load(ERB.new(File.read(config_path)).result)

    # Optionally overwrite configuration based on the environment.
    rails_env = (defined?(Rails) ? ::Rails.env : ENV['RAILS_ENV'] || "development")
    conf.merge! conf.delete rails_env if conf.has_key? rails_env

    @config_path            = config_path
    @configuration          = symbolize_keys(conf)

    @package_path           = conf[:package_path] || DEFAULT_PACKAGE_PATH

    # These default false
    @embed_assets           = conf[:embed_assets] || conf[:embed_images]
    @mhtml_enabled          = @embed_assets && @embed_assets != "datauri"

    # These default true, as `!(nil == false) # => true`
    @compress_assets        = !(conf[:compress_assets] == false)
    @rewrite_relative_paths = !(conf[:rewrite_relative_paths] == false)
    @gzip_assets            = !(conf[:gzip_assets] == false)
    @allow_debugging        = !(conf[:allow_debugging] == false)

    @compressor_options     = symbolize_keys(conf[:compressor_options] || {})
    @css_compressor_options = symbolize_keys(conf[:css_compressor_options] || {})
    set_javascript_compressor(conf[:javascript_compressor])
    set_css_compressor(conf[:css_compressor])
    set_package_assets(conf[:package_assets])
    set_template_function(conf[:template_function])
    set_template_namespace(conf[:template_namespace])
    set_template_extension(conf[:template_extension])
    set_public_root(conf[:public_root]) if conf[:public_root]
    symbolize_keys(conf[:stylesheets]) if conf[:stylesheets]
    symbolize_keys(conf[:javascripts]) if conf[:javascripts]
    check_for_deprecations
    self<commit_msg>Load configuration as a hash as well as a file path<commit_after>$LOAD_PATH.push File.expand_path(File.dirname(__FILE__))

# @Jammit@ is the central namespace for all Jammit classes, and provides access
# to all of the configuration options.
module Jammit

  VERSION                       = "0.7.1"

  ROOT                          = File.expand_path(File.dirname(__FILE__) + '/..')

  ASSET_ROOT                    = File.expand_path((defined?(Rails) && Rails.root.to_s.length > 0) ? Rails.root : ENV['RAILS_ROOT'] || ".") unless defined?(ASSET_ROOT)

  DEFAULT_PUBLIC_ROOT           = (defined?(Rails) && Rails.public_path.to_s.length > 0) ? Rails.public_path.to_s : File.join(ASSET_ROOT, 'public') unless defined?(PUBLIC_ROOT)

  DEFAULT_CONFIG_PATH           = File.join(ASSET_ROOT, 'config', 'assets.yml')

  DEFAULT_PACKAGE_PATH          = "assets"

  DEFAULT_JST_SCRIPT            = File.join(ROOT, 'lib/jammit/jst.js')

  DEFAULT_JST_COMPILER          = "template"

  DEFAULT_JST_NAMESPACE         = "window.JST"

  JAVASCRIPT_COMPRESSORS        = [:jsmin, :yui, :closure, :uglifier]

  DEFAULT_JAVASCRIPT_COMPRESSOR = :jsmin

  CSS_COMPRESSORS               = [:cssmin, :yui, :sass]

  DEFAULT_CSS_COMPRESSOR        = :cssmin

  # Extension matchers for JavaScript and JST, which need to be disambiguated.
  JS_EXTENSION          = /\.js\Z/
  DEFAULT_JST_EXTENSION = "jst"

  # Jammit raises a @PackageNotFound@ exception when a non-existent package is
  # requested by a browser -- rendering a 404.
  class PackageNotFound < NameError; end

  # Jammit raises a MissingConfiguration exception when you try to load the
  # configuration of an assets.yml file that doesn't exist, or are missing
  # a piece of required configuration.
  class MissingConfiguration < NameError; end

  # Jammit raises an OutputNotWritable exception if the output directory for
  # cached packages is locked.
  class OutputNotWritable < StandardError; end

  # Jammit raises a DeprecationError if you try to use an outdated feature.
  class DeprecationError < StandardError; end

  class << self
    attr_reader   :configuration, :template_function, :template_namespace,
                  :embed_assets, :package_assets, :compress_assets, :gzip_assets,
                  :package_path, :mhtml_enabled, :include_jst_script, :config_path,
                  :javascript_compressor, :compressor_options, :css_compressor,
                  :css_compressor_options, :template_extension,
                  :template_extension_matcher, :allow_debugging,
                  :rewrite_relative_paths, :public_root
    attr_accessor :javascript_compressors, :css_compressors
  end

  # The minimal required configuration.
  @configuration  = {}
  @public_root    = DEFAULT_PUBLIC_ROOT
  @package_path   = DEFAULT_PACKAGE_PATH

  @javascript_compressors = JAVASCRIPT_COMPRESSORS
  @css_compressors        = CSS_COMPRESSORS

  # Load the complete asset configuration from the specified @config_path@.
  # If we're loading softly, don't let missing configuration error out.
  def self.load_configuration(config, soft=false)
    conf = if config.kind_of? Hash
      config
    else
      exists = config && File.exists?(config)
      return false if soft && !exists
      raise MissingConfiguration, "could not find the \"#{config}\" configuration file" unless exists
      YAML.load(ERB.new(File.read(config)).result)
    end

    # Optionally overwrite configuration based on the environment.
    rails_env = (defined?(Rails) ? ::Rails.env : ENV['RAILS_ENV'] || "development")
    conf.merge! conf.delete rails_env if conf.has_key? rails_env

    @config_path            = config
    @configuration          = symbolize_keys(conf)

    @package_path           = conf[:package_path] || DEFAULT_PACKAGE_PATH

    # These default false
    @embed_assets           = conf[:embed_assets] || conf[:embed_images]
    @mhtml_enabled          = @embed_assets && @embed_assets != "datauri"

    # These default true, as `!(nil == false) # => true`
    @compress_assets        = !(conf[:compress_assets] == false)
    @rewrite_relative_paths = !(conf[:rewrite_relative_paths] == false)
    @gzip_assets            = !(conf[:gzip_assets] == false)
    @allow_debugging        = !(conf[:allow_debugging] == false)

    @compressor_options     = symbolize_keys(conf[:compressor_options] || {})
    @css_compressor_options = symbolize_keys(conf[:css_compressor_options] || {})
    set_javascript_compressor(conf[:javascript_compressor])
    set_css_compressor(conf[:css_compressor])
    set_package_assets(conf[:package_assets])
    set_template_function(conf[:template_function])
    set_template_namespace(conf[:template_namespace])
    set_template_extension(conf[:template_extension])
    set_public_root(conf[:public_root]) if conf[:public_root]
    symbolize_keys(conf[:stylesheets]) if conf[:stylesheets]
    symbolize_keys(conf[:javascripts]) if conf[:javascripts]
    check_for_deprecations
    self
{'fraction_non_alphanumeric': 0.09638798701298701, 'fraction_numerical': 0.0016233766233766235, 'mean_word_length': 3.4845313921747043, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, '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': '5542762', 'n_tokens_mistral': 3026, 'n_tokens_neox': 2895, 'n_words': 671}