incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michal Fojtik <mfoj...@redhat.com>
Subject Re: [PATCH core] Added API docs generation tool
Date Tue, 14 Sep 2010 13:05:13 GMT
On 14/09/10 15:03 +0200, mfojtik@redhat.com wrote:
>From: Michal Fojtik <mfojtik@redhat.com>
>
>---
> server/support/tools/generate_documentation.rb |   56 ++++++++++++++++++++++++
> 1 files changed, 56 insertions(+), 0 deletions(-)
> create mode 100755 server/support/tools/generate_documentation.rb
>
>diff --git a/server/support/tools/generate_documentation.rb b/server/support/tools/generate_documentation.rb
>new file mode 100755
>index 0000000..deab1c7
>--- /dev/null
>+++ b/server/support/tools/generate_documentation.rb
>@@ -0,0 +1,56 @@
>+#!/usr/bin/ruby
>+
>+require 'rubygems'
>+require 'server'
>+require 'RedCloth'
>+require 'ap'

^^
This line can be safely removed. I'm always forgot remove this gem...

>+
>+version = '0.1'
>+
>+output = ["h1. Deltacloud API #{version} Reference"]
>+
>+collections.each do |collection|
>+  output << "h2. #{collection.first.to_s.capitalize.tr('_', ' ')}"
>+  output << collection.last.description
>+  collection.last.operations.each do |operation|
>+    output << "h3. #{operation.first}"
>+    operation_name=case operation.first
>+      when :index, :create then ""
>+      when :show, :destroy then "/:id"
>+      when :stop, :start, :reboot then "/:id/#{operation.first}"
>+      else "/"+operation.first.to_s
>+    end
>+    output << "h4. URI: #{operation.last.method.to_s.upcase} /api/#{collection.first}#{operation_name}"
>+    output << operation.last.description
>+    output << "h5. Parameters:"
>+    operation.last.params.each do |name, param|
>+      param_description = param.description
>+      param_description = case name
>+        when :id then "ID of #{collection.first.to_s.gsub(/s$/, '')}"
>+      end if param.description.empty?
>+      output << "* **#{name}** - #{param_description}"
>+    end
>+  end
>+end
>+
>+puts "<html"
>+puts "<head>"
>+puts "<style type='text/css'>"
>+style=<<-eos
>+body {
>+color: #252525;
>+font-family: 'Helvetica Neue', 'Liberation Sans', Arial, sans-serif;
>+font-size: 81.25%;  
>+}
>+h2 { border-bottom : 1px solid #ccc; background: #A4C3D4}
>+h3 { background : #E4EBEF;}
>+h4 { color : #738389;  font-style : italic;}
>+h4 .caps { font-style : normal;}
>+ul { list-style : none; }
>+ul li b { float : left; width : 150px; }
>+eos
>+puts style
>+puts "</style>"
>+puts "</head><body>"
>+puts RedCloth.new(output.join("\n\n")).to_html
>+puts "</body></html>"
>-- 
>1.7.2.2
>

-- 
--------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org
--------------------------------------------------------

Mime
View raw message