From 2f2e9beb6e40e6599d55ef43df220acd3991fe7f Mon Sep 17 00:00:00 2001 From: Ashley Willard Date: Thu, 12 Dec 2024 15:31:55 -0800 Subject: [PATCH] Add README template pathname We want to allow users to specify a README template other than the default template currently defined in `packs`. Users can specify an alternative path to this file in `packs.yml` or define `README_TEMPLATE.md` in the project root. --- lib/packs/specification/configuration.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/packs/specification/configuration.rb b/lib/packs/specification/configuration.rb index 046d9fe..a3b4b1e 100644 --- a/lib/packs/specification/configuration.rb +++ b/lib/packs/specification/configuration.rb @@ -10,15 +10,18 @@ class Configuration < T::Struct 'packs/*', 'packs/*/*' ], T::Array[String]) + DEFAULT_README_TEMPLATE_PATHNAME = T.let(Pathname.new('README_TEMPLATE.md'), Pathname) prop :pack_paths, T::Array[String] + prop :readme_template_pathname, Pathname sig { returns(Configuration) } def self.fetch config_hash = CONFIGURATION_PATHNAME.exist? ? YAML.load_file(CONFIGURATION_PATHNAME) : {} new( - pack_paths: pack_paths(config_hash) + pack_paths: pack_paths(config_hash), + readme_template_pathname: readme_template_pathname(config_hash) ) end @@ -31,6 +34,16 @@ def self.pack_paths(config_hash) Array(specified_pack_paths) end end + + sig { params(config_hash: T::Hash[T.untyped, T.untyped]).returns(Pathname) } + def self.readme_template_pathname(config_hash) + specified_readme_template_path = config_hash['readme_template_path'] + if specified_readme_template_path.nil? + DEFAULT_README_TEMPLATE_PATHNAME + else + Pathname.new(specified_readme_template_path) + end + end end end end