From 35561110e8f52ad0ab03d40dcc64d88e654aeff5 Mon Sep 17 00:00:00 2001 From: Jordan Cook Date: Tue, 13 Apr 2021 13:53:00 -0500 Subject: Include example scripts on readthedocs --- docs/_static/collapsible_container.css | 26 ++++++++++++ docs/_templates/page.html | 15 +++++++ docs/conf.py | 5 +++ docs/examples.rst | 73 ++++++++++++++++++++++++++++++++++ docs/index.rst | 1 + docs/related_projects.rst | 2 + 6 files changed, 122 insertions(+) create mode 100644 docs/_static/collapsible_container.css create mode 100644 docs/_templates/page.html create mode 100644 docs/examples.rst (limited to 'docs') diff --git a/docs/_static/collapsible_container.css b/docs/_static/collapsible_container.css new file mode 100644 index 0000000..65542e2 --- /dev/null +++ b/docs/_static/collapsible_container.css @@ -0,0 +1,26 @@ +/* Taken from: https://github.com/plone/training/blob/master/_static/custom.css */ + +.toggle { + background: none repeat scroll 0 0 #e7f2fa; + padding: 12px; + line-height: 24px; + margin-bottom: 24px; +} + +.toggle .admonition-title { + display: block; + clear: both; + cursor: pointer; +} + +.toggle .admonition-title:after { + content: " ▶"; +} + +.toggle .admonition-title.open:after { + content: " ▼"; +} + +.toggle p:last-child { + margin-bottom: 0; +} diff --git a/docs/_templates/page.html b/docs/_templates/page.html new file mode 100644 index 0000000..724739b --- /dev/null +++ b/docs/_templates/page.html @@ -0,0 +1,15 @@ +{# Taken from: https://github.com/plone/training/blob/master/_templates/page.html #} +{% extends "!page.html" %} + +{% block footer %} + +{% endblock %} diff --git a/docs/conf.py b/docs/conf.py index cd7df64..6d92cad 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -65,3 +65,8 @@ autosectionlabel_prefix_document = True # HTML theme settings pygments_style = 'sphinx' html_theme = 'sphinx_rtd_theme' + + +def setup(app): + """Run some additional steps after the Sphinx builder is initialized""" + app.add_css_file('collapsible_container.css') diff --git a/docs/examples.rst b/docs/examples.rst new file mode 100644 index 0000000..daf2ee4 --- /dev/null +++ b/docs/examples.rst @@ -0,0 +1,73 @@ +Examples +-------- +This section contains some complete examples that demonstrate the main features of requests-cache. + +These can also be found in the +`examples/ `_ folder on GitHub. + + +Basic usage (with sessions) +~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.. include:: ../examples/log_requests.py + :start-line: 2 + :end-line: 3 + +.. admonition:: Example code + :class: toggle + + .. literalinclude:: ../examples/basic_usage.py + :lines: 1,6- + + +Basic usage (with patching) +~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.. include:: ../examples/session_patch.py + :start-line: 3 + :end-line: 4 + +.. admonition:: Example code + :class: toggle + + .. literalinclude:: ../examples/session_patch.py + :lines: 1,6- + + +Cache expiration +~~~~~~~~~~~~~~~~ +.. include:: ../examples/expiration.py + :start-line: 2 + :end-line: 3 + +.. admonition:: Example code + :class: toggle + + .. literalinclude:: ../examples/expiration.py + :lines: 1,5- + + +Logging requests +~~~~~~~~~~~~~~~~ +.. include:: ../examples/log_requests.py + :start-line: 2 + :end-line: 3 + +.. admonition:: Example code + :class: toggle + + .. literalinclude:: ../examples/log_requests.py + :lines: 1,5- + + +Converting an old cache +~~~~~~~~~~~~~~~~~~~~~~~ +.. include:: ../examples/convert_cache.py + :start-line: 2 + :end-line: 4 + +.. admonition:: Example code + :class: toggle + + .. literalinclude:: ../examples/convert_cache.py + :lines: 1,6- + + diff --git a/docs/index.rst b/docs/index.rst index 24a6db6..bb39011 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -15,6 +15,7 @@ Contents user_guide advanced_usage security + examples api contributing contributors diff --git a/docs/related_projects.rst b/docs/related_projects.rst index 5ceb81b..deca9cd 100644 --- a/docs/related_projects.rst +++ b/docs/related_projects.rst @@ -15,3 +15,5 @@ You can also check out these other python cache projects: ``aiohttp`` web server * `aiocache `_: General-purpose (not HTTP-specific) async cache backends +* `flask-caching `_: A server-side HTTP cache for + applications using the Flask framework -- cgit v1.2.1