source: specdomain/src/specdomain/sphinxcontrib/newer_specdomain.py @ 917

Last change on this file since 917 was 917, checked in by jemian, 11 years ago

prepare to revert to previous version and work from there

File size: 3.1 KB
Line 
1# -*- coding: utf-8 -*-
2"""
3    sphinxcontrib.specdomain
4    ~~~~~~~~~~~~~~~~~~~~~~~~~~
5
6    SPEC domain.
7
8    :copyright: Copyright 2012 by Pete Jemian
9    :license: BSD, see LICENSE for details.
10"""
11
12# $Id: $
13
14# http://sphinx.pocoo.org/ext/appapi.html
15
16
17import re                                               #@UnusedImport
18import string                                           #@UnusedImport
19
20from docutils import nodes                              #@UnusedImport
21from docutils.parsers.rst import directives             #@UnusedImport
22
23from sphinx import addnodes                             #@UnusedImport
24from sphinx.roles import XRefRole                       #@UnusedImport
25from sphinx.locale import l_, _                         #@UnusedImport
26from sphinx.directives import ObjectDescription         #@UnusedImport
27from sphinx.domains import Domain, ObjType, Index       #@UnusedImport
28from sphinx.util.compat import Directive                #@UnusedImport
29from sphinx.util.nodes import make_refnode              #@UnusedImport
30from sphinx.util.docfields import Field, TypedField     #@UnusedImport
31
32
33class SpecObject(ObjectDescription):
34    """
35    Description of a SPEC object (macro definition or variable).
36    """
37    def _get_index_text(self, name):
38        if self.objtype == 'def':
39            return _('%s (SPEC macro)') % name
40        elif self.objtype == 'rdef':
41            return _('%s (SPEC macro)') % name
42        elif self.objtype == 'cdef':
43            return _('%s (SPEC global)') % name
44        else:
45            return ''
46
47
48class SpecXRefRole(XRefRole):
49    def process_link(self, env, refnode, has_explicit_title, title, target):
50        refnode['spec:def'] = env.temp_data.get('spec:def')
51        if not has_explicit_title:
52            title = title.lstrip(':')   # only has a meaning for the target
53            target = target.lstrip('~') # only has a meaning for the title
54            # if the first character is a tilde, don't display the module/class
55            # parts of the contents
56            if title[0:1] == '~':
57                title = title[1:]
58                colon = title.rfind(':')
59                if colon != -1:
60                    title = title[colon+1:]
61        return title, target
62
63
64class SpecDomain(Domain):
65    """SPEC language domain."""
66    name = 'spec'
67    label = 'SPEC, http://www.certif.com'
68    object_types = {    # type of object that a domain can document
69        'def':  ObjType(l_('def'),  'def'),
70        'rdef': ObjType(l_('rdef'), 'rdef'),
71        'cdef': ObjType(l_('cdef'), 'cdef'),
72    }
73    directives = {
74        'def':          SpecObject,
75        'rdef':         SpecObject,
76        'cdef':         SpecObject,
77    }
78    roles = {
79        'def' :  SpecXRefRole(),
80        'rdef':  SpecXRefRole(),
81        'cdef':  SpecXRefRole(),
82    }
83    #indices = [
84    #    SpecMacroIndex,
85    #]
86
87
88# http://sphinx.pocoo.org/ext/tutorial.html#the-setup-function
89
90def setup(app):
91    app.add_domain(SpecDomain)
92    # http://sphinx.pocoo.org/ext/appapi.html#sphinx.domains.Domain
Note: See TracBrowser for help on using the repository browser.