58 | | app.add_directive('versionadded', parse_version_directive, 1, (1, 1, 1)) |
59 | | app.add_directive('versionchanged', parse_version_directive, 1, (1, 1, 1)) |
| 59 | app.add_directive('versionadded', VersionDirective) |
| 60 | app.add_directive('versionchanged', VersionDirective) |
63 | | def parse_version_directive(name, arguments, options, content, lineno, |
64 | | content_offset, block_text, state, state_machine): |
65 | | env = state.document.settings.env |
66 | | is_nextversion = env.config.django_next_version == arguments[0] |
67 | | ret = [] |
68 | | node = addnodes.versionmodified() |
69 | | ret.append(node) |
70 | | if not is_nextversion: |
71 | | if len(arguments) == 1: |
72 | | linktext = 'Please, see the release notes <releases-%s>' % (arguments[0]) |
73 | | try: |
74 | | xrefs = roles.XRefRole()('ref', linktext, linktext, lineno, state) # Sphinx >= 1.0 |
75 | | except: |
76 | | xrefs = roles.xfileref_role('ref', linktext, linktext, lineno, state) # Sphinx < 1.0 |
77 | | node.extend(xrefs[0]) |
78 | | node['version'] = arguments[0] |
79 | | else: |
80 | | node['version'] = "Development version" |
81 | | node['type'] = name |
82 | | if len(arguments) == 2: |
83 | | inodes, messages = state.inline_text(arguments[1], lineno+1) |
84 | | node.extend(inodes) |
85 | | if content: |
86 | | state.nested_parse(content, content_offset, node) |
87 | | ret = ret + messages |
88 | | env.note_versionchange(node['type'], node['version'], node, lineno) |
89 | | return ret |
| 64 | |
| 65 | class VersionDirective(Directive): |
| 66 | has_content = True |
| 67 | required_arguments = 1 |
| 68 | optional_arguments = 1 |
| 69 | final_argument_whitespace = True |
| 70 | option_spec = {} |
| 71 | |
| 72 | def run(self): |
| 73 | env = self.state.document.settings.env |
| 74 | arg0 = self.arguments[0] |
| 75 | is_nextversion = env.config.django_next_version == arg0 |
| 76 | ret = [] |
| 77 | node = addnodes.versionmodified() |
| 78 | ret.append(node) |
| 79 | if not is_nextversion: |
| 80 | if len(self.arguments) == 1: |
| 81 | linktext = 'Please, see the release notes <releases-%s>' % (arg0) |
| 82 | try: |
| 83 | xrefs = roles.XRefRole()('std:ref', linktext, linktext, self.lineno, self.state) # Sphinx >= 1.0 |
| 84 | except: |
| 85 | xrefs = roles.xfileref_role('ref', linktext, linktext, self.lineno, self.state) # Sphinx < 1.0 |
| 86 | node.extend(xrefs[0]) |
| 87 | node['version'] = arg0 |
| 88 | else: |
| 89 | node['version'] = "Development version" |
| 90 | node['type'] = self.name |
| 91 | if len(self.arguments) == 2: |
| 92 | inodes, messages = self.state.inline_text(self.arguments[1], self.lineno+1) |
| 93 | node.extend(inodes) |
| 94 | if self.content: |
| 95 | self.state.nested_parse(self.content, self.content_offset, node) |
| 96 | ret = ret + messages |
| 97 | env.note_versionchange(node['type'], node['version'], node, self.lineno) |
| 98 | return ret |