Michael Manfre avatar Michael Manfre committed 1eac7da

Added docs helpers

Comments (0)

Files changed (2)

docs/_ext/mssqldocs.py

+import urllib
+from docutils import nodes, utils
+from sphinx import addnodes, roles, __version__ as sphinx_ver
+
+# setup function to register the extension
+def setup(app):
+    app.add_config_value('django_ticket_base_url', 'https://code.djangoproject.com/ticket/', 'env')
+    app.add_role('djangoticket', make_django_ticket_link)
+
+    app.add_config_value('mssql_ticket_base_url', 'https://code.djangoproject.com/ticket/', 'env')
+    app.add_role('mssqlticket', make_mssql_ticket_link)
+
+    app.add_crossref_type(
+        directivename = "setting",
+        rolename      = "setting",
+        indextemplate = "pair: %s; setting",
+    )
+
+def make_ticket_link(type_, base_url, name, rawtext, text, lineno, inliner, options={}, content=[]):
+    try:
+        issue_num = int(text)
+        if issue_num < 1:
+            raise ValueError
+    except ValueError:
+        msg = inliner.reporter.error(
+            '{0} issue number must be a number greater than or equal to 1; "{1}" is invalid.'.format(
+                type_, text, line=lineno
+            )
+        )
+        prb = inline.problematic(rawtext, rawtext, msg)
+        return [prb], [msg]
+    ref = base_url.rstrip('/') + '/' + urllib.quote(text, safe='')
+    node = nodes.reference(rawtext, 'Django #' + utils.unescape(text), refuri=ref, **options)
+    return [node],[]
+
+def make_django_ticket_link(name, rawtext, text, lineno, inliner, options={}, content=[]):
+    env = inliner.document.settings.env
+    base_url =  env.config.django_ticket_base_url
+    return make_ticket_link('Django', base_url, name, rawtext, text, lineno, inliner, options, content)
+
+def make_mssql_ticket_link(name, rawtext, text, lineno, inliner, options={}, content=[]):
+    env = inliner.document.settings.env
+    base_url =  env.config.mssql_ticket_base_url
+    return make_ticket_link('django-mssql', base_url, name, rawtext, text, lineno, inliner, options, content)
 # If extensions (or modules to document with autodoc) are in another directory,
 # add these directories to sys.path here. If the directory is relative to the
 # documentation root, use os.path.abspath to make it absolute, like shown here.
+sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "_ext")))
 sys.path.insert(0, os.path.abspath('..'))
 
 # -- General configuration -----------------------------------------------------
 
 # Add any Sphinx extension module names here, as strings. They can be extensions
 # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
-extensions = []
+extensions = ['sphinx.ext.todo', 'sphinx.ext.viewcode',
+    'mssqldocs',]
 
 # Add any paths that contain templates here, relative to this directory.
 templates_path = ['_templates']
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.