Skip to content

Commit 13643ae

Browse files
committed
allow appending a footer in the mandoc renderer
1 parent 025a644 commit 13643ae

File tree

8 files changed

+59
-17
lines changed

8 files changed

+59
-17
lines changed

.rubocop.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ RSpec/FilePath:
2828
- 'spec/bashly/concerns/completions_command_spec.rb'
2929
- 'spec/bashly/concerns/completions_flag_spec.rb'
3030

31-
# FIXME: This test is ugly and long
31+
# Allow longer integration examples as they are more complex by nature
3232
RSpec/ExampleLength:
3333
Exclude:
34-
- 'spec/bashly/integration/rendering_spec.rb'
34+
- 'spec/bashly/integration/**/*'

lib/bashly/libraries/render/mandoc/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ $ PREVIEW="cli download" bashly render :mandoc docs
2121
# .. and also watch for changes
2222
$ PREVIEW="cli download" bashly render :mandoc docs --watch
2323
```
24+
25+
## Appending a footer
26+
27+
In case you wish to append additional sections to your generated man pages,
28+
you can place a file named `_footer.md` in your target directory.

lib/bashly/libraries/render/mandoc/mandoc.gtx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ if examples
166166
>
167167
end
168168
> ~~~
169+
>
169170
end
170171

171172
if public_commands.any?
@@ -175,3 +176,5 @@ if public_commands.any?
175176
= public_commands.map { |x| "**#{x.full_name.to_hyphen}**(1)" }.join ', '
176177
>
177178
end
179+
180+
>

lib/bashly/libraries/render/mandoc/render.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@
1111
manfile = "#{target}/#{command.full_name.tr(' ', '-')}.1"
1212
save mdfile, gtx.parse(command)
1313

14-
cmd = %[pandoc -f markdown-smart -s --to man "#{mdfile}" > "#{manfile}"]
14+
# Append the footer file if it exists
15+
footer_file = "#{target}/_footer.md"
16+
if File.exist? footer_file
17+
File.append mdfile, File.read(footer_file)
18+
end
1519

20+
# The pandoc command that creates a manpage from markdown
21+
cmd = %[pandoc -f markdown-smart -s --to man "#{mdfile}" > "#{manfile}"]
1622
success = system cmd
1723
raise "Failed running pandoc\nMake sure the following command succeeds and try again:\n\n #{cmd}" unless success
1824

spec/approvals/rendering/mandoc/catch-all-advanced/cli-download.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ cli download example.com
5151
cli download example.com ./output -f
5252
5353
~~~
54+

spec/approvals/rendering/mandoc/minimal/download.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ download example.com
4646
download example.com ./output -f
4747
4848
~~~
49+

spec/bashly/integration/rendering_spec.rb renamed to spec/bashly/integration/rendering_mandoc_spec.rb

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This spec tests that the rendering using the libraries/render templates
22
# is generating the expected output.
3-
describe 'rendering templates' do
3+
describe 'rendering mandoc' do
44
subject { Commands::Render.new }
55

66
target = 'spec/tmp'
@@ -22,19 +22,7 @@
2222
reset_tmp_dir
2323
end
2424

25-
it 'renders markdown properly' do
26-
expect { subject.execute %W[render :markdown #{target}] }
27-
.to output_approval("rendering/markdown/#{example}/stdout")
28-
29-
Dir["#{target}/*.md"].each do |file|
30-
puts " => #{file}"
31-
basename = File.basename file
32-
expect(File.read file).to match_approval("rendering/markdown/#{example}/#{basename}")
33-
.diff(leeway)
34-
end
35-
end
36-
37-
it 'renders mandoc properly' do
25+
it 'renders properly' do
3826
expect { subject.execute %W[render :mandoc #{target}] }
3927
.to output_approval("rendering/mandoc/#{example}/stdout")
4028

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This spec tests that the rendering using the libraries/render templates
2+
# is generating the expected output.
3+
describe 'rendering markdown' do
4+
subject { Commands::Render.new }
5+
6+
target = 'spec/tmp'
7+
examples = %w[
8+
catch-all-advanced
9+
dependencies-alt
10+
docker-like
11+
extensible-delegate
12+
minimal
13+
]
14+
15+
# Allow up to a certain string distance from the approval text in CI
16+
leeway = ENV['CI'] ? 20 : 0
17+
18+
examples.each do |example|
19+
describe example do
20+
before do
21+
Settings.config_path = "examples/#{example}/src/bashly.yml"
22+
reset_tmp_dir
23+
end
24+
25+
it 'renders properly' do
26+
expect { subject.execute %W[render :markdown #{target}] }
27+
.to output_approval("rendering/markdown/#{example}/stdout")
28+
29+
Dir["#{target}/*.md"].each do |file|
30+
puts " => #{file}"
31+
basename = File.basename file
32+
expect(File.read file).to match_approval("rendering/markdown/#{example}/#{basename}")
33+
.diff(leeway)
34+
end
35+
end
36+
end
37+
end
38+
end

0 commit comments

Comments
 (0)