aboutsummaryrefslogtreecommitdiff
path: root/src/guff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2016-03-06 02:10:29 -0500
committerPaul Duncan <pabs@pablotron.org>2016-03-06 02:10:29 -0500
commit2421d5f15569515d9fda3c6f36edeaf7e5222b54 (patch)
treea9c5d8cdf8eb7154435c450a7a63ed29d98f5836 /src/guff
parent845049cc77426ddf14d351b9d548b1fbb53925d1 (diff)
downloadold-guff-2421d5f15569515d9fda3c6f36edeaf7e5222b54.tar.bz2
old-guff-2421d5f15569515d9fda3c6f36edeaf7e5222b54.zip
add api-docs
Diffstat (limited to 'src/guff')
-rw-r--r--src/guff/api-docs-html-view.cr30
-rw-r--r--src/guff/api-handler.cr8
-rw-r--r--src/guff/views/api-docs.ecr32
3 files changed, 63 insertions, 7 deletions
diff --git a/src/guff/api-docs-html-view.cr b/src/guff/api-docs-html-view.cr
new file mode 100644
index 0000000..e3f1097
--- /dev/null
+++ b/src/guff/api-docs-html-view.cr
@@ -0,0 +1,30 @@
+require "html"
+require "ecr/macros"
+require "./html-page-view"
+require "./api-methods"
+
+module Guff
+ class APIDocsHTMLView
+ TITLE = "Guff API Documentation"
+
+ def self.run(context : HTTP::Server::Context)
+ page = HTMLPageView.new(TITLE, new.to_s)
+ context.response.content_type = page.content_type
+ context.response.puts page
+ end
+
+ private def namespaces
+ APIMethods::API.keys.sort
+ end
+
+ private def methods(namespace : String)
+ APIMethods::API[namespace].keys.sort
+ end
+
+ def h(s : String)
+ HTML.escape(s || "")
+ end
+
+ ECR.def_to_s("./src/guff/views/api-docs.ecr")
+ end
+end
diff --git a/src/guff/api-handler.cr b/src/guff/api-handler.cr
index 2b4cfb0..ad78706 100644
--- a/src/guff/api-handler.cr
+++ b/src/guff/api-handler.cr
@@ -110,13 +110,7 @@ module Guff
end
private def do_docs(context : HTTP::Server::Context)
- page = HTMLPageView.new(
- "API Documentation",
- "<p>API Documentation</p>"
- )
-
- context.response.content_type = page.content_type
- context.response.puts page
+ APIDocsHTMLView.run(context)
end
end
end
diff --git a/src/guff/views/api-docs.ecr b/src/guff/views/api-docs.ecr
new file mode 100644
index 0000000..8611285
--- /dev/null
+++ b/src/guff/views/api-docs.ecr
@@ -0,0 +1,32 @@
+<h1><%= TITLE %></h1>
+
+<div class='section'>
+<h2>Table of Contents</h2>
+<ul><% namespaces.each do |namespace| %>
+ <li>
+ <%= namespace %>
+ <ul><% methods(namespace).each do |method| %>
+ <li>
+ <a
+ href='#m-<%= namespace %>-<%= method %>'
+ title='View <%= namespace %>/<%= method %> details.'
+ >
+ <%= method %>
+ </a>
+ </li>
+ <% end %></ul>
+ </li>
+<% end %></ul>
+</div><!-- section -->
+
+<% namespaces.each do |namespace| %>
+ <% methods(namespace).each do |method| %>
+ <div id='m-<%= namespace %>-<%= method %>' class='section'>
+ <b><%= namespace %>/<%= method %></b>
+
+ <p><%=
+ h(APIMethods::API[namespace][method][:text] as String)
+ %></p>
+ </div><!-- section -->
+ <% end %>
+<% end %>