summaryrefslogtreecommitdiff
path: root/sphinx/domains/javascript.py
diff options
context:
space:
mode:
authorAnthony Johnson <aj@ohess.org>2017-03-15 23:13:08 -0700
committerAnthony Johnson <aj@ohess.org>2017-03-15 23:13:08 -0700
commit4a61366ff14ff9cda2646455a965bbae404e4780 (patch)
treeb5b07f39d31a44967a9c7f3091c5827f37064613 /sphinx/domains/javascript.py
parent3ba60ffd5dbd86ba3433db952304dcef6a3f023c (diff)
downloadsphinx-git-4a61366ff14ff9cda2646455a965bbae404e4780.tar.gz
Some cleanup
Diffstat (limited to 'sphinx/domains/javascript.py')
-rw-r--r--sphinx/domains/javascript.py35
1 files changed, 15 insertions, 20 deletions
diff --git a/sphinx/domains/javascript.py b/sphinx/domains/javascript.py
index e61a834b6..8ace6c892 100644
--- a/sphinx/domains/javascript.py
+++ b/sphinx/domains/javascript.py
@@ -142,14 +142,14 @@ class JSObject(ObjectDescription):
# type: () -> None
"""Handle object nesting before content
- If this class is a nestable object, such as a class object, build up a
- representation of the nesting heirarchy so that de-nesting multiple
- levels works correctly.
+ :py:class:`PyObject` represents Python language constructs. For
+ constructs that are nestable, such as a Python classes, this method will
+ build up a stack of the nesting heirarchy so that it can be later
+ de-nested correctly, in :py:meth:`after_content`.
- If this class isn't a nestable object, just set the current object
- prefix using the object name. This prefix will be removed with
- :py:meth:`after_content`, and is not added to the list of nested
- object prefixes.
+ For constructs that aren't nestable, the stack is bypassed, and instead
+ only the most recent object is tracked. This object prefix name will be
+ removed with :py:meth:`after_content`.
The following keys are used in ``self.env.ref_context``:
@@ -172,10 +172,8 @@ class JSObject(ObjectDescription):
if prefix:
self.env.ref_context['js:object'] = prefix
if self.allow_nesting:
- try:
- self.env.ref_context['js:objects'].append(prefix)
- except (AttributeError, KeyError):
- self.env.ref_context['js:objects'] = [prefix]
+ objects = self.env.ref_context.setdefault('js:objects', [])
+ objects.append(prefix)
def after_content(self):
# type: () -> None
@@ -188,17 +186,14 @@ class JSObject(ObjectDescription):
be altered as we didn't affect the nesting levels in
:py:meth:`before_content`.
"""
+ objects = self.env.ref_context.setdefault('js:objects', [])
if self.allow_nesting:
try:
- self.env.ref_context['js:objects'].pop()
- except (KeyError, IndexError):
- self.env.ref_context['js:objects'] = []
- try:
- prefix = self.env.ref_context.get('js:objects', [])[-1]
- except IndexError:
- prefix = None
- finally:
- self.env.ref_context['js:object'] = prefix
+ objects.pop()
+ except IndexError:
+ pass
+ self.env.ref_context['js:object'] = (objects[-1] if len(objects) > 0
+ else None)
class JSCallable(JSObject):