+1, with a comment below.

On Jun 6, 2010, at 9:04 AM, Brice Figureau wrote:

This adds the --charset option to puppetdoc for RDoc mode.
This allows to set the charset for the generated html.

Signed-off-by: Brice Figureau <[email protected]>
---
bin/puppetdoc                 |    5 ++++-
lib/puppet/application/doc.rb |    3 ++-
lib/puppet/util/rdoc.rb       |    3 ++-
spec/unit/application/doc.rb  |   15 +++++++++++----
spec/unit/util/rdoc.rb        |    6 ++++++
5 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/bin/puppetdoc b/bin/puppetdoc
index 849b533..400a582 100755
--- a/bin/puppetdoc
+++ b/bin/puppetdoc
@@ -9,7 +9,7 @@
# = Usage
#
# puppet doc [-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|..>] [-- charset CHARSET] [manifest-file]
#
# = Description
#
@@ -42,6 +42,9 @@
# reference::
# Build a particular reference. Get a list of references by running +puppet doc --list+.
#
+# charset::
+# Used only in 'rdoc' mode. It sets the charset used in the html files produced.
+#
# = Example
#
#   $ puppet doc -r type > /tmp/type_reference.rst
diff --git a/lib/puppet/application/doc.rb b/lib/puppet/application/ doc.rb
index 74cde98..bbc6784 100644
--- a/lib/puppet/application/doc.rb
+++ b/lib/puppet/application/doc.rb
@@ -25,6 +25,7 @@ class Puppet::Application::Doc < Puppet::Application
    option("--outputdir OUTPUTDIR","-o")
    option("--verbose","-v")
    option("--debug","-d")
+    option("--charset CHARSET")

    option("--format FORMAT", "-f") do |arg|
        method = "to_%s" % arg
@@ -81,7 +82,7 @@ class Puppet::Application::Doc < Puppet::Application
                Puppet::Util::RDoc.manifestdoc(files)
            else
                options[:outputdir] = "doc" unless options[:outputdir]
-                Puppet::Util::RDoc.rdoc(options[:outputdir], files)
+ Puppet::Util::RDoc.rdoc(options[:outputdir], files, options[:charset])
            end
        rescue => detail
            if Puppet[:trace]
diff --git a/lib/puppet/util/rdoc.rb b/lib/puppet/util/rdoc.rb
index fc4e2c6..cb9610c 100644
--- a/lib/puppet/util/rdoc.rb
+++ b/lib/puppet/util/rdoc.rb
@@ -5,7 +5,7 @@ module Puppet::Util::RDoc

    # launch a rdoc documenation process
    # with the files/dir passed in +files+
-    def rdoc(outputdir, files)
+    def rdoc(outputdir, files, charset = nil)
        begin
            Puppet[:ignoreimport] = true

@@ -26,6 +26,7 @@ module Puppet::Util::RDoc
                        "--exclude", "/modules/[^/]*/files/.*\.pp$",
                        "--op", outputdir ]

+            options += [ "--charset", charset] if charset
            options += files

            # launch the documentation process
diff --git a/spec/unit/application/doc.rb b/spec/unit/application/ doc.rb
index c118492..3089f24 100755
--- a/spec/unit/application/doc.rb
+++ b/spec/unit/application/doc.rb
@@ -58,7 +58,7 @@ describe Puppet::Application::Doc do
    end

    describe "when handling options" do
-        [:all, :outputdir, :verbose, :debug].each do |option|
+ [:all, :outputdir, :verbose, :debug, :charset].each do | option|
            it "should declare handle_#{option} method" do
                @doc.should respond_to("handle_#{option}".to_sym)
            end
@@ -298,6 +298,7 @@ describe Puppet::Application::Doc do
Puppet.stubs(: []).with(:manifestdir).returns('manifests')
                @doc.options.stubs(:[]).with(:all).returns(false)
@doc.options.stubs(: []).with(:outputdir).returns('doc')
+                @doc.options.stubs(:[]).with(:charset).returns(nil)
                Puppet.settings.stubs(:[]=).with(:document_all, false)
                Puppet.settings.stubs(:setdefaults)
                Puppet::Util::RDoc.stubs(:rdoc)
@@ -315,13 +316,19 @@ describe Puppet::Application::Doc do
            end

            it "should call Puppet::Util::RDoc.rdoc in full mode" do
- Puppet::Util::RDoc.expects(:rdoc).with('doc', ['modules','manifests']) + Puppet::Util::RDoc.expects(:rdoc).with('doc', ['modules','manifests'], nil)
+                @doc.rdoc
+            end
+
+ it "should call Puppet::Util::RDoc.rdoc with a charset if --charset has been provided" do + @doc.options.expects(: []).with(:charset).returns("utf-8") + Puppet::Util::RDoc.expects(:rdoc).with('doc', ['modules','manifests'], "utf-8")

These tests can usually be written better like this:

Puppet::Util::RDoc.expects(:rdoc).with { |dir, array, charset| charset == "utf-8" }

Exceptions aren't quite as clear, but the tests are far more resilient to changes in the method profile.

                @doc.rdoc
            end

it "should call Puppet::Util::RDoc.rdoc in full mode with outputdir set to doc if no --outputdir" do @doc.options.expects(: []).with(:outputdir).returns(false) - Puppet::Util::RDoc.expects(:rdoc).with('doc', ['modules','manifests']) + Puppet::Util::RDoc.expects(:rdoc).with('doc', ['modules','manifests'], nil)
                @doc.rdoc
            end

@@ -335,7 +342,7 @@ describe Puppet::Application::Doc do
@env.expects(:modulepath).returns(['envmodules1','envmodules2']) @env.expects(: []).with(:manifest).returns('envmanifests/site.pp')

- Puppet::Util::RDoc.expects(:rdoc).with('doc', ['envmodules1','envmodules2','envmanifests']) + Puppet::Util::RDoc.expects(:rdoc).with('doc', ['envmodules1','envmodules2','envmanifests'], nil)

                @doc.rdoc
            end
diff --git a/spec/unit/util/rdoc.rb b/spec/unit/util/rdoc.rb
index 25c94a1..4417fca 100755
--- a/spec/unit/util/rdoc.rb
+++ b/spec/unit/util/rdoc.rb
@@ -37,6 +37,12 @@ describe Puppet::Util::RDoc do
            Puppet::Util::RDoc.rdoc("output", [])
        end

+        it "should pass charset to RDoc" do
+ @rdoc.expects(:document).with { |args| args.include?("-- charset") and args.include?("utf-8") }
+
+            Puppet::Util::RDoc.rdoc("output", [], "utf-8")
+        end
+
        it "should tell RDoc to force updates of indices" do
@rdoc.expects(:document).with { |args| args.include?("-- force-update") }

--
1.6.6.1

--
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 .



--
A little government and a little luck are necessary in life, but only a
fool trusts either of them. -- P. J. O'Rourke
---------------------------------------------------------------------
Luke Kanies  -|-   http://puppetlabs.com   -|-   +1(615)594-8199

--
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