mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Implement get_full_qualified_name() to JavascriptDomain (refs: #3630)
This commit is contained in:
parent
db377ceb55
commit
96fa6d2972
@ -398,6 +398,16 @@ class JavaScriptDomain(Domain):
|
||||
yield refname, refname, type, docname, \
|
||||
refname.replace('$', '_S_'), 1
|
||||
|
||||
def get_full_qualified_name(self, node):
|
||||
# type: (nodes.Node) -> unicode
|
||||
modname = node.get('js:module')
|
||||
prefix = node.get('js:object')
|
||||
target = node.get('reftarget')
|
||||
if target is None:
|
||||
return None
|
||||
else:
|
||||
return '.'.join(filter(None, [modname, prefix, target]))
|
||||
|
||||
|
||||
def setup(app):
|
||||
# type: (Sphinx) -> Dict[unicode, Any]
|
||||
|
@ -10,7 +10,11 @@
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from mock import Mock
|
||||
from docutils import nodes
|
||||
|
||||
from sphinx import addnodes
|
||||
from sphinx.domains.javascript import JavaScriptDomain
|
||||
|
||||
from util import assert_node
|
||||
|
||||
@ -133,3 +137,31 @@ def test_domain_js_find_obj(app, status, warning):
|
||||
( u'module_a.submodule.ModTopLevel.mod_child_2', (u'module', u'method')))
|
||||
assert (find_obj(u'module_b.submodule', u'ModTopLevel', u'module_a.submodule', u'mod') ==
|
||||
( u'module_a.submodule', (u'module', u'module')))
|
||||
|
||||
|
||||
def test_get_full_qualified_name():
|
||||
env = Mock(domaindata={})
|
||||
domain = JavaScriptDomain(env)
|
||||
|
||||
# non-js references
|
||||
node = nodes.reference()
|
||||
assert domain.get_full_qualified_name(node) is None
|
||||
|
||||
# simple reference
|
||||
node = nodes.reference(reftarget='func')
|
||||
assert domain.get_full_qualified_name(node) == 'func'
|
||||
|
||||
# with js:module context
|
||||
kwargs = {'js:module': 'module1'}
|
||||
node = nodes.reference(reftarget='func', **kwargs)
|
||||
assert domain.get_full_qualified_name(node) == 'module1.func'
|
||||
|
||||
# with js:object context
|
||||
kwargs = {'js:object': 'Class'}
|
||||
node = nodes.reference(reftarget='func', **kwargs)
|
||||
assert domain.get_full_qualified_name(node) == 'Class.func'
|
||||
|
||||
# with both js:module and js:object context
|
||||
kwargs = {'js:module': 'module1', 'js:object': 'Class'}
|
||||
node = nodes.reference(reftarget='func', **kwargs)
|
||||
assert domain.get_full_qualified_name(node) == 'module1.Class.func'
|
||||
|
@ -212,6 +212,30 @@ def test_missing_reference_stddomain(tempdir, app, status, warning):
|
||||
assert rn.astext() == 'ls -l'
|
||||
|
||||
|
||||
def test_missing_reference_jsdomain(tempdir, app, status, warning):
|
||||
inv_file = tempdir / 'inventory'
|
||||
inv_file.write_bytes(inventory_v2)
|
||||
app.config.intersphinx_mapping = {
|
||||
'https://docs.python.org/': inv_file,
|
||||
}
|
||||
app.config.intersphinx_cache_limit = 0
|
||||
|
||||
# load the inventory and check if it's done correctly
|
||||
load_mappings(app)
|
||||
|
||||
# no context data
|
||||
kwargs = {}
|
||||
node, contnode = fake_node('js', 'meth', 'baz', 'baz()', **kwargs)
|
||||
rn = missing_reference(app, app.env, node, contnode)
|
||||
assert rn is None
|
||||
|
||||
# js:module and js:object context helps to search objects
|
||||
kwargs = {'js:module': 'foo', 'js:object': 'bar'}
|
||||
node, contnode = fake_node('js', 'meth', 'baz', 'baz()', **kwargs)
|
||||
rn = missing_reference(app, app.env, node, contnode)
|
||||
assert rn.astext() == 'baz()'
|
||||
|
||||
|
||||
def test_load_mappings_warnings(tempdir, app, status, warning):
|
||||
"""
|
||||
load_mappings issues a warning if new-style mapping
|
||||
|
@ -37,6 +37,10 @@ CFunc c:function 2 cfunc.html#CFunc -
|
||||
a term std:term -1 glossary.html#term-a-term -
|
||||
ls.-l std:cmdoption 1 index.html#cmdoption-ls-l -
|
||||
docname std:doc -1 docname.html -
|
||||
foo js:module 1 index.html#foo -
|
||||
foo.bar js:class 1 index.html#foo.bar -
|
||||
foo.bar.baz js:method 1 index.html#foo.bar.baz -
|
||||
foo.bar.qux js:data 1 index.html#foo.bar.qux -
|
||||
a term including:colon std:term -1 glossary.html#term-a-term-including-colon -
|
||||
'''.encode('utf-8'))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user