diff options
Diffstat (limited to 'src/guff/views/html/api-docs.cr')
-rw-r--r-- | src/guff/views/html/api-docs.cr | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/guff/views/html/api-docs.cr b/src/guff/views/html/api-docs.cr new file mode 100644 index 0000000..0b5aff3 --- /dev/null +++ b/src/guff/views/html/api-docs.cr @@ -0,0 +1,71 @@ +require "html" +require "ecr/macros" +require "../../api/methods" +require "./page" + +class Guff::APIDocsHTMLView + TITLE = "Guff API Documentation" + + def self.run(context : HTTP::Server::Context) + page = PageHTMLView.new(TITLE, new.to_s) + context.response.content_type = page.content_type + context.response.puts page + end + + private def namespaces + API::Methods::METHODS.keys.sort + end + + private def methods( + namespace : String + ) + API::Methods::METHODS[namespace].keys.sort + end + + private def method_text( + namespace : String, + method : String + ) + API::Methods::METHODS[namespace][method][:text] as String + end + + private def method_args( + namespace : String, + method : String + ) + if method_has_args?(namespace, method) + args = API::Methods::METHODS[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 = API::Methods::METHODS[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 + ) + API::Methods::METHODS[namespace][method].has_key?(:args) + end + + def h(s : String) + HTML.escape(s || "") + end + + ECR.def_to_s("./src/guff/views/ecrs/api-docs.ecr") +end |