Permalink
Browse files

Provide option to enable pretty xml output

  • Loading branch information...
1 parent 3aff3a2 commit 217557807cfc935a6c06f573e20706f0f8b68158 @chrisroberts committed Mar 18, 2012
Showing with 12 additions and 3 deletions.
  1. +4 −1 bin/dav4rack
  2. +8 −2 lib/dav4rack/controller.rb
View
@@ -27,7 +27,8 @@ opts = GetoptLong.new(
['--version', '-v', GetoptLong::NO_ARGUMENT],
['--root', '-r', GetoptLong::REQUIRED_ARGUMENT],
['--log', '-l', GetoptLong::OPTIONAL_ARGUMENT],
- ['--verbosity', '-V', GetoptLong::REQUIRED_ARGUMENT]
+ ['--verbosity', '-V', GetoptLong::REQUIRED_ARGUMENT],
+ ['--pretty-xml', '-P', GetoptLong::REQUIRED_ARGUMENT]
)
credentials = {}
@@ -47,6 +48,8 @@ opts.each do |opt,arg|
puts "ERROR: Path provided is not a valid directory (#{arg})"
exit(-1)
end
+ when '--pretty-xml'
+ credentials[:pretty_xml] = true
when '--version'
print_version_info
exit(0)
@@ -412,8 +412,14 @@ def render_xml(root_type)
yield xml
end
end
-
- response.body = doc.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XML)
+
+ if(@options[:pretty_xml])
+ response.body = doc.to_xml
+ else
+ response.body = doc.to_xml(
+ :save_with => Nokogiri::XML::Node::SaveOptions::AS_XML
+ )
+ end
response["Content-Type"] = 'text/xml; charset="utf-8"'
response["Content-Length"] = response.body.size.to_s
end

0 comments on commit 2175578

Please sign in to comment.