Commit 1bf49c9034b999def3fc82288d0fa96a72cdb8de

Authored by Aurélio A. Heckert
Committed by Rodrigo Souto
1 parent cc60c41d

Basic API autodoc

Lists EndPoints at /api
app/controllers/public/api_controller.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class ApiController < PublicController
  2 +
  3 + no_design_blocks
  4 +
  5 + def index
  6 + @api = Noosfero::API.api_class
  7 + end
  8 +
  9 +end
... ...
app/views/api/index.html.erb 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +<h1>EndPoints</h1>
  2 +
  3 +<%= @api.endpoints.map do |endpoint|
  4 + app = endpoint.options[:app].to_s
  5 + unless app.blank?
  6 + content_tag(:h2, app.split('::').last.to_s, title: app) +
  7 + (content_tag :ul do
  8 + endpoint.routes.map do |route|
  9 + content_tag :li do
  10 + content_tag(:strong, route.route_method) + ' ' +
  11 + route.route_path.gsub(':version', content_tag(:b, route.route_version))
  12 + end
  13 + end.join "\n"
  14 + end)
  15 + end
  16 +end.join "\n" %>
... ...
config/routes.rb
... ... @@ -22,6 +22,7 @@ Noosfero::Application.routes.draw do
22 22 root :to => 'home#index', :constraints => EnvironmentDomainConstraint.new
23 23  
24 24 match 'site(/:action)', :controller => 'home'
  25 + match 'api(/:action)', :controller => 'api'
25 26  
26 27 match 'images(/*stuff)' => 'not_found#nothing'
27 28 match 'stylesheets(/*stuff)' => 'not_found#nothing'
... ...
lib/noosfero/api/api.rb
... ... @@ -45,5 +45,8 @@ module Noosfero
45 45 end
46 46 end
47 47 end
  48 + def self.api_class
  49 + API
  50 + end
48 51 end
49 52 end
... ...