Skip to content

Commit 6df5b81

Browse files
author
Arnaud Coomans
committed
Merge pull request #12 from acoomans/development
Development
2 parents 1791d09 + e4d58f4 commit 6df5b81

File tree

15 files changed

+398
-233
lines changed

15 files changed

+398
-233
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
language: python
22
python:
33
- "2.7"
4+
- "3.3"
5+
- "3.4"
46
install:
57
- pip install -r requirements.txt
68
script:

README.md

Lines changed: 72 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
Flask-Autodoc
22
=============
33

4-
Flask Autodoc is a Flask extension that automatically creates documentation for your endpoints based on the routes,
5-
function arguments and docstring.
4+
Flask-Autodoc is a Flask extension that automatically creates documentation for your endpoints based on the routes, function arguments and docstrings.
65

7-
[![Build Status](https://api.travis-ci.org/acoomans/flask-autodoc.png)](https://travis-ci.org/acoomans/flask-autodoc)
6+
[![Build](https://api.travis-ci.org/acoomans/flask-autodoc.png)](https://travis-ci.org/acoomans/flask-autodoc)
7+
[![Pypi version](http://img.shields.io/pypi/v/flask-autodoc.svg)](https://pypi.python.org/pypi/Flask-Autodoc)
8+
[![Pypi license](http://img.shields.io/pypi/l/flask-autodoc.svg)](https://pypi.python.org/pypi/Flask-Autodoc)
9+
![Python 2](http://img.shields.io/badge/python-2-blue.svg)
10+
![Python 3](http://img.shields.io/badge/python-3-blue.svg)
11+
12+
13+
## Requirements
14+
15+
Flask-Autodoc is compatible with Python versions 2 and 3; and it depends only on Flask.
816

917
## Install
1018

11-
To install Flask-Autodoc:
19+
To install Flask-Autodoc, run pip:
20+
21+
pip install flask-autodoc
22+
23+
or clone this directory and run setup:
1224

1325
python setup.py install
1426

@@ -22,28 +34,28 @@ Start using Flask-Autodoc by importing it and initializing it:
2234
app = Flask(__name__)
2335
auto = Autodoc(app)
2436

25-
by default, Flask-Autodoc will only document the routes you explicitly tell him to with the _doc_ decorator,
26-
like this:
37+
by default, Flask-Autodoc will only document the routes explicitly decorated with _doc_:
2738

2839
@app.route('/user/<int:id>')
2940
@auto.doc()
3041
def show_user(id):
31-
"""This returns a user with a given id."""
3242
return user_from_database(id)
3343

34-
to generate the documentation from an endpoint, use the _html()_ method:
44+
to generate the documentation, use the _html()_ method:
3545

3646
@app.route('/documentation')
3747
def documentation():
3848
return auto.html()
3949

40-
if you to access the documentation without it being rendered in html:
50+
## Custom documentation
51+
52+
To access the documentation without rendering html:
4153

4254
@app.route('/documentation')
4355
def documentation():
4456
return auto.generate()
4557

46-
the documentation will then be returned as a list of rules, where each rule is a dictionary containing:
58+
the documentation will be returned as a list of rules, where each rule is a dictionary containing:
4759

4860
- methods: the set of allowed methods (ie ['GET', 'POST'])
4961
- rule: relative url (ie '/user/<int:id>')
@@ -52,27 +64,67 @@ the documentation will then be returned as a list of rules, where each rule is a
5264
- args: function arguments
5365
- defaults: defaults values for the arguments
5466

55-
## Groups
67+
## Custom template
68+
69+
To use a custom template for your documentation, give a _template_ argument to the _html_ method. This will use a template from the flask _templates_ directory.
70+
71+
Additionnal arguments (other than _group_, _groups_, and _template_) will be passed down to the template:
72+
73+
auto.html(
74+
75+
template='custom_documentation.html'
76+
77+
title='My Documentation',
78+
author='John Doe',
79+
)
80+
5681

57-
You may want to group endpoints together, to have different documentation sets. With this you can for example, only
58-
show some endpoints to third party developer and have full documentation for your own.
82+
_title_ and _author_ will be available in the template:
5983

60-
to assign an endpoint to a group, pass the name of the group as argument of the _doc_ decorator:
84+
<!-- templates/custom_documentation.html -->
85+
...
86+
{% if title is defined %}
87+
{{title}}
88+
{% endif %}
89+
...
90+
91+
## Documentation sets
92+
93+
Endpoints can be grouped together in different documentation sets. It is possible for instance to show some endpoints to third party developers and have full documentation for primary developers.
94+
95+
To assign an endpoint to a group, pass the name of the group as argument of the _doc_ decorator:
6196

6297
@app.route('/user/<int:id>')
63-
@auto.doc("public")
98+
@auto.doc('public')
6499
def show_user(id):
65100

66101
to assign an endpoint to multiple groups, pass a list of group names as the _groups_ argument to _doc_:
67102

68103
@app.route('/user/<int:id>')
69-
@auto.doc(groups=["public","private"])
104+
@auto.doc(groups=['public','private'])
70105
def show_user(id):
71106

72-
to generate the documentation for a specific group, pass the name of the group to the _generate_ or _html_ methods:
107+
to generate the documentation for a specific group, pass the name of the group to the _html_ or _generate_ methods:
108+
109+
auto.html('public')
110+
auto.html(groups=['public','private'])
111+
auto.generate('public')
112+
113+
## Examples
114+
115+
Apps in the _examples_ directory are an api for a blog:
116+
117+
- _simple_ is a simple app
118+
- _factory_ uses blueprints
119+
120+
Run with
121+
122+
python simple/blog.py
123+
124+
and connect to [/doc/public](http://127.0.0.1:5000/doc/public) and [/doc/private](http://127.0.0.1:5000/doc/private) to see public and private documentations.
73125

74-
auto.generate("public")
126+
## Screenshots
75127

76-
or
128+
![screenshots](Screenshots/screenshot00.png)
77129

78-
auto.html("public")
130+
![screenshots](Screenshots/screenshot01.png)

examples/blog.py

Lines changed: 0 additions & 82 deletions
This file was deleted.

examples/factory/app.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from flask import Flask
2-
from flask.ext.autodoc import Autodoc
2+
33

44
def create_app(config_filename=None):
55
app = Flask(__name__)
@@ -18,6 +18,7 @@ def create_app(config_filename=None):
1818

1919
return app
2020

21-
if __name__ == "__main__":
21+
22+
if __name__ == '__main__':
2223
app = create_app()
23-
app.run()
24+
app.run()

examples/factory/blog/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from admin import admin
2-
from frontend import frontend
3-
from doc import doc, auto
1+
from .admin import admin
2+
from .frontend import frontend
3+
from .doc import doc, auto

examples/factory/blog/admin.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
from flask import current_app, Blueprint, render_template
2-
from flask.ext.autodoc import Autodoc
1+
from flask import Blueprint
2+
3+
from .doc import auto
4+
35

46
admin = Blueprint('admin', __name__, url_prefix='/admin')
5-
from doc import auto
7+
68

79
@admin.route('/')
810
@auto.doc(groups=['private'])
911
def index():
1012
"""Admin interface."""
11-
return "Admin interface"
13+
return 'Admin interface'

examples/factory/blog/doc.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
from flask import current_app, Blueprint, render_template
1+
from flask import Blueprint
22
from flask.ext.autodoc import Autodoc
33

4+
45
doc = Blueprint('doc', __name__, url_prefix='/doc')
56
auto = Autodoc()
67

8+
79
@doc.route('/')
810
@doc.route('/public')
911
def public_doc():
10-
return auto.html(groups=["public"], title="Blog Documentation")
12+
return auto.html(groups=['public'], title='Blog Documentation')
13+
1114

1215
@doc.route('/private')
1316
def private_doc():
14-
return auto.html(groups=["private"], title="Private Documentation")
17+
return auto.html(groups=['private'], title='Private Documentation')

0 commit comments

Comments
 (0)