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 | |
---|
17 | import re #@UnusedImport |
---|
18 | import string #@UnusedImport |
---|
19 | |
---|
20 | from docutils import nodes #@UnusedImport |
---|
21 | from docutils.parsers.rst import directives #@UnusedImport |
---|
22 | |
---|
23 | from sphinx import addnodes #@UnusedImport |
---|
24 | from sphinx.roles import XRefRole #@UnusedImport |
---|
25 | from sphinx.locale import l_, _ #@UnusedImport |
---|
26 | from sphinx.directives import ObjectDescription #@UnusedImport |
---|
27 | from sphinx.domains import Domain, ObjType, Index #@UnusedImport |
---|
28 | from sphinx.util.compat import Directive #@UnusedImport |
---|
29 | from sphinx.util.nodes import make_refnode #@UnusedImport |
---|
30 | from sphinx.util.docfields import Field, TypedField #@UnusedImport |
---|
31 | |
---|
32 | |
---|
33 | class 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 | |
---|
48 | class 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 | |
---|
64 | class 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 | |
---|
90 | def setup(app): |
---|
91 | app.add_domain(SpecDomain) |
---|
92 | # http://sphinx.pocoo.org/ext/appapi.html#sphinx.domains.Domain |
---|