X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/1324f9b1e4d57c5ab50bc264507f7adc3207eb99..0959d38b27c03863ec376839dcc6d896d04e36ea:/docs/_ext/philodocs.py diff --git a/docs/_ext/philodocs.py b/docs/_ext/philodocs.py new file mode 100644 index 0000000..6c1ecf7 --- /dev/null +++ b/docs/_ext/philodocs.py @@ -0,0 +1,56 @@ +import inspect + +from sphinx.addnodes import desc_addname +from sphinx.domains.python import PyModulelevel, PyXRefRole +from sphinx.ext import autodoc + + +DOMAIN = 'py' + + +class TemplateTag(PyModulelevel): + indextemplate = "pair: %s; template tag" + + def get_signature_prefix(self, sig): + return self.objtype + ' ' + + def handle_signature(self, sig, signode): + fullname, name_prefix = PyModulelevel.handle_signature(self, sig, signode) + + for i, node in enumerate(signode): + if isinstance(node, desc_addname): + lib = '.'.join(node[0].split('.')[-2:]) + new_node = desc_addname(lib, lib) + signode[i] = new_node + + return fullname, name_prefix + + +class TemplateTagDocumenter(autodoc.FunctionDocumenter): + objtype = 'templatetag' + domain = DOMAIN + + @classmethod + def can_document_member(cls, member, membername, isattr, parent): + # Only document explicitly. + return False + + def format_args(self): + return None + +class TemplateFilterDocumenter(autodoc.FunctionDocumenter): + objtype = 'templatefilter' + domain = DOMAIN + + @classmethod + def can_document_member(cls, member, membername, isattr, parent): + # Only document explicitly. + return False + +def setup(app): + app.add_directive_to_domain(DOMAIN, 'templatetag', TemplateTag) + app.add_role_to_domain(DOMAIN, 'ttag', PyXRefRole()) + app.add_directive_to_domain(DOMAIN, 'templatefilter', TemplateTag) + app.add_role_to_domain(DOMAIN, 'tfilter', PyXRefRole()) + app.add_autodocumenter(TemplateTagDocumenter) + app.add_autodocumenter(TemplateFilterDocumenter) \ No newline at end of file