Skip to content

Commit 3800876

Browse files
committed
Adding banner message feature.
Adding CLI options, Sphinx context variables, etc for displaying banner messages on non-latest versions. Fixes #13
1 parent 333f19c commit 3800876

23 files changed

+541
-16
lines changed

README.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,20 @@ Unreleased
4848
----------
4949

5050
Added
51+
* Option to enable warning banner in old/development versions. Similar to Jinja2's documentation.
52+
* Command line options: ``--banner-greatest-tag`` ``--banner-recent-tag`` ``--show-banner`` ``--banner-main-ref``
5153
* Jinja2 context functions: ``vhasdoc()`` ``vpathto()``
54+
* Jinja2 context variables: ``scv_show_banner`` ``scv_banner_greatest_tag`` ``scv_banner_main_ref_is_branch``
55+
``scv_banner_main_ref_is_tag`` ``scv_banner_main_version`` ``scv_banner_recent_tag``
5256

5357
Changed
5458
* Root ref will also be built in its own directory like other versions. All URLs to root ref will point to the one
5559
in that directory instead of the root. More info: https://github.com/Robpol86/sphinxcontrib-versioning/issues/15
5660
* Renamed Jinja2 context variable ``scv_is_root_ref`` to ``scv_is_root``.
5761

62+
Fixed
63+
* https://github.com/Robpol86/sphinxcontrib-versioning/issues/13
64+
5865
Removed
5966
* Jinja2 context variables: ``scv_root_ref_is_branch`` ``scv_root_ref_is_tag``
6067

docs/banner.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.. _banner:
2+
3+
==============
4+
Banner Message
5+
==============
6+
7+
Banner messages can be displayed at the top of every document informing users that they are currently viewing either old
8+
or the development version of the project's documentation, with the exception of the :option:`--banner-main-ref`. This
9+
feature is inspired by banner on the `Jinja2 documentation <http://jinja.pocoo.org/docs/dev/>`_.
10+
11+
The banner feature is disabled by default. It can be enabled with the :option:`--show-banner` setting.
12+
13+
.. figure:: screenshots/sphinx_rtd_theme_banner_dev.png
14+
:target: _images/sphinx_rtd_theme_banner_dev.png
15+
16+
The message displayed when users are viewing docs from a branch and the :option:`--banner-main-ref` is a tag. The
17+
entire banner is a link that sends users to the latest version of the current page if it exists there.
18+
19+
.. figure:: screenshots/sphinx_rtd_theme_banner_old.png
20+
:target: _images/sphinx_rtd_theme_banner_old.png
21+
22+
The message displayed when users are viewing docs from a tag and the :option:`--banner-main-ref` is a tag. Like the
23+
message above this one links users to the latest version of the current page.
24+
25+
.. figure:: screenshots/sphinx_rtd_theme_banner_nourl.png
26+
:target: _images/sphinx_rtd_theme_banner_nourl.png
27+
28+
An example of a banner message from a page that does not exist in the :option:`--banner-main-ref` version. Since
29+
there is no page to link to this is just text informing the user that they're viewing the development version of the
30+
docs.

docs/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
googleanalytics_id = 'UA-82627369-1'
3838

3939
# SCVersioning.
40-
scv_greatest_tag = True
40+
scv_banner_greatest_tag = True
4141
scv_grm_exclude = ('.gitignore', '.nojekyll', 'README.rst')
42+
scv_show_banner = True
4243
scv_sort = ('semver', 'time')

docs/context.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,36 @@ Functions
8484
Go to <a href="{{ vpathto('master') }}">master</a> for the latest docs.
8585
{% endif %}
8686
87+
Banner Variables
88+
================
89+
90+
These variables are exposed in the Jinja2 context to facilitate displaying the banner message and deciding which message
91+
to display.
92+
93+
.. attribute:: scv_banner_greatest_tag
94+
95+
A boolean set to True if :option:`--banner-greatest-tag` is used.
96+
97+
.. attribute:: scv_banner_main_ref_is_branch
98+
99+
A boolean set to True if the banner main ref is a branch.
100+
101+
.. attribute:: scv_banner_main_ref_is_tag
102+
103+
A boolean set to True if the banner main ref is a tag.
104+
105+
.. attribute:: scv_banner_main_version
106+
107+
A string, the value of :option:`--banner-main-ref`.
108+
109+
.. attribute:: scv_banner_recent_tag
110+
111+
A boolean set to True if :option:`--banner-recent-tag` is used.
112+
113+
.. attribute:: scv_show_banner
114+
115+
A boolean set to True if :option:`--show-banner` is used.
116+
87117
Other Variables
88118
===============
89119

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Project Links
3939

4040
install
4141
tutorial
42+
banner
4243
settings
4344
context
4445
themes
55.2 KB
Loading
51 KB
Loading
53.2 KB
Loading

docs/settings.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,52 @@ Options
124124

125125
These options are available for the build sub command:
126126

127+
.. option:: -a, --banner-greatest-tag, scv_banner_greatest_tag
128+
129+
Override banner-main-ref to be the tag with the highest version number. If no tags have docs then this option is
130+
ignored and :option:`--banner-main-ref` is used.
131+
132+
This setting may also be specified in your conf.py file. It must be a boolean:
133+
134+
.. code-block:: python
135+
136+
scv_banner_greatest_tag = True
137+
138+
.. option:: -A, --banner-recent-tag, scv_banner_recent_tag
139+
140+
Override banner-main-ref to be the most recent committed tag. If no tags have docs then this option is ignored and
141+
:option:`--banner-main-ref` is used.
142+
143+
This setting may also be specified in your conf.py file. It must be a boolean:
144+
145+
.. code-block:: python
146+
147+
scv_banner_recent_tag = True
148+
149+
.. option:: -b, --show-banner, scv_show_banner
150+
151+
Show a warning banner. Enables the :ref:`banner` feature.
152+
153+
This setting may also be specified in your conf.py file. It must be a boolean:
154+
155+
.. code-block:: python
156+
157+
scv_show_banner = True
158+
159+
.. option:: -B <ref>, --banner-main-ref <ref>, scv_banner_main_ref
160+
161+
The branch/tag considered to be the latest/current version. The banner will not be displayed in this ref, only in
162+
all others. Default is **master**.
163+
164+
If the banner-main-ref does not exist or does not have docs the banner will be disabled completely in all versions.
165+
Docs will continue to be built.
166+
167+
This setting may also be specified in your conf.py file. It must be a string:
168+
169+
.. code-block:: python
170+
171+
scv_banner_main_ref = 'feature_branch'
172+
127173
.. option:: -i, --invert, scv_invert
128174

129175
Invert the order of branches/tags displayed in the sidebars in generated HTML documents. The default order is

setup.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ def run(cls):
100100
license=LICENSE,
101101
long_description=readme(),
102102
name=NAME,
103-
package_data={'': [os.path.join('_templates', 'versions.html')]},
103+
package_data={'': [
104+
os.path.join('_static', 'banner.css'),
105+
os.path.join('_templates', 'banner.html'),
106+
os.path.join('_templates', 'layout.html'),
107+
os.path.join('_templates', 'versions.html'),
108+
]},
104109
packages=['sphinxcontrib', os.path.join('sphinxcontrib', 'versioning')],
105110
url='https://github.com/Robpol86/' + NAME,
106111
version=VERSION,

0 commit comments

Comments
 (0)