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