class Puppet::Util::Reference
Manage Reference Documentation.
Attributes
depth[RW]
doc[W]
dynamic[RW]
header[RW]
page[RW]
title[RW]
Public Class Methods
modes()
click to toggle source
# File lib/puppet/util/reference.rb 14 def self.modes 15 %w{pdf text} 16 end
new(name, title: nil, depth: nil, dynamic: nil, doc: nil, &block)
click to toggle source
# File lib/puppet/util/reference.rb 80 def initialize(name, title: nil, depth: nil, dynamic: nil, doc: nil, &block) 81 @name = name 82 @title = title 83 @depth = depth 84 @dynamic = dynamic 85 @doc = doc 86 87 meta_def(:generate, &block) 88 89 # Now handle the defaults 90 @title ||= _("%{name} Reference") % { name: @name.to_s.capitalize } 91 @page ||= @title.gsub(/\s+/, '') 92 @depth ||= 2 93 @header ||= "" 94 end
newreference(name, options = {}, &block)
click to toggle source
# File lib/puppet/util/reference.rb 18 def self.newreference(name, options = {}, &block) 19 ref = self.new(name, **options, &block) 20 instance_hash(:reference)[name.intern] = ref 21 22 ref 23 end
page(*sections)
click to toggle source
# File lib/puppet/util/reference.rb 25 def self.page(*sections) 26 depth = 4 27 # Use the minimum depth 28 sections.each do |name| 29 section = reference(name) or raise _("Could not find section %{name}") % { name: name } 30 depth = section.depth if section.depth < depth 31 end 32 end
pdf(text)
click to toggle source
# File lib/puppet/util/reference.rb 34 def self.pdf(text) 35 puts _("creating pdf") 36 rst2latex = which('rst2latex') || which('rst2latex.py') || 37 raise(_("Could not find rst2latex")) 38 39 cmd = %{#{rst2latex} /tmp/puppetdoc.txt > /tmp/puppetdoc.tex} 40 Puppet::Util.replace_file("/tmp/puppetdoc.txt") {|f| f.puts text } 41 # There used to be an attempt to use secure_open / replace_file to secure 42 # the target, too, but that did nothing: the race was still here. We can 43 # get exactly the same benefit from running this effort: 44 Puppet::FileSystem.unlink('/tmp/puppetdoc.tex') rescue nil 45 output = %x{#{cmd}} 46 unless $CHILD_STATUS == 0 47 $stderr.puts _("rst2latex failed") 48 $stderr.puts output 49 exit(1) 50 end 51 $stderr.puts output 52 53 # Now convert to pdf 54 Dir.chdir("/tmp") do 55 %x{texi2pdf puppetdoc.tex >/dev/null 2>/dev/null} 56 end 57 58 end
references(environment)
click to toggle source
# File lib/puppet/util/reference.rb 60 def self.references(environment) 61 instance_loader(:reference).loadall(environment) 62 loaded_instances(:reference).sort_by(&:to_s) 63 end
Public Instance Methods
doc()
click to toggle source
# File lib/puppet/util/reference.rb 68 def doc 69 if defined?(@doc) 70 return "#{@name} - #{@doc}" 71 else 72 return @title 73 end 74 end
dynamic?()
click to toggle source
# File lib/puppet/util/reference.rb 76 def dynamic? 77 self.dynamic 78 end
indent(text, tab)
click to toggle source
Indent every line in the chunk except those which begin with '..'.
# File lib/puppet/util/reference.rb 97 def indent(text, tab) 98 text.gsub(/(^|\A)/, tab).gsub(/^ +\.\./, "..") 99 end
option(name, value)
click to toggle source
# File lib/puppet/util/reference.rb 101 def option(name, value) 102 ":#{name.to_s.capitalize}: #{value}\n" 103 end
text()
click to toggle source
# File lib/puppet/util/reference.rb 105 def text 106 puts output 107 end
to_markdown(withcontents = true)
click to toggle source
# File lib/puppet/util/reference.rb 109 def to_markdown(withcontents = true) 110 # First the header 111 text = markdown_header(@title, 1) 112 text << _("\n\n**This page is autogenerated; any changes will get overwritten**\n\n") 113 114 text << @header 115 116 text << generate 117 118 text 119 end