Anonymous avatar Anonymous committed 95763d8

Added initial support for sphinx.

Comments (0)

Files changed (1)

piston/handlers_doc.py

+from docutils import nodes
+from sphinx.util.compat import Directive
+from piston.doc import generate_doc
+
+class handlers_doc(nodes.General, nodes.Element): pass
+
+class PistonHandlers(Directive):
+    required_arguments = 1
+
+    def run(self):
+        module_name = self.arguments[0]
+        content = []
+        try:
+            __import__(module_name)
+            content = [handlers_doc()]
+        except ImportError:
+            self.state.document.reporter.warning("Can't import %s module." % module_name)
+        return content
+
+def add_piston_documentation(app, doctree, fromdocname):
+    content = []
+
+    from piston.handler import handler_tracker
+    for handler in handler_tracker:
+        doc = generate_doc(handler)
+        title = nodes.title()
+        title += nodes.Text(doc.name)
+        content.append(title)
+        if doc.doc:
+            doctitle = nodes.paragraph()
+            doctitle += nodes.Text('Docstring:')
+            content.append(doctitle)
+            docstring = nodes.literal_block()
+            docstring += nodes.Text(doc.doc, doc.doc)
+            content.append(docstring)
+        uri = nodes.literal_block()
+        uri += nodes.Text(doc.get_resource_uri_template())
+        content.append(uri)
+        methods = nodes.paragraph()
+        methods_text = nodes.paragraph()
+        methods_text += nodes.Text("Accepted methods:")
+        methods += methods_text
+        accepted_methods = nodes.bullet_list()
+        for accepted_method in doc.allowed_methods:
+            item = nodes.list_item()
+            item_para = nodes.paragraph()
+            item_para += nodes.Text(accepted_method)
+            item += item_para
+            accepted_methods += item
+        methods += accepted_methods
+        content.append(methods)
+
+    for node in doctree.traverse(handlers_doc):
+        node.replace_self(content)
+
+def setup(app):
+    app.add_node(handlers_doc)
+    app.add_directive('piston_handlers', PistonHandlers)
+    app.connect('doctree-resolved', add_piston_documentation)
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.