+1

On Jul 1, 2009, at 11:14 PM, James Turnbull wrote:

>
>
> Signed-off-by: James Turnbull <[email protected]>
> ---
> bin/puppetdoc                       |    6 ++++--
> lib/puppet/application/puppetdoc.rb |   27 ++++++++++++++++++++++++++-
> lib/puppet/util/reference.rb        |   29 +++++++++++++++++++++++ 
> +-----
> 3 files changed, 54 insertions(+), 8 deletions(-)
>
> diff --git a/bin/puppetdoc b/bin/puppetdoc
> index 09d0966..a69d169 100755
> --- a/bin/puppetdoc
> +++ b/bin/puppetdoc
> @@ -8,7 +8,7 @@
> #
> # = 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]
> #
> # = Description
> @@ -37,7 +37,7 @@
> #   Specifies the directory where to output the rdoc documentation  
> in 'rdoc' 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::
> #   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
> # or
> #   $ puppetdoc /etc/puppet/manifests/site.pp
> +# or
> +#   $ puppetdoc -m markdown -r configuration
> #
> # = Author
> #
> diff --git a/lib/puppet/application/puppetdoc.rb b/lib/puppet/ 
> application/puppetdoc.rb
> index 99e46cf..297efe6 100644
> --- a/lib/puppet/application/puppetdoc.rb
> +++ b/lib/puppet/application/puppetdoc.rb
> @@ -60,6 +60,7 @@ Puppet::Application.new(:puppetdoc) do
>     dispatch do
>         return :rdoc if options[:mode] == :rdoc
>         return :trac if options[:mode] == :trac
> +        return :markdown if options[:mode] == :markdown
>         return :other
>     end
>
> @@ -101,6 +102,30 @@ 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)
> +            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 +157,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 40e49f4..93673bb 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,33 @@ 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."
> +        File.open("/tmp/#{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 /tmp/#{name}.rst - 
> o /tmp/#{name}.txt}
> +        output = %x{#{cmd}}
> +        unless $? == 0
> +            $stderr.puts "Pandoc failed to create #{name} reference."
> +            $stderr.puts output
> +            exit(1)
> +        end
> +
>     end
>
>     def self.references
> -- 
> 1.6.0.6
>
>
> >


-- 
Venter's First Law:
     Discoveries made in a field by some one from another discipline  
will
     always be upsetting to the majority of those inside.
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to