start working on general docs
This commit is contained in:
parent
e9474652a8
commit
72dae6867c
7
docs/00_overview.md
Normal file
7
docs/00_overview.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
# Overview
|
||||
|
||||
... some general docs here ...
|
||||
|
||||
## Media Types
|
||||
|
||||
The API is currently JSON only.
|
23
docs/01_cross_origin.md
Normal file
23
docs/01_cross_origin.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Web Clients
|
||||
|
||||
When write an in-browsers client, you have to circumvent the browser's
|
||||
[same origin policy](http://en.wikipedia.org/wiki/Same_origin_policy).
|
||||
Generally, we offer two different approaches for this:
|
||||
[Cross-Origin Resource Sharing](http://en.wikipedia.org/wiki/CORS) (aka CORS)
|
||||
and [JSONP](http://en.wikipedia.org/wiki/JSONP). If you don't have any good
|
||||
reason for using JSONP, we recommend you use CORS.
|
||||
|
||||
## Cross-Origin Resource Sharing
|
||||
|
||||
... some general docs here ...
|
||||
|
||||
In contrast to JSONP, CORS does not lead to any execution of untrusted code.
|
||||
|
||||
Most JavaScript frameworks, like [jQuery](http://jquery.com), take care of CORS
|
||||
requests for you under the hood, so you can just do a normal *ajax* request.
|
||||
|
||||
Our current setup allows the headers `Content-Type`, `Authorization`, `Accept` and the HTTP methods `HEAD`, `GET`, `POST`, `PATCH`, `PUT`, `DELETE`.
|
||||
|
||||
## JSONP
|
||||
|
||||
... some docs here ...
|
|
@ -11,7 +11,12 @@ class Travis::Api::App
|
|||
get '/' do
|
||||
content_type :html
|
||||
endpoints = Endpoints.endpoints
|
||||
erb :index, {}, :endpoints => endpoints.keys.sort.map { |k| endpoints[k] }
|
||||
erb :index, {}, endpoints: endpoints.keys.sort.map { |k| endpoints[k] }
|
||||
end
|
||||
|
||||
get '/x' do
|
||||
content_type :html
|
||||
general_docs
|
||||
end
|
||||
|
||||
helpers do
|
||||
|
@ -38,6 +43,29 @@ class Travis::Api::App
|
|||
gsub(/<\/?code>/, '').
|
||||
gsub(/TODO:?/, '<span class="label label-warning">TODO</span>')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def general_docs
|
||||
@@general_docs ||= doc_files.map do |file|
|
||||
header, content = File.read(file).split("\n", 2)
|
||||
content = markdown(content)
|
||||
subheaders = []
|
||||
|
||||
content.gsub!(/<h2>(.*)<\/h2>/) do
|
||||
subheaders << $1
|
||||
"<h2 id=\"#{$1}\">#{$1}</h2>"
|
||||
end
|
||||
|
||||
header.gsub! /^#* */, ''
|
||||
{ id: header, title: header, content: content, subheaders: subheaders }
|
||||
end
|
||||
end
|
||||
|
||||
def doc_files
|
||||
pattern = File.expand_path('../../../../../../docs/*.md', __FILE__)
|
||||
Dir[pattern].sort
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -118,6 +146,13 @@ __END__
|
|||
</div>
|
||||
<div class="well" style="padding: 8px 0;">
|
||||
<ul class="nav nav-list">
|
||||
<% general_docs.each do |doc| %>
|
||||
<li class="nav-header"><a href="#<%= doc[:id] %>"><%= doc[:title] %></a></li>
|
||||
<% doc[:subheaders].each do |sub| %>
|
||||
<li><a href="#<%= sub %>"><%= sub %></a></li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<li class="divider"></li>
|
||||
<% endpoints.each do |endpoint| %>
|
||||
<li class="nav-header"><a href="#<%= endpoint['name'] %>"><%= endpoint['name'] %></a></li>
|
||||
<% endpoint['routes'].each do |route| %>
|
||||
|
@ -163,29 +198,15 @@ __END__
|
|||
|
||||
<section class="span9">
|
||||
|
||||
<% general_docs.each do |doc| %>
|
||||
<%= erb :entry, locals: doc %>
|
||||
<% end %>
|
||||
|
||||
<% endpoints.each do |endpoint| %>
|
||||
<div id="<%= endpoint['name'] %>">
|
||||
<div class="page-header">
|
||||
<h1>
|
||||
<a href="#<%= endpoint['name'] %>"><%= endpoint['name'] %></a>
|
||||
</h1>
|
||||
</div>
|
||||
<% unless endpoint['doc'].to_s.empty? %>
|
||||
<%= docs_for endpoint %>
|
||||
<hr>
|
||||
<% end %>
|
||||
<% endpoint['routes'].each do |route| %>
|
||||
<div class="route" id="<%= slug_for(route) %>">
|
||||
<pre><h3><%= route['verb'] %> <%= route['uri'] %></h3></pre>
|
||||
<% if route['scope'] %>
|
||||
<p>
|
||||
<h5>Required autorization scope: <span class="label"><%= route['scope'] %></span></h5>
|
||||
</p>
|
||||
<% end %>
|
||||
<%= docs_for route %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<%= erb :entry, {},
|
||||
id: endpoint['name'],
|
||||
title: endpoint['name'],
|
||||
content: erb(:endpoint_content, {}, endpoint: endpoint) %>
|
||||
<% end %>
|
||||
|
||||
</section>
|
||||
|
@ -193,3 +214,31 @@ __END__
|
|||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ endpoint_content
|
||||
<% unless endpoint['doc'].to_s.empty? %>
|
||||
<%= docs_for endpoint %>
|
||||
<hr>
|
||||
<% end %>
|
||||
<% endpoint['routes'].each do |route| %>
|
||||
<div class="route" id="<%= slug_for(route) %>">
|
||||
<pre><h3><%= route['verb'] %> <%= route['uri'] %></h3></pre>
|
||||
<% if route['scope'] %>
|
||||
<p>
|
||||
<h5>Required autorization scope: <span class="label"><%= route['scope'] %></span></h5>
|
||||
</p>
|
||||
<% end %>
|
||||
<%= docs_for route %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ entry
|
||||
<div id="<%= id %>">
|
||||
<div class="page-header">
|
||||
<h1>
|
||||
<a href="#<%= id %>"><%= title %></a>
|
||||
</h1>
|
||||
</div>
|
||||
<%= content %>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user