Merge branch 'hotfix/embed_widget' of git://github.com/lapilofu/philo into develop
[philo.git] / docs / _ext / philodocs.py
1 import inspect
2
3 from sphinx.addnodes import desc_addname
4 from sphinx.domains.python import PyModulelevel, PyXRefRole
5 from sphinx.ext import autodoc
6
7
8 DOMAIN = 'py'
9
10
11 class TemplateTag(PyModulelevel):
12         indextemplate = "pair: %s; template tag"
13         
14         def get_signature_prefix(self, sig):
15                 return self.objtype + ' '
16         
17         def handle_signature(self, sig, signode):
18                 fullname, name_prefix = PyModulelevel.handle_signature(self, sig, signode)
19                 
20                 for i, node in enumerate(signode):
21                         if isinstance(node, desc_addname):
22                                 lib = '.'.join(node[0].split('.')[-2:])
23                                 new_node = desc_addname(lib, lib)
24                                 signode[i] = new_node
25                 
26                 return fullname, name_prefix
27
28
29 class TemplateTagDocumenter(autodoc.FunctionDocumenter):
30         objtype = 'templatetag'
31         domain = DOMAIN
32         
33         @classmethod
34         def can_document_member(cls, member, membername, isattr, parent):
35                 # Only document explicitly.
36                 return False
37         
38         def format_args(self):
39                 return None
40
41 class TemplateFilterDocumenter(autodoc.FunctionDocumenter):
42         objtype = 'templatefilter'
43         domain = DOMAIN
44         
45         @classmethod
46         def can_document_member(cls, member, membername, isattr, parent):
47                 # Only document explicitly.
48                 return False
49
50 def setup(app):
51         app.add_directive_to_domain(DOMAIN, 'templatetag', TemplateTag)
52         app.add_role_to_domain(DOMAIN, 'ttag', PyXRefRole())
53         app.add_directive_to_domain(DOMAIN, 'templatefilter', TemplateTag)
54         app.add_role_to_domain(DOMAIN, 'tfilter', PyXRefRole())
55         app.add_autodocumenter(TemplateTagDocumenter)
56         app.add_autodocumenter(TemplateFilterDocumenter)