Skip to content

Commit 332b8f5

Browse files
Make README template customizable (#165)
* 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
1 parent 856fc13 commit 332b8f5

File tree

6 files changed

+53
-2
lines changed

6 files changed

+53
-2
lines changed

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ GIT
1717
PATH
1818
remote: .
1919
specs:
20-
packs (0.0.45)
20+
packs (0.1.0)
2121
bigdecimal
2222
code_ownership (>= 1.33.0)
2323
packs-specification

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ pack_paths:
1515
- gems/* # gems can be packs too!
1616
```
1717
18+
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:
19+
```yml
20+
readme_template_path: my_folder/README_STUFF.md
21+
```
22+
1823
# Ecosystem
1924
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.
2025

lib/packs/configuration.rb

+15
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ module Packs
77
class Configuration
88
extend T::Sig
99

10+
CONFIGURATION_PATHNAME = T.let(Pathname.new('packs.yml'), Pathname)
11+
DEFAULT_README_TEMPLATE_PATHNAME = T.let(Pathname.new('README_TEMPLATE.md'), Pathname)
12+
1013
sig { params(enforce_dependencies: T::Boolean).void }
1114
attr_writer :enforce_dependencies
1215

@@ -45,6 +48,18 @@ def bust_cache!
4548
def default_enforce_dependencies
4649
true
4750
end
51+
52+
sig { returns(Pathname) }
53+
def readme_template_pathname
54+
config_hash = CONFIGURATION_PATHNAME.exist? ? YAML.load_file(CONFIGURATION_PATHNAME) : {}
55+
56+
specified_readme_template_path = config_hash['readme_template_path']
57+
if specified_readme_template_path.nil?
58+
DEFAULT_README_TEMPLATE_PATHNAME
59+
else
60+
Pathname.new(specified_readme_template_path)
61+
end
62+
end
4863
end
4964

5065
class << self

lib/packs/user_event_logger.rb

+5
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ def on_create_public_directory_todo(pack_name)
148148

149149
sig { params(pack_name: String).returns(String) }
150150
def on_create_readme_todo(pack_name)
151+
readme_template_pathname = Packs.config.readme_template_pathname
152+
readme_template = readme_template_pathname.read if readme_template_pathname.exist?
153+
154+
return readme_template unless readme_template.nil?
155+
151156
<<~MSG
152157
Welcome to `#{pack_name}`!
153158

packs.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |spec|
22
spec.name = 'packs'
3-
spec.version = '0.0.45'
3+
spec.version = '0.1.0'
44
spec.authors = ['Gusto Engineers']
55
spec.email = ['[email protected]']
66

spec/packs_spec.rb

+26
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,32 @@ def write_codeownership_config
333333
expect(actual_readme_todo.exist?).to eq false
334334
end
335335
end
336+
337+
context 'when the app has a README template' do
338+
it 'uses the template to create the README_TODO.md' do
339+
write_file('README_TEMPLATE.md', 'This is the template')
340+
Packs.create_pack!(pack_name: 'packs/organisms')
341+
ParsePackwerk.bust_cache!
342+
actual_readme_todo = ParsePackwerk.find('packs/organisms').directory.join('README_TODO.md')
343+
expect(actual_readme_todo.read).to eq 'This is the template'
344+
end
345+
346+
context 'and a custom path is specified for the README template' do
347+
before do
348+
write_file('packs.yml', <<~YML)
349+
readme_template_path: my_folder/README_STUFF.md
350+
YML
351+
end
352+
353+
it 'uses the template to create the README_TODO.md' do
354+
write_file('my_folder/README_STUFF.md', 'This is the custom template')
355+
Packs.create_pack!(pack_name: 'packs/organisms')
356+
ParsePackwerk.bust_cache!
357+
actual_readme_todo = ParsePackwerk.find('packs/organisms').directory.join('README_TODO.md')
358+
expect(actual_readme_todo.read).to eq 'This is the custom template'
359+
end
360+
end
361+
end
336362
end
337363
end
338364

0 commit comments

Comments
 (0)