mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Rename default_domain to primary_domain; give it special semantics.
This commit is contained in:
parent
3f4a791413
commit
0f2a0381ba
@ -192,12 +192,17 @@ General configuration
|
||||
|
||||
.. versionadded:: 1.0
|
||||
|
||||
.. confval:: default_domain
|
||||
.. confval:: primary_domain
|
||||
|
||||
.. index:: default; domain
|
||||
primary; domain
|
||||
|
||||
The name of the default :ref:`domain <domains>`. Can also be ``None`` to
|
||||
disable a default domain. The default is ``'py'``.
|
||||
disable a default domain. The default is ``'py'``. Those objects in other
|
||||
domains (whether the domain name is given explicitly, or selected by a
|
||||
:dir:`default-domain` directive) will have the domain name explicitly
|
||||
prepended when named (e.g., when the default domain is C, Python functions
|
||||
will be named "Python function", not just "function").
|
||||
|
||||
.. versionadded:: 1.0
|
||||
|
||||
|
@ -69,11 +69,11 @@ directive name.
|
||||
|
||||
To avoid having to writing the domain name all the time when you e.g. only
|
||||
describe Python objects, a default domain can be selected with either the config
|
||||
value :confval:`default_domain` or this directive:
|
||||
value :confval:`primary_domain` or this directive:
|
||||
|
||||
.. rst:directive:: .. default-domain:: name
|
||||
|
||||
Select a new default domain. While the :confval:`default_domain` selects a
|
||||
Select a new default domain. While the :confval:`primary_domain` selects a
|
||||
global default, this only has an effect within the same file.
|
||||
|
||||
If no other default is selected, the Python domain (named ``py``) is the default
|
||||
|
@ -61,7 +61,7 @@ class Config(object):
|
||||
rst_epilog = (None, 'env'),
|
||||
rst_prolog = (None, 'env'),
|
||||
trim_doctest_flags = (True, 'env'),
|
||||
default_domain = ('py', 'env'),
|
||||
primary_domain = ('py', 'env'),
|
||||
needs_sphinx = (None, None),
|
||||
nitpicky = (False, 'env'),
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
"""
|
||||
|
||||
from sphinx.errors import SphinxError
|
||||
from sphinx.locale import _
|
||||
|
||||
|
||||
class ObjType(object):
|
||||
@ -21,7 +22,7 @@ class ObjType(object):
|
||||
|
||||
Constructor arguments:
|
||||
|
||||
- *lname*: localized name of the type
|
||||
- *lname*: localized name of the type (do not include domain name)
|
||||
- *roles*: all the roles that can refer to an object of this type
|
||||
- *attrs*: object attributes -- currently only "searchprio" is known,
|
||||
which defines the object's priority in the full-text search index,
|
||||
@ -243,6 +244,14 @@ class Domain(object):
|
||||
"""
|
||||
return []
|
||||
|
||||
def get_type_name(self, type, primary=False):
|
||||
"""
|
||||
Return full name for given ObjType.
|
||||
"""
|
||||
if primary:
|
||||
return type.lname
|
||||
return _('%s %s') % (self.label, type.lname)
|
||||
|
||||
|
||||
from sphinx.domains.c import CDomain
|
||||
from sphinx.domains.cpp import CPPDomain
|
||||
|
@ -168,11 +168,11 @@ class CDomain(Domain):
|
||||
name = 'c'
|
||||
label = 'C'
|
||||
object_types = {
|
||||
'function': ObjType(l_('C function'), 'func'),
|
||||
'member': ObjType(l_('C member'), 'member'),
|
||||
'macro': ObjType(l_('C macro'), 'macro'),
|
||||
'type': ObjType(l_('C type'), 'type'),
|
||||
'var': ObjType(l_('C variable'), 'data'),
|
||||
'function': ObjType(l_('function'), 'func'),
|
||||
'member': ObjType(l_('member'), 'member'),
|
||||
'macro': ObjType(l_('macro'), 'macro'),
|
||||
'type': ObjType(l_('type'), 'type'),
|
||||
'var': ObjType(l_('variable'), 'data'),
|
||||
}
|
||||
|
||||
directives = {
|
||||
|
@ -10,7 +10,6 @@
|
||||
"""
|
||||
|
||||
import re
|
||||
import string
|
||||
from copy import deepcopy
|
||||
|
||||
from docutils import nodes
|
||||
@ -22,7 +21,7 @@ from sphinx.domains import Domain, ObjType
|
||||
from sphinx.directives import ObjectDescription
|
||||
from sphinx.util.nodes import make_refnode
|
||||
from sphinx.util.compat import Directive
|
||||
from sphinx.util.docfields import Field, TypedField
|
||||
from sphinx.util.docfields import TypedField
|
||||
|
||||
|
||||
_identifier_re = re.compile(r'\b(~?[a-zA-Z_][a-zA-Z0-9_]*)\b')
|
||||
@ -1028,10 +1027,10 @@ class CPPDomain(Domain):
|
||||
name = 'cpp'
|
||||
label = 'C++'
|
||||
object_types = {
|
||||
'class': ObjType(l_('C++ class'), 'class'),
|
||||
'function': ObjType(l_('C++ function'), 'func'),
|
||||
'member': ObjType(l_('C++ member'), 'member'),
|
||||
'type': ObjType(l_('C++ type'), 'type')
|
||||
'class': ObjType(l_('class'), 'class'),
|
||||
'function': ObjType(l_('function'), 'func'),
|
||||
'member': ObjType(l_('member'), 'member'),
|
||||
'type': ObjType(l_('type'), 'type')
|
||||
}
|
||||
|
||||
directives = {
|
||||
|
@ -163,9 +163,9 @@ class JavaScriptDomain(Domain):
|
||||
label = 'JavaScript'
|
||||
# if you add a new object type make sure to edit JSObject.get_index_string
|
||||
object_types = {
|
||||
'function': ObjType(l_('JavaScript function'), 'func'),
|
||||
'data': ObjType(l_('JavaScript data'), 'data'),
|
||||
'attribute': ObjType(l_('JavaScript attribute'), 'attr'),
|
||||
'function': ObjType(l_('function'), 'func'),
|
||||
'data': ObjType(l_('data'), 'data'),
|
||||
'attribute': ObjType(l_('attribute'), 'attr'),
|
||||
}
|
||||
directives = {
|
||||
'function': JSCallable,
|
||||
|
@ -100,8 +100,8 @@ class ReSTDomain(Domain):
|
||||
label = 'reStructuredText'
|
||||
|
||||
object_types = {
|
||||
'directive': ObjType(l_('reStructuredText directive'), 'dir'),
|
||||
'role': ObjType(l_('reStructuredText role'), 'role'),
|
||||
'directive': ObjType(l_('directive'), 'dir'),
|
||||
'role': ObjType(l_('role'), 'role'),
|
||||
}
|
||||
directives = {
|
||||
'directive': ReSTDirective,
|
||||
|
@ -495,3 +495,7 @@ class StandardDomain(Domain):
|
||||
self.object_types[type].attrs['searchprio'])
|
||||
for name, info in self.data['labels'].iteritems():
|
||||
yield (name, info[2], 'label', info[0], info[1], -1)
|
||||
|
||||
def get_type_name(self, type, primary=False):
|
||||
# never prepend "Default"
|
||||
return type.lname
|
||||
|
@ -594,7 +594,7 @@ class BuildEnvironment:
|
||||
self.temp_data['docname'] = docname
|
||||
# defaults to the global default, but can be re-set in a document
|
||||
self.temp_data['default_domain'] = \
|
||||
self.domains.get(self.config.default_domain)
|
||||
self.domains.get(self.config.primary_domain)
|
||||
|
||||
self.settings['input_encoding'] = self.config.source_encoding
|
||||
self.settings['trim_footnote_reference_space'] = \
|
||||
|
@ -170,7 +170,8 @@ class IndexBuilder(object):
|
||||
otypes[domainname, type] = i
|
||||
otype = domain.object_types.get(type)
|
||||
if otype:
|
||||
onames[i] = str(otype.lname) # fire translation proxies
|
||||
# use str() to fire translation proxies
|
||||
onames[i] = str(domain.get_type_name(otype))
|
||||
else:
|
||||
onames[i] = type
|
||||
pdict[name] = (fn2index[docname], i, prio)
|
||||
|
Loading…
Reference in New Issue
Block a user