summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJames Turnbull <james@lovedthanlost.net>2009-07-02 14:01:39 +1000
committerJames Turnbull <james@lovedthanlost.net>2009-07-10 14:55:41 +1000
commit44f127f738f6427bdf2adbe1d06d57b7b62e715e (patch)
tree6165256ca9d30f70d409113c5b612fdf07fed843 /lib
parent8a8ce9d40fd97b26906301b0587395c9fb9fddf6 (diff)
downloadpuppet-44f127f738f6427bdf2adbe1d06d57b7b62e715e.tar.gz
puppet-44f127f738f6427bdf2adbe1d06d57b7b62e715e.tar.xz
puppet-44f127f738f6427bdf2adbe1d06d57b7b62e715e.zip
Added Markdown mode to puppetdoc to output Markdown.
Requires the pandoc binary to function (http://johnmacfarlane.net/pandoc/).
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/application/puppetdoc.rb30
-rw-r--r--lib/puppet/util/reference.rb32
2 files changed, 54 insertions, 8 deletions
diff --git a/lib/puppet/application/puppetdoc.rb b/lib/puppet/application/puppetdoc.rb
index 99e46cfd1..45aba42ea 100644
--- a/lib/puppet/application/puppetdoc.rb
+++ b/lib/puppet/application/puppetdoc.rb
@@ -58,8 +58,7 @@ Puppet::Application.new(:puppetdoc) do
end
dispatch do
- return :rdoc if options[:mode] == :rdoc
- return :trac if options[:mode] == :trac
+ return options[:mode] if [:rdoc, :trac, :markdown].include?(options[:mode])
return :other
end
@@ -101,6 +100,31 @@ Puppet::Application.new(:puppetdoc) do
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
text = ""
if options[:references].length > 1
@@ -132,7 +156,7 @@ Puppet::Application.new(:puppetdoc) do
if options[:mode] == :pdf
Puppet::Util::Reference.pdf(text)
- else
+ else
puts text
end
diff --git a/lib/puppet/util/reference.rb b/lib/puppet/util/reference.rb
index 40e49f45f..7526e6566 100644
--- a/lib/puppet/util/reference.rb
+++ b/lib/puppet/util/reference.rb
@@ -14,7 +14,7 @@ class Puppet::Util::Reference
end
def self.modes
- %w{pdf trac text}
+ %w{pdf trac text markdown}
end
def self.newreference(name, options = {}, &block)
@@ -57,14 +57,36 @@ class Puppet::Util::Reference
$stderr.puts output
# Now convert to pdf
- puts "handling pdf"
Dir.chdir("/tmp") do
%x{texi2pdf puppetdoc.tex >/dev/null 2>/dev/null}
end
- #if FileTest.exists?("/tmp/puppetdoc.pdf")
- # FileUtils.mv("/tmp/puppetdoc.pdf", "/export/apache/docroots/reductivelabs.com/htdocs/downloads/puppet/reference.pdf")
- #end
+ 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
def self.references