Skip to content

Commit 5f2fb7d

Browse files
committed
Rename hoverxref_tooltip_api_host to hoverxref_api_host
This config works for both, tooltip and modal now. So, the "tooltip" prefix is not needed anymore. I added a warning message and also keep support for the old name.
1 parent f96139e commit 5f2fb7d

File tree

5 files changed

+31
-14
lines changed

5 files changed

+31
-14
lines changed

docs/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@
5151

5252
# Used when building the documentation from the terminal and using a local Read
5353
# the Docs instance as backend
54-
hoverxref_tooltip_api_host = 'http://localhost:8000'
54+
hoverxref_api_host = 'http://localhost:8000'
5555

5656
if os.environ.get('READTHEDOCS') == 'True':
5757
# Building on Read the Docs
58-
hoverxref_tooltip_api_host = 'https://readthedocs.org'
58+
hoverxref_api_host = 'https://readthedocs.org'
5959
if os.environ.get('LOCAL_READTHEDOCS') == 'True':
6060
# Building on a local Read the Docs instance
61-
hoverxref_tooltip_api_host = 'http://community.dev.readthedocs.io'
61+
hoverxref_api_host = 'http://community.dev.readthedocs.io'
6262

6363
hoverxref_tooltip_maxwidth = 650
6464
hoverxref_auto_ref = True

docs/configuration.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,19 @@ These settings are global and have effect on both, tooltips and modal dialogues.
8888

8989
.. _Mathjax: http://www.sphinx-doc.org/es/master/usage/extensions/math.html#module-sphinx.ext.mathjax
9090

91+
.. confval:: hoverxref_api_host
9192

92-
Tooltipster
93-
-----------
93+
Description: Host URL for the API to retrieve the content of the floating window
9494

95-
These settings have effect only in tooltips.
95+
Default: ``https://readthedocs.org``
9696

97-
.. confval:: hoverxref_tooltip_api_host
97+
Type: string
9898

99-
Description: Host URL for the API to retrieve the tooltip content
10099

101-
Default: ``https://readthedocs.org``
100+
Tooltipster
101+
-----------
102102

103-
Type: string
103+
These settings have effect only in tooltips.
104104

105105
.. confval:: hoverxref_tooltip_class
106106

docs/development.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ To setup this approach, you need to put these settings in the ``conf.py`` of you
2323
2424
hoverxref_project = 'sphinx-hoverxref'
2525
hoverxref_version = 'latest'
26-
hoverxref_tooltip_api_host = 'https://readthedocs.org'
26+
hoverxref_api_host = 'https://readthedocs.org'
2727
2828
After building the documentation all the requests will be done to URLs like::
2929

@@ -84,7 +84,7 @@ To make the extension to work, you will need to define this setting in your ``co
8484

8585
.. code-block:: python
8686
87-
hoverxref_tooltip_api_host = 'http://dev.readthedocs.io:8000'
87+
hoverxref_api_host = 'http://dev.readthedocs.io:8000'
8888
8989
.. tip::
9090

hoverxref/_static/js/hoverxref.js_t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ $(document).ready(function() {
7979
// we set a variable so the data is only loaded once via Ajax, not every time the tooltip opens
8080
if ($origin.data('loaded') !== true) {
8181
// TODO: improve URL handling here
82-
var url = '{{ hoverxref_tooltip_api_host }}' + '/api/v2/embed/?' + 'project=' + project + '&version=' + version + '&doc=' + doc + '&section=' + section;
82+
var url = '{{ hoverxref_api_host }}' + '/api/v2/embed/?' + 'project=' + project + '&version=' + version + '&doc=' + doc + '&section=' + section;
8383
$.get(url, function(data) {
8484
// call the 'content' method to update the content of our tooltip with the returned data.
8585
// note: this content update will trigger an update animation (see the updateAnimation option)
@@ -150,7 +150,7 @@ $(document).ready(function() {
150150
var doc = element.data('doc');
151151
var section = element.data('section');
152152
console.debug('Data: project=' + project + ' version=' + version + ' doc=' + doc + ' section=' + section);
153-
var url = '{{ hoverxref_tooltip_api_host }}' + '/api/v2/embed/?' + 'project=' + project + '&version=' + version + '&doc=' + doc + '&section=' + section;
153+
var url = '{{ hoverxref_api_host }}' + '/api/v2/embed/?' + 'project=' + project + '&version=' + version + '&doc=' + doc + '&section=' + section;
154154

155155
$.get(url, function(data) {
156156
var content = $('<div></div>');

hoverxref/extension.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
from docutils import nodes
44
from sphinx.roles import XRefRole
55
from sphinx.util.fileutil import copy_asset
6+
from sphinx.util import logging
67

78
from . import version
89
from .domains import HoverXRefPythonDomain, HoverXRefStandardDomain
910
from .translators import HoverXRefHTMLTranslator
1011

12+
logger = logging.getLogger(__name__)
13+
14+
1115
HOVERXREF_ASSETS_FILES = [
1216
'js/hoverxref.js_t', # ``_t`` tells Sphinx this is a template
1317
]
@@ -132,6 +136,15 @@ def setup_theme(app, exception):
132136
)
133137

134138

139+
def deprecated_configs_warning(app, exception):
140+
"""Log warning message if old configs are used."""
141+
default, rebuild, types = app.config.values.get('hoverxref_tooltip_api_host')
142+
if app.config.hoverxref_tooltip_api_host != default:
143+
message = '"hoverxref_tooltip_api_host" is deprecated and replaced by "hoverxref_api_host".'
144+
logger.warning(message)
145+
app.config.hoverxref_api_host = app.config.hoverxref_tooltip_api_host
146+
147+
135148
def setup(app):
136149
"""Setup ``hoverxref`` Sphinx extension."""
137150

@@ -148,8 +161,10 @@ def setup(app):
148161
app.add_config_value('hoverxref_roles', [], 'env')
149162
app.add_config_value('hoverxref_domains', [], 'env')
150163
app.add_config_value('hoverxref_type', 'tooltip', 'env')
164+
app.add_config_value('hoverxref_api_host', 'https://readthedocs.org', 'env')
151165

152166
# Tooltipster settings
167+
# Deprecated in favor of ``hoverxref_api_host``
153168
app.add_config_value('hoverxref_tooltip_api_host', 'https://readthedocs.org', 'env')
154169
app.add_config_value('hoverxref_tooltip_theme', ['tooltipster-shadow', 'tooltipster-shadow-custom'], 'env')
155170
app.add_config_value('hoverxref_tooltip_interactive', True, 'env')
@@ -180,6 +195,8 @@ def setup(app):
180195
app.set_translator('readthedocs', HoverXRefHTMLTranslator, override=True)
181196
app.set_translator('readthedocsdirhtml', HoverXRefHTMLTranslator, override=True)
182197

198+
app.connect('config-inited', deprecated_configs_warning)
199+
183200
app.connect('config-inited', setup_domains)
184201
app.connect('config-inited', setup_sphinx_tabs)
185202
app.connect('config-inited', setup_theme)

0 commit comments

Comments
 (0)