lib/nanoc/base/repos/config_loader.rb in nanoc-4.9.1 vs lib/nanoc/base/repos/config_loader.rb in nanoc-4.9.2

- old
+ new

@@ -26,11 +26,16 @@ !config_filename_for_cwd.nil? end # @return [String] def self.config_filename_for_cwd - filenames = %w[nanoc.yaml config.yaml] + filenames = + if Nanoc::Feature.enabled?(Nanoc::Feature::TOML) + %w[nanoc.yaml config.yaml nanoc.toml] + else + %w[nanoc.yaml config.yaml] + end candidate = filenames.find { |f| File.file?(f) } candidate && File.expand_path(candidate) end def new_from_cwd @@ -39,18 +44,29 @@ raise NoConfigFileFoundError if filename.nil? # Read config = apply_parent_config( - Nanoc::Int::Configuration.new(hash: YAML.load_file(filename)), + Nanoc::Int::Configuration.new(hash: load_file(filename)), [filename], ).with_defaults # Load environment config.with_environment end + def load_file(filename) + case File.extname(filename) + when '.yaml' + YAML.load_file(filename) + when '.toml' + Tomlrb.load_file(filename) + else + raise Nanoc::Int::Errors::InternalInconsistency, 'Unhandled config file extension' + end + end + # @api private def apply_parent_config(config, processed_paths = []) parent_path = config[:parent_config_file] return config if parent_path.nil? @@ -64,10 +80,10 @@ if processed_paths.include?(parent_path) raise CyclicalConfigFileError.new(parent_path) end # Load - parent_config = Nanoc::Int::Configuration.new(hash: YAML.load_file(parent_path)) + parent_config = Nanoc::Int::Configuration.new(hash: load_file(parent_path)) full_parent_config = apply_parent_config(parent_config, processed_paths + [parent_path]) full_parent_config.merge(config.without(:parent_config_file)) end end end