Permalink
Browse files

display parameters

  • Loading branch information...
1 parent 5ef74ce commit 3c302061c59a22669d41fbd4e4375d0667062a6b @markbates committed Mar 6, 2012
Showing with 17 additions and 2 deletions.
  1. +10 −1 lib/api_doc/document.rb
  2. +7 −1 lib/api_doc/templates/page.html.erb
View
@@ -14,7 +14,8 @@ def initialize(env, options = {})
# puts "@request.env['action_dispatch.request.path_parameters']: #{@request.env['action_dispatch.request.path_parameters'].inspect}"
@response = @env.response
- @params = @request.headers['action_dispatch.request.path_parameters']
+ @params = @request.env['action_dispatch.request.parameters']
+ @path_parameters = @request.env['action_dispatch.request.path_parameters']
# puts File.join(@params["controller"], @params["action"])
options.reverse_merge!(path: File.join(@params["controller"], @params["action"]))
@options = options
@@ -37,6 +38,10 @@ def request_json
end
end
+ def request_params
+ @params.except(*@path_parameters.keys, "format").to_query
+ end
+
def response_json
body = @response.body.strip
if body.present?
@@ -46,6 +51,10 @@ def response_json
end
end
+ def response_headers
+ @response.headers.map {|k, v| "'#{k}': '#{v.to_json}'"}.join("\n")
+ end
+
def generate!
template = ERB.new(File.read(File.join(File.dirname(__FILE__), "templates", "page.html.erb")))
html = template.result(binding)
@@ -37,6 +37,12 @@
<h2><%= @request.method %> <%= @request.path_info %></h2>
<h3>Status: <%= @response.status %></h3>
+<% unless request_params.blank? %>
+<h3>Parameters</h3>
+<pre class="prettyprint">
+?<%= request_params %>
+</pre>
+<% end %>
<h3>Body</h3>
<pre class="prettyprint">
<%= request_json %>
@@ -49,7 +55,7 @@
<% if @response.headers.present? %>
<h3>Headers:</h3>
<pre class="prettyprint">
-<%= @response.headers %>
+<%= response_headers %>
</pre>
<% end %>

0 comments on commit 3c30206

Please sign in to comment.