Now add data samples for the wanted protocols on the data types
This commit is contained in:
parent
bcf76e7075
commit
3d77a5e692
10
doc/_static/toggle.css
vendored
Normal file
10
doc/_static/toggle.css
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
dl.toggle dt {
|
||||||
|
background-color: #eeffcc;
|
||||||
|
border: 1px solid #ac9;
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
|
||||||
|
dl.toggle dd {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
9
doc/_static/toggle.js
vendored
Normal file
9
doc/_static/toggle.js
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
/*global $,document*/
|
||||||
|
$(document).ready(function () {
|
||||||
|
"use strict";
|
||||||
|
$("dl.toggle > dt").click(
|
||||||
|
function (event) {
|
||||||
|
$(this).next().toggle(250);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
@ -224,3 +224,7 @@ man_pages = [
|
|||||||
|
|
||||||
|
|
||||||
autodoc_member_order = 'bysource'
|
autodoc_member_order = 'bysource'
|
||||||
|
|
||||||
|
wsme_protocols = [
|
||||||
|
'restjson', 'restxml', 'soap', 'extdirect'
|
||||||
|
]
|
||||||
|
@ -16,6 +16,14 @@ class SampleType(object):
|
|||||||
#: A Int
|
#: A Int
|
||||||
aint = int
|
aint = int
|
||||||
|
|
||||||
|
def __init__(self, aint=None):
|
||||||
|
if aint:
|
||||||
|
self.aint = aint
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def sample(cls):
|
||||||
|
return SampleType(10)
|
||||||
|
|
||||||
|
|
||||||
class TypeDirective(PyClasslike):
|
class TypeDirective(PyClasslike):
|
||||||
pass
|
pass
|
||||||
@ -35,6 +43,10 @@ class TypeDocumenter(autodoc.ClassDocumenter):
|
|||||||
|
|
||||||
required_arguments = 1
|
required_arguments = 1
|
||||||
|
|
||||||
|
option_spec = dict(autodoc.ClassDocumenter.option_spec, **{
|
||||||
|
'protocols': lambda l: [v.strip() for v in l.split(',')]
|
||||||
|
})
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def can_document_member(cls, member, membername, isattr, parent):
|
def can_document_member(cls, member, membername, isattr, parent):
|
||||||
# we don't want to be automaticaly used
|
# we don't want to be automaticaly used
|
||||||
@ -44,6 +56,9 @@ class TypeDocumenter(autodoc.ClassDocumenter):
|
|||||||
def format_name(self):
|
def format_name(self):
|
||||||
return self.object.__name__
|
return self.object.__name__
|
||||||
|
|
||||||
|
def format_signature(self):
|
||||||
|
return u''
|
||||||
|
|
||||||
def add_directive_header(self, sig):
|
def add_directive_header(self, sig):
|
||||||
super(TypeDocumenter, self).add_directive_header(sig)
|
super(TypeDocumenter, self).add_directive_header(sig)
|
||||||
# remove the :module: option that was added by ClassDocumenter
|
# remove the :module: option that was added by ClassDocumenter
|
||||||
@ -57,6 +72,34 @@ class TypeDocumenter(autodoc.ClassDocumenter):
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def add_content(self, more_content, no_docstring=False):
|
||||||
|
protocols = self.options.protocols or self.env.app.config.wsme_protocols
|
||||||
|
protocols = [wsme.protocols.getprotocol(p) for p in protocols]
|
||||||
|
content = []
|
||||||
|
if protocols:
|
||||||
|
sample_obj = getattr(self.object, 'sample', self.object)()
|
||||||
|
content.extend([
|
||||||
|
l_(u'Data samples:'),
|
||||||
|
u'',
|
||||||
|
u'.. cssclass:: toggle',
|
||||||
|
u''
|
||||||
|
])
|
||||||
|
for protocol in protocols:
|
||||||
|
language, sample = protocol.encode_sample_value(
|
||||||
|
self.object, sample_obj, format=True)
|
||||||
|
content.extend([
|
||||||
|
protocol.displayname or protocol.name,
|
||||||
|
u' .. code-block:: ' + language,
|
||||||
|
u'',
|
||||||
|
])
|
||||||
|
content.extend((
|
||||||
|
u' ' * 8 + line for line in sample.split('\n')))
|
||||||
|
for line in content:
|
||||||
|
self.add_line(line, u'<wsme.sphinxext')
|
||||||
|
super(TypeDocumenter, self).add_content(
|
||||||
|
more_content, no_docstring)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AttributeDocumenter(autodoc.AttributeDocumenter):
|
class AttributeDocumenter(autodoc.AttributeDocumenter):
|
||||||
datatype = None
|
datatype = None
|
||||||
@ -73,7 +116,8 @@ class AttributeDocumenter(autodoc.AttributeDocumenter):
|
|||||||
return success
|
return success
|
||||||
|
|
||||||
def add_content(self, more_content, no_docstring=False):
|
def add_content(self, more_content, no_docstring=False):
|
||||||
self.add_line(u':type: %s' % self.datatype.__name__, '<sphinxext>')
|
self.add_line(u':type: %s' % self.datatype.__name__, '<wsme.sphinxext>')
|
||||||
|
self.add_line(u'', '<wsme.sphinxext>')
|
||||||
super(AttributeDocumenter, self).add_content(
|
super(AttributeDocumenter, self).add_content(
|
||||||
more_content, no_docstring)
|
more_content, no_docstring)
|
||||||
|
|
||||||
@ -98,3 +142,7 @@ def setup(app):
|
|||||||
app.add_domain(WSMEDomain)
|
app.add_domain(WSMEDomain)
|
||||||
app.add_autodocumenter(TypeDocumenter)
|
app.add_autodocumenter(TypeDocumenter)
|
||||||
app.add_autodocumenter(AttributeDocumenter)
|
app.add_autodocumenter(AttributeDocumenter)
|
||||||
|
|
||||||
|
app.add_config_value('wsme_protocols', ['restjson', 'restxml'], 'env')
|
||||||
|
app.add_javascript('toggle.js')
|
||||||
|
app.add_stylesheet('toggle.css')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user