Details
-
Type:
Story
-
Status: Won't Fix
-
Resolution: Done
-
Fix Version/s: None
-
Component/s: Stack Documentation and UX
-
Labels:
-
Story Points:0.7
-
Epic Link:
-
Team:SQuaRE
Description
From experience creating Sphinx extensions (DM-15821), it's clear that extensions can have lots of members that need to be tracked by the setup function. I think this can be made easier by using decorators that register directives, roles, and so forth, and then using that centralized registry to auto-populate the setup function.
It looks something like this:
from docutils import nodes
|
from docutils.parsers.rst import Directive
|
|
from documenteer.sphinxext.utils import SphinxExtension
|
|
|
# module-level instance. All members of the Sphinx extension refer to
|
# this instance.
|
extension = SphinxExtension()
|
|
# Decorate a directive class to register it with the extension
|
@extension.directive
|
def MyDirective(Directive):
|
|
# By putting a ``name`` attribute in your directive, SphinxExtension
|
# will use that name for the directive name.
|
name = "my-directive"
|
|
def run(self):
|
return [nodes.paragraph(text='Hello world')
|
|
# Now your setup function just calls the setup method on the
|
# SphinxExtension instance
|
def setup():
|
extension.setup()
|
Attachments
Issue Links
- mentioned in
-
Page Loading...
Is this ticket still relevant?