Class: Puppet::Util::Reference
Overview
Manage Reference Documentation.
Constant Summary
collapse
[nil, "#", "##", "###", "####", "#####"]
Instance Attribute Summary collapse
Attributes included from Docs
#nodoc
Class Method Summary
collapse
Instance Method Summary
collapse
instance_docs, instance_hash, instance_load, instance_loader, instance_loading?, loaded_instance, loaded_instances
activerecord_version, benchmark, chuser, classproxy, #execfail, #execpipe, execute, logmethods, memory, proxy, recmkdir, secure_open, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, #threadlock, which, withumask
Methods included from POSIX
#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from Docs
#desc, #dochook, #doctable, #nodoc?, #pad, scrub
Constructor Details
#initialize(name, options = {}, &block) ⇒ Reference
Returns a new instance of Reference.
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/puppet/util/reference.rb', line 88
def initialize(name, options = {}, &block)
@name = name
options.each do |option, value|
send(option.to_s + "=", value)
end
meta_def(:generate, &block)
@title ||= "#{@name.to_s.capitalize} Reference"
@page ||= @title.gsub(/\s+/, '')
@depth ||= 2
||= ""
end
|
Instance Attribute Details
Returns the value of attribute depth.
69
70
71
|
# File 'lib/puppet/util/reference.rb', line 69
def depth
@depth
end
|
72
73
74
75
76
77
78
|
# File 'lib/puppet/util/reference.rb', line 72
def doc
if defined?(@doc)
return "#{@name} - #{@doc}"
else
return @title
end
end
|
Returns the value of attribute dynamic.
69
70
71
|
# File 'lib/puppet/util/reference.rb', line 69
def dynamic
@dynamic
end
|
Returns the value of attribute header.
69
70
71
|
# File 'lib/puppet/util/reference.rb', line 69
def
end
|
Returns the value of attribute page.
69
70
71
|
# File 'lib/puppet/util/reference.rb', line 69
def page
@page
end
|
Returns the value of attribute title.
69
70
71
|
# File 'lib/puppet/util/reference.rb', line 69
def title
@title
end
|
Class Method Details
13
14
15
|
# File 'lib/puppet/util/reference.rb', line 13
def self.
"\n\n----------------\n\n*This page autogenerated on #{Time.now}*\n"
end
|
17
18
19
|
# File 'lib/puppet/util/reference.rb', line 17
def self.modes
%w{pdf text}
end
|
.newreference(name, options = {}, &block) ⇒ Object
21
22
23
24
25
26
|
# File 'lib/puppet/util/reference.rb', line 21
def self.newreference(name, options = {}, &block)
ref = self.new(name, options, &block)
instance_hash(:reference)[symbolize(name)] = ref
ref
end
|
.page(*sections) ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/puppet/util/reference.rb', line 28
def self.page(*sections)
depth = 4
sections.each do |name|
section = reference(name) or raise "Could not find section #{name}"
depth = section.depth if section.depth < depth
end
end
|
.pdf(text) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/puppet/util/reference.rb', line 37
def self.pdf(text)
puts "creating pdf"
Puppet::Util.secure_open("/tmp/puppetdoc.txt", "w") do |f|
f.puts text
end
rst2latex = which('rst2latex') || which('rst2latex.py') || raise("Could not find rst2latex")
cmd = %{#{rst2latex} /tmp/puppetdoc.txt > /tmp/puppetdoc.tex}
Puppet::Util.secure_open("/tmp/puppetdoc.tex","w") do |f|
end
output = %x{#{cmd}}
unless $CHILD_STATUS == 0
$stderr.puts "rst2latex failed"
$stderr.puts output
exit(1)
end
$stderr.puts output
Dir.chdir("/tmp") do
%x{texi2pdf puppetdoc.tex >/dev/null 2>/dev/null}
end
end
|
.references ⇒ Object
62
63
64
65
|
# File 'lib/puppet/util/reference.rb', line 62
def self.references
instance_loader(:reference).loadall
loaded_instances(:reference).sort { |a,b| a.to_s <=> b.to_s }
end
|
Instance Method Details
#dynamic? ⇒ Boolean
80
81
82
|
# File 'lib/puppet/util/reference.rb', line 80
def dynamic?
self.dynamic
end
|
#h(name, level) ⇒ Object
84
85
86
|
# File 'lib/puppet/util/reference.rb', line 84
def h(name, level)
"#{HEADER_LEVELS[level]} #{name}\n\n"
end
|
#indent(text, tab) ⇒ Object
Indent every line in the chunk except those which begin with ‘..’.
104
105
106
|
# File 'lib/puppet/util/reference.rb', line 104
def indent(text, tab)
text.gsub(/(^|\A)/, tab).gsub(/^ +\.\./, "..")
end
|
#option(name, value) ⇒ Object
108
109
110
|
# File 'lib/puppet/util/reference.rb', line 108
def option(name, value)
":#{name.to_s.capitalize}: #{value}\n"
end
|
#paramwrap(name, text, options = {}) ⇒ Object
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/puppet/util/reference.rb', line 112
def paramwrap(name, text, options = {})
options[:level] ||= 5
str = h(name, options[:level])
str += "- **namevar**\n\n" if options[:namevar]
str += text
str += "\n\n"
end
|
123
124
125
|
# File 'lib/puppet/util/reference.rb', line 123
def text
puts output
end
|
#to_markdown(withcontents = true) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/puppet/util/reference.rb', line 127
def to_markdown(withcontents = true)
text = h(@title, 1)
text += "\n\n**This page is autogenerated; any changes will get overwritten** *(last generated on #{Time.now.to_s})*\n\n"
text +=
text += generate
text += self.class. if withcontents
text
end
|