-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathpuppet_doc.rb
More file actions
52 lines (46 loc) · 1.93 KB
/
puppet_doc.rb
File metadata and controls
52 lines (46 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# frozen_string_literal: true
require 'puppet_references'
module PuppetReferences
module Puppet
class PuppetDoc < PuppetReferences::Reference
REFERENCES = %w[configuration].freeze
OUTPUT_DIR = PuppetReferences::OUTPUT_DIR + 'openvox'
def initialize(*)
@latest = '/openvox/latest'
super
end
def build_all
OUTPUT_DIR.mkpath
puts 'Oldskool refs: Building all...'
REFERENCES.each do |ref|
build_reference(ref)
end
puts 'Oldskool refs: Done!'
end
def build_reference(reference)
puts "Oldskool refs: Building #{reference} reference"
raw_content = PuppetReferences::DocCommand.new(reference).get
# Remove the first H1 with the title, like "# Metaparameter Reference"
raw_content.sub!(/^# \w+ Reference *$/, '')
clean_configuration_reference!(raw_content) if reference == 'configuration'
header_data = { title: "#{reference.capitalize} Reference",
toc: 'columns',
canonical: "#{@latest}/#{reference}.html", }
content = make_header(header_data) + raw_content
filename = OUTPUT_DIR + "#{reference}.md"
filename.open('w') { |f| f.write(content) }
end
# Remove any references to a real system's hostname.
def clean_configuration_reference!(text)
# Assume we aren't on Solaris or AIX, where this might set the hostname to "-f" D:
fqdn = `hostname -f`.strip
domain = fqdn.partition('.')[2]
text.gsub!(fqdn.downcase, "(the system's fully qualified domain name)")
# This is yuck to deal with when the domain name is "local," like a Mac on a DNS-less network.
# Will have to be very specific, which makes it kind of brittle.
return unless domain != ''
text.gsub!("- *Default*: #{domain.downcase}\n", "- *Default*: (the system's own domain)\n")
end
end
end
end