Added Markdown mode to puppetdoc to output Markdown.
Requires the pandoc binary to function (http://johnmacfarlane.net/pandoc/).
This commit is contained in:
Родитель
8a8ce9d40f
Коммит
44f127f738
|
@ -8,7 +8,7 @@
|
||||||
#
|
#
|
||||||
# = Usage
|
# = Usage
|
||||||
#
|
#
|
||||||
# puppetdoc [-a|--all] [-h|--help] [-o|--outputdir <rdoc outputdir>] [-m|--mode <text|pdf|trac|rdoc>]
|
# puppetdoc [-a|--all] [-h|--help] [-o|--outputdir <rdoc outputdir>] [-m|--mode <text|pdf|markdown|trac|rdoc>]
|
||||||
# [-r|--reference <[type]|configuration|..>] [manifest-file]
|
# [-r|--reference <[type]|configuration|..>] [manifest-file]
|
||||||
#
|
#
|
||||||
# = Description
|
# = Description
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
# Specifies the directory where to output the rdoc documentation in 'rdoc' mode.
|
# Specifies the directory where to output the rdoc documentation in 'rdoc' mode.
|
||||||
#
|
#
|
||||||
# mode::
|
# mode::
|
||||||
# Determine the output mode. Valid modes are 'text', 'trac', 'pdf' and 'rdoc'. Note that 'trac' mode only works on Reductive Labs servers. The default mode is 'text'. In 'rdoc' mode you must provide 'manifests-path'
|
# Determine the output mode. Valid modes are 'text', 'trac', 'pdf', 'markdown' and 'rdoc'. The 'pdf' and 'markdown' modes create PDF or Markdown formatted files in the /tmp directory. Note that 'trac' mode only works on Reductive Labs servers. The default mode is 'text'. In 'rdoc' mode you must provide 'manifests-path'
|
||||||
#
|
#
|
||||||
# reference::
|
# reference::
|
||||||
# Build a particular reference. Get a list of references by running +puppetdoc --list+.
|
# Build a particular reference. Get a list of references by running +puppetdoc --list+.
|
||||||
|
@ -49,6 +49,8 @@
|
||||||
# $ puppetdoc --outputdir /tmp/rdoc --mode rdoc /path/to/manifests
|
# $ puppetdoc --outputdir /tmp/rdoc --mode rdoc /path/to/manifests
|
||||||
# or
|
# or
|
||||||
# $ puppetdoc /etc/puppet/manifests/site.pp
|
# $ puppetdoc /etc/puppet/manifests/site.pp
|
||||||
|
# or
|
||||||
|
# $ puppetdoc -m markdown -r configuration
|
||||||
#
|
#
|
||||||
# = Author
|
# = Author
|
||||||
#
|
#
|
||||||
|
|
|
@ -58,8 +58,7 @@ Puppet::Application.new(:puppetdoc) do
|
||||||
end
|
end
|
||||||
|
|
||||||
dispatch do
|
dispatch do
|
||||||
return :rdoc if options[:mode] == :rdoc
|
return options[:mode] if [:rdoc, :trac, :markdown].include?(options[:mode])
|
||||||
return :trac if options[:mode] == :trac
|
|
||||||
return :other
|
return :other
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -101,6 +100,31 @@ Puppet::Application.new(:puppetdoc) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
command(:markdown) do
|
||||||
|
text = ""
|
||||||
|
with_contents = false
|
||||||
|
exit_code = 0
|
||||||
|
options[:references].sort { |a,b| a.to_s <=> b.to_s }.each do |name|
|
||||||
|
raise "Could not find reference %s" % name unless section = Puppet::Util::Reference.reference(name)
|
||||||
|
|
||||||
|
begin
|
||||||
|
# Add the per-section text, but with no ToC
|
||||||
|
text += section.send(options[:format], with_contents)
|
||||||
|
text += Puppet::Util::Reference.footer
|
||||||
|
text.gsub!(/`\w+\s+([^`]+)`:trac:/) { |m| $1 }
|
||||||
|
Puppet::Util::Reference.markdown(name, text)
|
||||||
|
text = ""
|
||||||
|
rescue => detail
|
||||||
|
puts detail.backtrace
|
||||||
|
$stderr.puts "Could not generate reference %s: %s" % [name, detail]
|
||||||
|
exit_code = 1
|
||||||
|
next
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
exit exit_code
|
||||||
|
end
|
||||||
|
|
||||||
command(:other) do
|
command(:other) do
|
||||||
text = ""
|
text = ""
|
||||||
if options[:references].length > 1
|
if options[:references].length > 1
|
||||||
|
@ -132,7 +156,7 @@ Puppet::Application.new(:puppetdoc) do
|
||||||
|
|
||||||
if options[:mode] == :pdf
|
if options[:mode] == :pdf
|
||||||
Puppet::Util::Reference.pdf(text)
|
Puppet::Util::Reference.pdf(text)
|
||||||
else
|
else
|
||||||
puts text
|
puts text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ class Puppet::Util::Reference
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.modes
|
def self.modes
|
||||||
%w{pdf trac text}
|
%w{pdf trac text markdown}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.newreference(name, options = {}, &block)
|
def self.newreference(name, options = {}, &block)
|
||||||
|
@ -57,14 +57,36 @@ class Puppet::Util::Reference
|
||||||
$stderr.puts output
|
$stderr.puts output
|
||||||
|
|
||||||
# Now convert to pdf
|
# Now convert to pdf
|
||||||
puts "handling pdf"
|
|
||||||
Dir.chdir("/tmp") do
|
Dir.chdir("/tmp") do
|
||||||
%x{texi2pdf puppetdoc.tex >/dev/null 2>/dev/null}
|
%x{texi2pdf puppetdoc.tex >/dev/null 2>/dev/null}
|
||||||
end
|
end
|
||||||
|
|
||||||
#if FileTest.exists?("/tmp/puppetdoc.pdf")
|
end
|
||||||
# FileUtils.mv("/tmp/puppetdoc.pdf", "/export/apache/docroots/reductivelabs.com/htdocs/downloads/puppet/reference.pdf")
|
|
||||||
#end
|
def self.markdown(name, text)
|
||||||
|
puts "Creating markdown for #{name} reference."
|
||||||
|
dir = "/tmp/" + Puppet::PUPPETVERSION
|
||||||
|
FileUtils.mkdir(dir) unless File.directory?(dir)
|
||||||
|
File.open(dir + "/" + "#{name}.rst", "w") do |f|
|
||||||
|
f.puts text
|
||||||
|
end
|
||||||
|
pandoc = %x{which pandoc}
|
||||||
|
if $? != 0 or pandoc =~ /no /
|
||||||
|
pandoc = %x{which pandoc}
|
||||||
|
end
|
||||||
|
if $? != 0 or pandoc =~ /no /
|
||||||
|
raise "Could not find pandoc"
|
||||||
|
end
|
||||||
|
pandoc.chomp!
|
||||||
|
cmd = %{#{pandoc} -s -r rst -w markdown #{dir}/#{name}.rst -o #{dir}/#{name}.mdwn}
|
||||||
|
output = %x{#{cmd}}
|
||||||
|
unless $? == 0
|
||||||
|
$stderr.puts "Pandoc failed to create #{name} reference."
|
||||||
|
$stderr.puts output
|
||||||
|
exit(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
File.unlink(dir + "/" + "#{name}.rst")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.references
|
def self.references
|
||||||
|
|
Загрузка…
Ссылка в новой задаче