From 3fff685c444672cfbc1f8d8d2d9432b905c67686 Mon Sep 17 00:00:00 2001 From: Yun Xu Date: Sat, 1 Jul 2017 23:46:34 -0700 Subject: [PATCH] add auto-doc support --- docs/conf.py | 13 +++++++++++++ docs/sanic/request_data.md | 8 ++++++++ docs/sanic/response.md | 8 ++++++++ docs/sanic/routing.md | 1 - sanic/response.py | 4 ++++ sanic/router.py | 9 +++++++++ 6 files changed, 42 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index c97f3c19..33f5097d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -13,6 +13,9 @@ import sys # Add support for Markdown documentation using Recommonmark from recommonmark.parser import CommonMarkParser +# Add support for auto-doc +from recommonmark.transform import AutoStructify + # Ensure that sanic is present in the path, to allow sphinx-apidoc to # autogenerate documentation from docstrings root_directory = os.path.dirname(os.getcwd()) @@ -140,3 +143,13 @@ epub_exclude_files = ['search.html'] # -- Custom Settings ------------------------------------------------------- suppress_warnings = ['image.nonlocal_uri'] + + +# app setup hook +def setup(app): + app.add_config_value('recommonmark_config', { + 'auto_toc_tree_section': 'Contents', + 'enable_eval_rst': True, + 'enable_auto_doc_ref': True, + }, True) + app.add_transform(AutoStructify) diff --git a/docs/sanic/request_data.md b/docs/sanic/request_data.md index bf5ae4a8..82bf19c9 100644 --- a/docs/sanic/request_data.md +++ b/docs/sanic/request_data.md @@ -117,3 +117,11 @@ args.get('titles') # => 'Post 1' args.getlist('titles') # => ['Post 1', 'Post 2'] ``` + + +## Full API Reference + +```eval_rst +.. autoclass:: sanic.request.Request + :members: json, token, form, files, args, raw_args, cookies, ip, scheme, host, content_type, path, query_string, url +``` \ No newline at end of file diff --git a/docs/sanic/response.md b/docs/sanic/response.md index 9c3c95f7..91e0da83 100644 --- a/docs/sanic/response.md +++ b/docs/sanic/response.md @@ -110,3 +110,11 @@ def handle_request(request): status=200 ) ``` + + +## Full API Reference + +```eval_rst +.. automodule:: sanic.response + :members: json, text, raw, html, file, file_stream, stream, redirect +``` \ No newline at end of file diff --git a/docs/sanic/routing.md b/docs/sanic/routing.md index 9b4d060f..e039e249 100644 --- a/docs/sanic/routing.md +++ b/docs/sanic/routing.md @@ -214,4 +214,3 @@ and `recv` methods to send and receive data respectively. WebSocket support requires the [websockets](https://github.com/aaugustin/websockets) package by Aymeric Augustin. - diff --git a/sanic/response.py b/sanic/response.py index ea233d9a..f4fb1ea6 100644 --- a/sanic/response.py +++ b/sanic/response.py @@ -237,6 +237,7 @@ def json(body, status=200, headers=None, content_type="application/json", **kwargs): """ Returns response object with body in json format. + :param body: Response data to be serialized. :param status: Response code. :param headers: Custom Headers. @@ -250,6 +251,7 @@ def text(body, status=200, headers=None, content_type="text/plain; charset=utf-8"): """ Returns response object with body in text format. + :param body: Response data to be encoded. :param status: Response code. :param headers: Custom Headers. @@ -264,6 +266,7 @@ def raw(body, status=200, headers=None, content_type="application/octet-stream"): """ Returns response object without encoding the body. + :param body: Response data. :param status: Response code. :param headers: Custom Headers. @@ -276,6 +279,7 @@ def raw(body, status=200, headers=None, def html(body, status=200, headers=None): """ Returns response object with body in html format. + :param body: Response data to be encoded. :param status: Response code. :param headers: Custom Headers. diff --git a/sanic/router.py b/sanic/router.py index 691f1388..ce491881 100644 --- a/sanic/router.py +++ b/sanic/router.py @@ -99,7 +99,16 @@ class Router: return name, _type, pattern def add(self, uri, methods, handler, host=None, strict_slashes=False): + """Add a handler to the route list + :param uri: path to match + :param methods: sequence of accepted method names. If none are + provided, any method is allowed + :param handler: request handler function. + When executed, it should provide a response object. + :param strict_slashes: strict to trailing slash + :return: Nothing + """ # add regular version self._add(uri, methods, handler, host)