-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9459 from joshcooper/references_config_12065
(PUP-12065) Add task to generate configuration reference
- Loading branch information
Showing
4 changed files
with
2,302 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'tempfile' | ||
|
||
OUTPUT_DIR = 'references' | ||
CONFIGURATION_ERB = File.join(__dir__, 'references/configuration.erb') | ||
CONFIGURATION_MD = File.join(OUTPUT_DIR, 'configuration.md') | ||
|
||
def render_erb(erb_file, variables) | ||
# Create a binding so only the variables we specify will be visible | ||
template_binding = OpenStruct.new(variables).instance_eval {binding} | ||
ERB.new(File.read(erb_file), trim_mode: '-').result(template_binding) | ||
end | ||
|
||
def puppet_doc(reference) | ||
body = %x{bundle exec puppet doc -r #{reference}} | ||
# Remove the first H1 with the title, like "# Metaparameter Reference" | ||
body.sub!(/^# \w+ Reference *$/, '') | ||
body.chomp | ||
end | ||
|
||
# This is adapted from https://github.com/puppetlabs/puppet-docs/blob/1a13be3fc6981baa8a96ff832ab090abc986830e/lib/puppet_references/puppet/puppet_doc.rb#L22-L36 | ||
def generate_reference(reference, erb, body, output) | ||
sha = %x{git rev-parse HEAD}.chomp | ||
now = Time.now | ||
variables = { | ||
sha: sha, | ||
now: now, | ||
body: body | ||
} | ||
content = render_erb(erb, variables) | ||
File.write(output, content) | ||
puts "Generated #{output}" | ||
end | ||
|
||
namespace :references do | ||
desc "Generate configuration reference" | ||
task :configuration do | ||
ENV['PUPPET_REFERENCES_HOSTNAME'] = "(the system's fully qualified hostname)" | ||
ENV['PUPPET_REFERENCES_DOMAIN'] = "(the system's own domain)" | ||
|
||
body = puppet_doc('configuration') | ||
generate_reference('configuration', CONFIGURATION_ERB, body, CONFIGURATION_MD) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
layout: default | ||
built_from_commit: <%= sha %> | ||
title: Configuration Reference | ||
toc: columns | ||
canonical: "/puppet/latest/configuration.html" | ||
--- | ||
|
||
# Configuration Reference | ||
|
||
> **NOTE:** This page was generated from the Puppet source code on <%= now %> | ||
|
||
<%= body %> |
Oops, something went wrong.