From 02668d640f714dc27dbb14fcddbf04a63bed7c85 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sun, 6 Mar 2016 02:42:51 -0500 Subject: populate more of api docs --- src/guff/api-docs-html-view.cr | 45 +++++++++++++++++++++++++- src/guff/views/api-docs.ecr | 72 ++++++++++++++++++++++++++++-------------- 2 files changed, 92 insertions(+), 25 deletions(-) diff --git a/src/guff/api-docs-html-view.cr b/src/guff/api-docs-html-view.cr index 83c28d0..5fdbd86 100644 --- a/src/guff/api-docs-html-view.cr +++ b/src/guff/api-docs-html-view.cr @@ -17,10 +17,53 @@ module Guff APIMethods::API.keys.sort end - private def methods(namespace : String) + private def methods( + namespace : String + ) APIMethods::API[namespace].keys.sort end + private def method_text( + namespace : String, + method : String + ) + APIMethods::API[namespace][method][:text] as String + end + + private def method_args( + namespace : String, + method : String + ) + if method_has_args?(namespace, method) + args = APIMethods::API[namespace][method][:args] as \ + Hash(String, Hash(Symbol, String|Symbol|Bool)) | Nil + args.keys.sort + else + [] of String + end + end + + private def arg_text( + namespace : String, + method : String, + name : String + ) : String + if method_has_args?(namespace, method) + arg = APIMethods::API[namespace][method][:args][name] as\ + Hash(Symbol, String|Symbol|Bool) + arg[:text] as String + else + "" + end + end + + private def method_has_args?( + namespace : String, + method : String + ) + APIMethods::API[namespace][method].has_key?(:args) + end + def h(s : String) HTML.escape(s || "") end diff --git a/src/guff/views/api-docs.ecr b/src/guff/views/api-docs.ecr index 8611285..8ab9cc0 100644 --- a/src/guff/views/api-docs.ecr +++ b/src/guff/views/api-docs.ecr @@ -1,32 +1,56 @@

<%= TITLE %>

-

Table of Contents

- +

Table of Contents

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

<%= namespace %> methods

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

<%= namespace %>/<%= method %>

+ +

Description

+

+ <%= h(method_text(namespace, method)) %> +

-

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

-
- <% end %> +

Parameters

+
    <% method_args(namespace, method).each do |arg| %> +
  • + <%= arg %>: + <%= h(arg_text(namespace, method, arg)) %> +
  • + <% end %>
+
+ <% end %> +
<% end %> -- cgit v1.2.3