mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Some cleanup
This commit is contained in:
parent
3ba60ffd5d
commit
4a61366ff1
@ -142,14 +142,14 @@ class JSObject(ObjectDescription):
|
|||||||
# type: () -> None
|
# type: () -> None
|
||||||
"""Handle object nesting before content
|
"""Handle object nesting before content
|
||||||
|
|
||||||
If this class is a nestable object, such as a class object, build up a
|
:py:class:`PyObject` represents Python language constructs. For
|
||||||
representation of the nesting heirarchy so that de-nesting multiple
|
constructs that are nestable, such as a Python classes, this method will
|
||||||
levels works correctly.
|
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
|
For constructs that aren't nestable, the stack is bypassed, and instead
|
||||||
prefix using the object name. This prefix will be removed with
|
only the most recent object is tracked. This object prefix name will be
|
||||||
:py:meth:`after_content`, and is not added to the list of nested
|
removed with :py:meth:`after_content`.
|
||||||
object prefixes.
|
|
||||||
|
|
||||||
The following keys are used in ``self.env.ref_context``:
|
The following keys are used in ``self.env.ref_context``:
|
||||||
|
|
||||||
@ -172,10 +172,8 @@ class JSObject(ObjectDescription):
|
|||||||
if prefix:
|
if prefix:
|
||||||
self.env.ref_context['js:object'] = prefix
|
self.env.ref_context['js:object'] = prefix
|
||||||
if self.allow_nesting:
|
if self.allow_nesting:
|
||||||
try:
|
objects = self.env.ref_context.setdefault('js:objects', [])
|
||||||
self.env.ref_context['js:objects'].append(prefix)
|
objects.append(prefix)
|
||||||
except (AttributeError, KeyError):
|
|
||||||
self.env.ref_context['js:objects'] = [prefix]
|
|
||||||
|
|
||||||
def after_content(self):
|
def after_content(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
@ -188,17 +186,14 @@ class JSObject(ObjectDescription):
|
|||||||
be altered as we didn't affect the nesting levels in
|
be altered as we didn't affect the nesting levels in
|
||||||
:py:meth:`before_content`.
|
:py:meth:`before_content`.
|
||||||
"""
|
"""
|
||||||
|
objects = self.env.ref_context.setdefault('js:objects', [])
|
||||||
if self.allow_nesting:
|
if self.allow_nesting:
|
||||||
try:
|
try:
|
||||||
self.env.ref_context['js:objects'].pop()
|
objects.pop()
|
||||||
except (KeyError, IndexError):
|
except IndexError:
|
||||||
self.env.ref_context['js:objects'] = []
|
pass
|
||||||
try:
|
self.env.ref_context['js:object'] = (objects[-1] if len(objects) > 0
|
||||||
prefix = self.env.ref_context.get('js:objects', [])[-1]
|
else None)
|
||||||
except IndexError:
|
|
||||||
prefix = None
|
|
||||||
finally:
|
|
||||||
self.env.ref_context['js:object'] = prefix
|
|
||||||
|
|
||||||
|
|
||||||
class JSCallable(JSObject):
|
class JSCallable(JSObject):
|
||||||
|
Loading…
Reference in New Issue
Block a user