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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
# frozen_string_literal: true
require_relative '../../puppet/util/instance_loader'
require 'fileutils'
# Manage Reference Documentation.
class Puppet::Util::Reference
include Puppet::Util
include Puppet::Util::Docs
extend Puppet::Util::InstanceLoader
instance_load(:reference, 'puppet/reference')
def self.modes
%w[text]
end
def self.newreference(name, options = {}, &block)
ref = new(name, **options, &block)
instance_hash(:reference)[name.intern] = ref
ref
end
def self.page(*sections)
depth = 4
# Use the minimum depth
sections.each do |name|
section = reference(name) or raise _("Could not find section %{name}") % { name: name }
depth = section.depth if section.depth < depth
end
end
def self.references(environment)
instance_loader(:reference).loadall(environment)
loaded_instances(:reference).sort_by(&:to_s)
end
attr_accessor :page, :depth, :header, :title, :dynamic
attr_writer :doc
def doc
if defined?(@doc)
"#{@name} - #{@doc}"
else
@title
end
end
def dynamic?
dynamic
end
def initialize(name, title: nil, depth: nil, dynamic: nil, doc: nil, &block)
@name = name
@title = title
@depth = depth
@dynamic = dynamic
@doc = doc
meta_def(:generate, &block)
# Now handle the defaults
@title ||= _("%{name} Reference") % { name: @name.to_s.capitalize }
@page ||= @title.gsub(/\s+/, '')
@depth ||= 2
@header ||= ""
end
# Indent every line in the chunk except those which begin with '..'.
def indent(text, tab)
text.gsub(/(^|\A)/, tab).gsub(/^ +\.\./, "..")
end
def option(name, value)
":#{name.to_s.capitalize}: #{value}\n"
end
def text
puts output
end
def to_markdown(withcontents = true)
# First the header
text = markdown_header(@title, 1)
text << @header
text << generate
text
end
end
|