Skip to content

Commit d92a292

Browse files
author
Mike Dirolf
committed
mongohub doc stuff
1 parent 191d883 commit d92a292

File tree

4 files changed

+101
-1
lines changed

4 files changed

+101
-1
lines changed

doc/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# Add any Sphinx extension module names here, as strings. They can be extensions
1515
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
1616
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.coverage',
17-
'sphinx.ext.todo']
17+
'sphinx.ext.todo', 'doc.mongo_extensions']
1818

1919
# Add any paths that contain templates here, relative to this directory.
2020
templates_path = ['_templates']

doc/mongo_extensions.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Copyright 2009 10gen, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""MongoDB specific extensions to Sphinx."""
16+
17+
from docutils import nodes
18+
from docutils.writers import html4css1
19+
from sphinx import addnodes
20+
from sphinx.util.compat import (Directive,
21+
make_admonition)
22+
23+
class mongodoc(nodes.Admonition, nodes.Element):
24+
pass
25+
26+
class mongoref(nodes.reference):
27+
pass
28+
29+
30+
def visit_mongodoc_node(self, node):
31+
self.visit_admonition(node, "seealso")
32+
33+
34+
def depart_mongodoc_node(self, node):
35+
self.depart_admonition(node)
36+
37+
38+
def visit_mongoref_node(self, node):
39+
atts = {"class": "reference external",
40+
"href": node["refuri"],
41+
"name": node["name"]}
42+
self.body.append(self.starttag(node, 'a', '', **atts))
43+
44+
45+
def depart_mongoref_node(self, node):
46+
self.body.append('</a>')
47+
if not isinstance(node.parent, nodes.TextElement):
48+
self.body.append('\n')
49+
50+
51+
class MongodocDirective(Directive):
52+
53+
has_content = True
54+
required_arguments = 0
55+
optional_arguments = 0
56+
final_argument_whitespace = False
57+
option_spec = {}
58+
59+
def run(self):
60+
env = self.state.document.settings.env
61+
62+
return make_admonition(mongodoc, self.name,
63+
[_('See general MongoDB documentation')],
64+
self.options, self.content, self.lineno,
65+
self.content_offset, self.block_text, self.state,
66+
self.state_machine)
67+
68+
69+
def process_mongodoc_nodes(app, doctree, fromdocname):
70+
env = app.builder.env
71+
72+
for node in doctree.traverse(mongodoc):
73+
for name in node.parent.parent.traverse(addnodes.desc_signature):
74+
anchor = "#%s" % name["ids"][0]
75+
break
76+
for para in node.traverse(nodes.paragraph):
77+
tag = str(para.traverse()[1])
78+
link = mongoref("", "")
79+
link["refuri"] = "http://dochub.mongodb.org/core/%s" % tag
80+
link["name"] = anchor
81+
link.append(nodes.emphasis(_(tag), _(tag)))
82+
new_para = nodes.paragraph()
83+
new_para += link
84+
node.replace(para, new_para)
85+
break
86+
87+
88+
def setup(app):
89+
app.add_node(mongodoc,
90+
html=(visit_mongodoc_node, depart_mongodoc_node),
91+
latex=(visit_mongodoc_node, depart_mongodoc_node),
92+
text=(visit_mongodoc_node, depart_mongodoc_node))
93+
app.add_node(mongoref,
94+
html=(visit_mongoref_node, depart_mongoref_node))
95+
96+
app.add_directive("mongodoc", MongodocDirective)
97+
app.connect("doctree-resolved", process_mongodoc_nodes)

pymongo/collection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,8 @@ def find(self, spec=None, fields=None, skip=0, limit=0,
421421
422422
.. versionadded:: 1.1
423423
The `tailable` parameter.
424+
425+
.. mongodoc:: find
424426
"""
425427
if spec is None:
426428
spec = SON()

0 commit comments

Comments
 (0)