Commits

Anonymous committed ba08db1

Added a vala:currentnamespace directive

Comments (0)

Files changed (2)

sphinx/domains/vala.py

     :license: BSD, see LICENSE for details.
 """
 from sphinx.domains import Domain
+from sphinx.util.compat import Directive
+
+
+class ValaCurrentNamespace(Directive):
+    """
+    This directive tells Sphinx that we're documenting stuff in a namespace
+    foo, you won't be able to reference this.
+    """
+    # TODO: add more tests for this once we have an object type
+
+    has_content = False
+    required_arguments = 1
+    optional_arguments = 0
+    final_argument_whitespace = False
+    option_spec = {}
+
+    def run(self):
+        env = self.state.document.settings.env
+        namespace = self.arguments[0].strip()
+        if namespace == 'global':
+            env.temp_data['vala:namespace'] = None
+        else:
+            env.temp_data['vala:namespace'] = namespace
+        return []
 
 
 class ValaDomain(Domain):
     #       - methods
     #       - interfaces
     #       - structs
+    #       - namespace? this could be used like a python module
     object_types = {}
-    # TODO: add directive for namespace
-    directives = {}
+    directives = {
+        'currentnamespace': ValaCurrentNamespace,
+    }
     roles = {}
     initial_data = {
         'objects': {}, # fullname -> docname, objtype

tests/root/objects.txt

 
 .. js:attribute:: bar.spam
 
+
+Vala items
+==========
+
+.. vala:currentnamespace:: foo
+
+.. vala:currentnamespace:: foo.bar
+
+.. should reset the namespace
+.. vala:currentnamespace:: global
+
+
 References
 ==========
 
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.