Rename default_domain to primary_domain; give it special semantics.

This commit is contained in:
Georg Brandl 2010-05-23 16:48:54 +02:00
parent 3f4a791413
commit 0f2a0381ba
11 changed files with 42 additions and 24 deletions

View File

@ -192,12 +192,17 @@ General configuration
.. versionadded:: 1.0 .. versionadded:: 1.0
.. confval:: default_domain .. confval:: primary_domain
.. index:: default; domain .. index:: default; domain
primary; domain
The name of the default :ref:`domain <domains>`. Can also be ``None`` to 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 .. versionadded:: 1.0

View File

@ -69,11 +69,11 @@ directive name.
To avoid having to writing the domain name all the time when you e.g. only 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 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 .. 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. 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 If no other default is selected, the Python domain (named ``py``) is the default

View File

@ -61,7 +61,7 @@ class Config(object):
rst_epilog = (None, 'env'), rst_epilog = (None, 'env'),
rst_prolog = (None, 'env'), rst_prolog = (None, 'env'),
trim_doctest_flags = (True, 'env'), trim_doctest_flags = (True, 'env'),
default_domain = ('py', 'env'), primary_domain = ('py', 'env'),
needs_sphinx = (None, None), needs_sphinx = (None, None),
nitpicky = (False, 'env'), nitpicky = (False, 'env'),

View File

@ -11,6 +11,7 @@
""" """
from sphinx.errors import SphinxError from sphinx.errors import SphinxError
from sphinx.locale import _
class ObjType(object): class ObjType(object):
@ -21,7 +22,7 @@ class ObjType(object):
Constructor arguments: 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 - *roles*: all the roles that can refer to an object of this type
- *attrs*: object attributes -- currently only "searchprio" is known, - *attrs*: object attributes -- currently only "searchprio" is known,
which defines the object's priority in the full-text search index, which defines the object's priority in the full-text search index,
@ -243,6 +244,14 @@ class Domain(object):
""" """
return [] 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.c import CDomain
from sphinx.domains.cpp import CPPDomain from sphinx.domains.cpp import CPPDomain

View File

@ -168,11 +168,11 @@ class CDomain(Domain):
name = 'c' name = 'c'
label = 'C' label = 'C'
object_types = { object_types = {
'function': ObjType(l_('C function'), 'func'), 'function': ObjType(l_('function'), 'func'),
'member': ObjType(l_('C member'), 'member'), 'member': ObjType(l_('member'), 'member'),
'macro': ObjType(l_('C macro'), 'macro'), 'macro': ObjType(l_('macro'), 'macro'),
'type': ObjType(l_('C type'), 'type'), 'type': ObjType(l_('type'), 'type'),
'var': ObjType(l_('C variable'), 'data'), 'var': ObjType(l_('variable'), 'data'),
} }
directives = { directives = {

View File

@ -10,7 +10,6 @@
""" """
import re import re
import string
from copy import deepcopy from copy import deepcopy
from docutils import nodes from docutils import nodes
@ -22,7 +21,7 @@ from sphinx.domains import Domain, ObjType
from sphinx.directives import ObjectDescription from sphinx.directives import ObjectDescription
from sphinx.util.nodes import make_refnode from sphinx.util.nodes import make_refnode
from sphinx.util.compat import Directive 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') _identifier_re = re.compile(r'\b(~?[a-zA-Z_][a-zA-Z0-9_]*)\b')
@ -1028,10 +1027,10 @@ class CPPDomain(Domain):
name = 'cpp' name = 'cpp'
label = 'C++' label = 'C++'
object_types = { object_types = {
'class': ObjType(l_('C++ class'), 'class'), 'class': ObjType(l_('class'), 'class'),
'function': ObjType(l_('C++ function'), 'func'), 'function': ObjType(l_('function'), 'func'),
'member': ObjType(l_('C++ member'), 'member'), 'member': ObjType(l_('member'), 'member'),
'type': ObjType(l_('C++ type'), 'type') 'type': ObjType(l_('type'), 'type')
} }
directives = { directives = {

View File

@ -163,9 +163,9 @@ class JavaScriptDomain(Domain):
label = 'JavaScript' label = 'JavaScript'
# if you add a new object type make sure to edit JSObject.get_index_string # if you add a new object type make sure to edit JSObject.get_index_string
object_types = { object_types = {
'function': ObjType(l_('JavaScript function'), 'func'), 'function': ObjType(l_('function'), 'func'),
'data': ObjType(l_('JavaScript data'), 'data'), 'data': ObjType(l_('data'), 'data'),
'attribute': ObjType(l_('JavaScript attribute'), 'attr'), 'attribute': ObjType(l_('attribute'), 'attr'),
} }
directives = { directives = {
'function': JSCallable, 'function': JSCallable,

View File

@ -100,8 +100,8 @@ class ReSTDomain(Domain):
label = 'reStructuredText' label = 'reStructuredText'
object_types = { object_types = {
'directive': ObjType(l_('reStructuredText directive'), 'dir'), 'directive': ObjType(l_('directive'), 'dir'),
'role': ObjType(l_('reStructuredText role'), 'role'), 'role': ObjType(l_('role'), 'role'),
} }
directives = { directives = {
'directive': ReSTDirective, 'directive': ReSTDirective,

View File

@ -495,3 +495,7 @@ class StandardDomain(Domain):
self.object_types[type].attrs['searchprio']) self.object_types[type].attrs['searchprio'])
for name, info in self.data['labels'].iteritems(): for name, info in self.data['labels'].iteritems():
yield (name, info[2], 'label', info[0], info[1], -1) yield (name, info[2], 'label', info[0], info[1], -1)
def get_type_name(self, type, primary=False):
# never prepend "Default"
return type.lname

View File

@ -594,7 +594,7 @@ class BuildEnvironment:
self.temp_data['docname'] = docname self.temp_data['docname'] = docname
# defaults to the global default, but can be re-set in a document # defaults to the global default, but can be re-set in a document
self.temp_data['default_domain'] = \ 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['input_encoding'] = self.config.source_encoding
self.settings['trim_footnote_reference_space'] = \ self.settings['trim_footnote_reference_space'] = \

View File

@ -170,7 +170,8 @@ class IndexBuilder(object):
otypes[domainname, type] = i otypes[domainname, type] = i
otype = domain.object_types.get(type) otype = domain.object_types.get(type)
if otype: 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: else:
onames[i] = type onames[i] = type
pdict[name] = (fn2index[docname], i, prio) pdict[name] = (fn2index[docname], i, prio)