Skip to content

Commit c3dd7b8

Browse files
committed
rewrite tutorial docs and example
1 parent 16d83d6 commit c3dd7b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+3340
-2237
lines changed

CONTRIBUTING.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ First time setup
7575
.. _latest version of git: https://git-scm.com/downloads
7676
.. _username: https://help.github.com/articles/setting-your-username-in-git/
7777
.. _email: https://help.github.com/articles/setting-your-email-in-git/
78-
.. _Fork: https://github.com/pallets/flask/pull/2305#fork-destination-box
78+
.. _Fork: https://github.com/pallets/flask/fork
7979
.. _Clone: https://help.github.com/articles/fork-a-repo/#step-2-create-a-local-clone-of-your-fork
8080

8181
Start coding

docs/_static/flaskr.png

-64.7 KB
Binary file not shown.

docs/conf.py

+35-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
# All configuration values have a default; values that are commented out
1212
# serve to show the default.
1313
from __future__ import print_function
14+
15+
import datetime
1416
import os
1517
import sys
16-
import pkg_resources
1718
import time
18-
import datetime
1919

20-
from sphinx.application import Sphinx
20+
import pkg_resources
2121

2222
BUILD_DATE = datetime.datetime.utcfromtimestamp(int(os.environ.get('SOURCE_DATE_EPOCH', time.time())))
2323

@@ -300,7 +300,7 @@ def update_wrapper(wrapper, wrapped, *a, **kw):
300300
del unwrap_decorators
301301

302302

303-
def setup(app: Sphinx):
303+
def setup(app):
304304
def cut_module_meta(app, what, name, obj, options, lines):
305305
"""Remove metadata from autodoc output."""
306306
if what != 'module':
@@ -312,3 +312,34 @@ def cut_module_meta(app, what, name, obj, options, lines):
312312
]
313313

314314
app.connect('autodoc-process-docstring', cut_module_meta)
315+
316+
def github_link(
317+
name, rawtext, text, lineno, inliner,
318+
options=None, content=None
319+
):
320+
app = inliner.document.settings.env.app
321+
release = app.config.release
322+
base_url = 'https://github.com/pallets/flask/tree/'
323+
324+
if text.endswith('>'):
325+
words, text = text[:-1].rsplit('<', 1)
326+
words = words.strip()
327+
else:
328+
words = None
329+
330+
if release.endswith('dev'):
331+
url = '{0}master/{1}'.format(base_url, text)
332+
else:
333+
url = '{0}{1}/{2}'.format(base_url, release, text)
334+
335+
if words is None:
336+
words = url
337+
338+
from docutils.nodes import reference
339+
from docutils.parsers.rst.roles import set_classes
340+
options = options or {}
341+
set_classes(options)
342+
node = reference(rawtext, words, refuri=url, **options)
343+
return [node], []
344+
345+
app.add_role('gh', github_link)

docs/installation.rst

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ On Windows:
104104
105105
\Python27\Scripts\virtualenv.exe venv
106106
107+
.. _install-activate-env:
108+
107109
Activate the environment
108110
~~~~~~~~~~~~~~~~~~~~~~~~
109111

docs/patterns/jquery.rst

+2-4
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,5 @@ explanation of the little bit of code above:
162162
argument. Note that we can use the `$SCRIPT_ROOT` variable here that
163163
we set earlier.
164164

165-
If you don't get the whole picture, download the `sourcecode
166-
for this example
167-
<https://github.com/pallets/flask/tree/master/examples/jqueryexample>`_
168-
from GitHub.
165+
If you don't get the whole picture, download the :gh:`sourcecode
166+
for this example <examples/jqueryexample>`.

docs/patterns/packages.rst

+7-9
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ this::
1717
login.html
1818
...
1919

20-
If you find yourself stuck on something, feel free
21-
to take a look at the source code for this example.
22-
You'll find `the full src for this example here`_.
20+
The :ref:`tutorial <tutorial>` is structured this way, see the
21+
:gh:`example code <examples/tutorial>`.
2322

2423
Simple Packages
2524
---------------
@@ -59,21 +58,21 @@ a big problem, just add a new file called :file:`setup.py` next to the inner
5958
],
6059
)
6160

62-
In order to run the application you need to export an environment variable
63-
that tells Flask where to find the application instance::
61+
In order to run the application you need to export an environment variable
62+
that tells Flask where to find the application instance::
6463

6564
export FLASK_APP=yourapplication
6665

67-
If you are outside of the project directory make sure to provide the exact
66+
If you are outside of the project directory make sure to provide the exact
6867
path to your application directory. Similarly you can turn on the
6968
development features like this::
7069

7170
export FLASK_ENV=development
7271

73-
In order to install and run the application you need to issue the following
72+
In order to install and run the application you need to issue the following
7473
commands::
7574

76-
pip install -e .
75+
pip install -e .
7776
flask run
7877

7978
What did we gain from this? Now we can restructure the application a bit
@@ -134,7 +133,6 @@ You should then end up with something like that::
134133

135134

136135
.. _working-with-modules:
137-
.. _the full src for this example here: https://github.com/pallets/flask/tree/master/examples/patterns/largerapp
138136

139137
Working with Blueprints
140138
-----------------------

docs/testing.rst

+1-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ The Application
2828

2929
First, we need an application to test; we will use the application from
3030
the :ref:`tutorial`. If you don't have that application yet, get the
31-
source code from `the examples`_.
32-
33-
.. _the examples:
34-
https://github.com/pallets/flask/tree/master/examples/flaskr/
31+
source code from :gh:`the examples <examples/tutorial>`.
3532

3633
The Testing Skeleton
3734
--------------------

0 commit comments

Comments
 (0)