From 1bf49c9034b999def3fc82288d0fa96a72cdb8de Mon Sep 17 00:00:00 2001 From: Aurélio A. Heckert Date: Tue, 26 May 2015 19:16:38 -0300 Subject: [PATCH] Basic API autodoc --- app/controllers/public/api_controller.rb | 9 +++++++++ app/views/api/index.html.erb | 16 ++++++++++++++++ config/routes.rb | 1 + lib/noosfero/api/api.rb | 3 +++ 4 files changed, 29 insertions(+), 0 deletions(-) create mode 100644 app/controllers/public/api_controller.rb create mode 100644 app/views/api/index.html.erb diff --git a/app/controllers/public/api_controller.rb b/app/controllers/public/api_controller.rb new file mode 100644 index 0000000..5062771 --- /dev/null +++ b/app/controllers/public/api_controller.rb @@ -0,0 +1,9 @@ +class ApiController < PublicController + + no_design_blocks + + def index + @api = Noosfero::API.api_class + end + +end diff --git a/app/views/api/index.html.erb b/app/views/api/index.html.erb new file mode 100644 index 0000000..2aa83c1 --- /dev/null +++ b/app/views/api/index.html.erb @@ -0,0 +1,16 @@ +

EndPoints

+ +<%= @api.endpoints.map do |endpoint| + app = endpoint.options[:app].to_s + unless app.blank? + content_tag(:h2, app.split('::').last.to_s, title: app) + + (content_tag :ul do + endpoint.routes.map do |route| + content_tag :li do + content_tag(:strong, route.route_method) + ' ' + + route.route_path.gsub(':version', content_tag(:b, route.route_version)) + end + end.join "\n" + end) + end +end.join "\n" %> diff --git a/config/routes.rb b/config/routes.rb index 76ca289..1aae0d4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -22,6 +22,7 @@ Noosfero::Application.routes.draw do root :to => 'home#index', :constraints => EnvironmentDomainConstraint.new match 'site(/:action)', :controller => 'home' + match 'api(/:action)', :controller => 'api' match 'images(/*stuff)' => 'not_found#nothing' match 'stylesheets(/*stuff)' => 'not_found#nothing' diff --git a/lib/noosfero/api/api.rb b/lib/noosfero/api/api.rb index 2fe0adf..3b81f4d 100644 --- a/lib/noosfero/api/api.rb +++ b/lib/noosfero/api/api.rb @@ -45,5 +45,8 @@ module Noosfero end end end + def self.api_class + API + end end end -- libgit2 0.21.2