class Hyde::Configuration

Constants

DEFAULTS

Public Instance Methods

backwards_compatibilize() click to toggle source
# File lib/hyde/configuration.rb, line 123
def backwards_compatibilize
  clone
end
config_files(override) click to toggle source

Public: Generate list of configuration files from the override

override - the command-line options hash

Returns an Array of config files

# File lib/hyde/configuration.rb, line 65
def config_files(override)
  # Get configuration from <source>/_config.yml or <source>/<config_file>
  config_files = override.delete('config')
  if config_files.to_s.empty?
    config_files = File.join(source(override), "_config.yml")
    @default_config_file = true
  end
  config_files = [config_files] unless config_files.is_a? Array
  config_files
end
fix_common_issues() click to toggle source
# File lib/hyde/configuration.rb, line 119
def fix_common_issues
  clone
end
read_config_file(file) click to toggle source

Public: Read configuration and return merged Hash

file - the path to the YAML file to be read in

Returns this configuration, overridden by the values in the file

# File lib/hyde/configuration.rb, line 81
def read_config_file(file)
  next_config = safe_load_file(file)
  raise ArgumentError.new("Configuration file: (INVALID) #{file}".yellow) unless next_config.is_a?(Hash)
  Hyde.logger.info "Configuration file:", file
  next_config
rescue SystemCallError
  if @default_config_file
    Hyde.logger.warn "Configuration file:", "none"
    {}
  else
    Hyde.logger.error "Fatal:", "The configuration file '#{file}' could not be found."
    raise LoadError, "The Configuration file '#{file}' could not be found."
  end
end
read_config_files(files) click to toggle source

Public: Read in a list of configuration files and merge with this hash

files - the list of configuration file paths

Returns the full configuration, with the defaults overridden by the values in the configuration files

# File lib/hyde/configuration.rb, line 102
def read_config_files(files)
  configuration = clone

  begin
    files.each do |config_file|
      new_config = read_config_file(config_file)
      configuration = configuration.deep_merge(new_config)
    end
  rescue ArgumentError => err
    Hyde.logger.warn "WARNING:", "Error reading configuration. " +
                 "Using defaults (and options)."
    $stderr.puts "#{err}"
  end

  configuration.fix_common_issues.backwards_compatibilize
end
safe_load_file(filename) click to toggle source
# File lib/hyde/configuration.rb, line 49
def safe_load_file(filename)
  case File.extname(filename)
  when '.toml'
    TOML.load_file(filename)
  when /\.y(a)?ml/
    YAML.safe_load_file(filename)
  else
    raise ArgumentError, "No parser for '#{filename}' is available. Use a .toml or .y(a)ml file instead."
  end
end
source(override) click to toggle source

Public: Directory of the Jekyll source folder

override - the command-line options hash

Returns the path to the Jekyll source directory

# File lib/hyde/configuration.rb, line 45
def source(override)
  override['source'] || self['source'] || DEFAULTS['source']
end
stringify_keys() click to toggle source

Public: Turn all keys into string

Return a copy of the hash where all its keys are strings

# File lib/hyde/configuration.rb, line 36
def stringify_keys
  reduce({}) { |hsh,(k,v)| hsh.merge(k.to_s => v) }
end