Commits

Takeshi Komiya committed 58667e2

Add phpautofunction directive; Close #3

  • Participants
  • Parent commits dae9620

Comments (0)

Files changed (7)

src/sphinxcontrib_phpautodoc.py

             last_node = node
 
 
+class PHPAutoFunctionDirective(PHPAutodocDirectiveBase):
+    has_content = True
+    required_arguments = 1
+    directive_name = "phpautofunction"
+
+    option_spec = {
+        'filename': rst.directives.unchanged,
+    }
+
+    def run(self):
+        self.targets = [t.strip() for t in self.arguments[0].split(',')]
+        return super(PHPAutoFunctionDirective, self).run()
+
+    def traverse(self, tree, indent=0):
+        last_node = None
+        for node in tree:
+            if isinstance(node, ast.Function) and node.name in self.targets:
+                self.add_directive('function', to_s(node), last_node, indent, force=True)
+                break
+
+            last_node = node
+
+
 def setup(app):
-    classes = [PHPAutoModuleDirective, PHPAutoClassDirective]
+    classes = [PHPAutoModuleDirective,
+               PHPAutoClassDirective,
+               PHPAutoFunctionDirective]
     for cls in classes:
         app.add_directive(cls.directive_name, cls)

tests/inputs/phpautofunction/function_basic.rst

+.. phpautofunction:: doc_hello
+   :filename: inputs/function.php

tests/inputs/phpautofunction/private_function_basic.rst

+.. phpautofunction:: private_access_hello
+   :filename: inputs/function.php

tests/inputs/phpautofunction/undoc_function_basic.rst

+.. phpautofunction:: undoc_hello
+   :filename: inputs/function.php

tests/outputs/phpautofunction/function_basic.rst

+.. php:function:: doc_hello()
+
+   here is docs for doc_hello function
+

tests/outputs/phpautofunction/private_function_basic.rst

+.. php:function:: private_access_hello()
+

tests/outputs/phpautofunction/undoc_function_basic.rst

+.. php:function:: undoc_hello()
+