From 2421d5f15569515d9fda3c6f36edeaf7e5222b54 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sun, 6 Mar 2016 02:10:29 -0500 Subject: add api-docs --- src/guff/api-docs-html-view.cr | 30 ++++++++++++++++++++++++++++++ src/guff/api-handler.cr | 8 +------- src/guff/views/api-docs.ecr | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 src/guff/api-docs-html-view.cr create mode 100644 src/guff/views/api-docs.ecr (limited to 'src') 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", - "

API Documentation

" - ) - - 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 @@ +

<%= TITLE %>

+ +
+

Table of Contents

+ +
+ +<% namespaces.each do |namespace| %> + <% methods(namespace).each do |method| %> +
+ <%= namespace %>/<%= method %> + +

<%= + h(APIMethods::API[namespace][method][:text] as String) + %>

+
+ <% end %> +<% end %> -- cgit v1.2.3