Skip to content

Commit

Permalink
Make README template customizable (#165)
Browse files Browse the repository at this point in the history
* Make README template customizable

Allows users to specify a README template other than the default template currently defined in `packs`.

* bump version

* update text in spec
  • Loading branch information
ashleywillard authored Dec 18, 2024
1 parent 856fc13 commit 332b8f5
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ GIT
PATH
remote: .
specs:
packs (0.0.45)
packs (0.1.0)
bigdecimal
code_ownership (>= 1.33.0)
packs-specification
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ pack_paths:
- gems/* # gems can be packs too!
```
To customize the README template, include a `README_TEMPLATE.md` file in the root of your project. If you want to use a custom path for your README template, you can specify it in the `packs.yml` file in the root of your project:
```yml
readme_template_path: my_folder/README_STUFF.md
```

# Ecosystem
The rest of the [rubyatscale](https://github.com/rubyatscale) ecosystem is intended to help make using packs and improving the boundaries between them more clear.

Expand Down
15 changes: 15 additions & 0 deletions lib/packs/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ module Packs
class Configuration
extend T::Sig

CONFIGURATION_PATHNAME = T.let(Pathname.new('packs.yml'), Pathname)
DEFAULT_README_TEMPLATE_PATHNAME = T.let(Pathname.new('README_TEMPLATE.md'), Pathname)

sig { params(enforce_dependencies: T::Boolean).void }
attr_writer :enforce_dependencies

Expand Down Expand Up @@ -45,6 +48,18 @@ def bust_cache!
def default_enforce_dependencies
true
end

sig { returns(Pathname) }
def readme_template_pathname
config_hash = CONFIGURATION_PATHNAME.exist? ? YAML.load_file(CONFIGURATION_PATHNAME) : {}

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

class << self
Expand Down
5 changes: 5 additions & 0 deletions lib/packs/user_event_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ def on_create_public_directory_todo(pack_name)

sig { params(pack_name: String).returns(String) }
def on_create_readme_todo(pack_name)
readme_template_pathname = Packs.config.readme_template_pathname
readme_template = readme_template_pathname.read if readme_template_pathname.exist?

return readme_template unless readme_template.nil?

<<~MSG
Welcome to `#{pack_name}`!
Expand Down
2 changes: 1 addition & 1 deletion packs.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = 'packs'
spec.version = '0.0.45'
spec.version = '0.1.0'
spec.authors = ['Gusto Engineers']
spec.email = ['[email protected]']

Expand Down
26 changes: 26 additions & 0 deletions spec/packs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,32 @@ def write_codeownership_config
expect(actual_readme_todo.exist?).to eq false
end
end

context 'when the app has a README template' do
it 'uses the template to create the README_TODO.md' do
write_file('README_TEMPLATE.md', 'This is the template')
Packs.create_pack!(pack_name: 'packs/organisms')
ParsePackwerk.bust_cache!
actual_readme_todo = ParsePackwerk.find('packs/organisms').directory.join('README_TODO.md')
expect(actual_readme_todo.read).to eq 'This is the template'
end

context 'and a custom path is specified for the README template' do
before do
write_file('packs.yml', <<~YML)
readme_template_path: my_folder/README_STUFF.md
YML
end

it 'uses the template to create the README_TODO.md' do
write_file('my_folder/README_STUFF.md', 'This is the custom template')
Packs.create_pack!(pack_name: 'packs/organisms')
ParsePackwerk.bust_cache!
actual_readme_todo = ParsePackwerk.find('packs/organisms').directory.join('README_TODO.md')
expect(actual_readme_todo.read).to eq 'This is the custom template'
end
end
end
end
end

Expand Down

0 comments on commit 332b8f5

Please sign in to comment.