docs(lib): cross linking of resources/activities

This makes it so much easier to get to the example call you are
interested in.
It's getting there, slowly ;)
This commit is contained in:
Sebastian Thiel
2015-03-08 18:58:15 +01:00
parent 4b12da4a12
commit ac35432b3f
7 changed files with 199 additions and 109 deletions

View File

@@ -1,6 +1,6 @@
<%! from util import (activity_split, put_and, md_italic, split_camelcase_s, canonical_type_name,
rust_test_fn_invisible, rust_doc_test_norun, rust_doc_comment, markdown_rust_block,
unindent_first_by, mangle_ident) %>\
unindent_first_by, mangle_ident, mb_type, singular) %>\
<%namespace name="util" file="util.mako"/>\
## If rust-doc is True, examples will be made to work for rust doc tests. Otherwise they are set
@@ -18,7 +18,22 @@
Handle the following *Resources* with ease ...
% for r in sorted(c.rta_map.keys()):
* ${split_camelcase_s(r)} (${put_and(md_italic(sorted(c.rta_map[r])))})
<%
md_methods = list()
for method in sorted(c.rta_map[r]):
if rust_doc:
md_methods.append("[*%s*](struct.%s.html)" % (method, mb_type(r, method)))
else:
# TODO: link to final destination, possibly just have one for all ...
md_methods.append("*%s*" % method)
md_resource = split_camelcase_s(r)
sn = singular(canonical_type_name(r))
if rust_ddoc and sn in schemas:
md_resource = '[%s](struct.%s.html)' % (md_resource, singular(canonical_type_name(r)))
%>\
* ${md_resource} (${put_and(md_methods)})
% endfor
# Structure of this Library

View File

@@ -1,8 +1,10 @@
<%! from util import (schema_markers, rust_doc_comment, mangle_ident, to_rust_type, put_and,
IO_TYPES, activity_split, enclose_in, REQUEST_MARKER)
IO_TYPES, activity_split, enclose_in, REQUEST_MARKER_TRAIT, mb_type)
%>\
## Create new schema with everything.
## 's' contains the schema structure from json to build
###################################################################################################################
###################################################################################################################
<%def name="new(s, c)">\
<%
## assert s.type == "object"
@@ -28,7 +30,7 @@ pub struct ${s.id}\
impl ${marker_trait} for ${s.id} {}
% endfor
% if REQUEST_MARKER in markers:
% if REQUEST_MARKER_TRAIT in markers:
impl ${s.id} {
/// Return a comma separated list of members that are currently set, i.e. for which `self.member.is_some()`.
/// The produced string is suitable for use as a parts list that indicates the parts you are sending, and/or
@@ -53,6 +55,8 @@ impl ${s.id} {
% endif
</%def>
#########################################################################################################
#########################################################################################################
<%def name="doc(s, c)">\
${s.get('description', 'There is no detailed description.')}
% if s.id in c.sta_map:
@@ -62,7 +66,7 @@ ${s.get('description', 'There is no detailed description.')}
This type is used in activities, which are methods you may call on this type or where this type is involved in.
The list links the activity name, along with information about where it is used (one of ${put_and(enclose_in('*', IO_TYPES))}).
${''.join("* %s (%s)\n" % (activity_split(a)[1], iot and '|'.join(iot) or 'none')
${''.join("* [%s](struct.%s.html) (%s)\n" % (activity_split(a)[1], mb_type(*activity_split(a)[:2]), iot and '|'.join(iot) or 'none')
for a, iot in c.sta_map[s.id].iteritems())}
% else:

View File

@@ -43,7 +43,9 @@ NESTED_TYPE_MARKER = 'is_nested'
SPACES_PER_TAB = 4
REQUEST_PRIORITY = 100
REQUEST_MARKER = 'RequestValue'
REQUEST_MARKER_TRAIT = 'RequestValue'
PART_MARKER_TRAIT = 'Part'
NESTED_MARKER_TRAIT = 'NestedType'
REQUEST_VALUE_PROPERTY_NAME = 'request'
PROTOCOL_TYPE_INFO = {
@@ -55,7 +57,7 @@ If the upload fails for whichever reason, all progress is lost.""",
'default': 'fs::File',
'where': 'Read',
'suffix': '',
'example_value': 'fs::File::open("filepath.ext").unwrap(), 148, "application/octet-stream".parse().unwrap()'
'example_value': 'fs::File::open("file.ext").unwrap(), 148, "application/octet-stream".parse().unwrap()'
},
'resumable' : {
'arg_name': 'resumeable_stream',
@@ -68,7 +70,7 @@ TODO: Write more about how delegation works in this particular case.""",
'default': 'fs::File',
'where': 'ReadSeek',
'suffix': '_resumable',
'example_value': 'fs::File::open("filepath.ext").unwrap(), 282, "application/octet-stream".parse().unwrap()'
'example_value': 'fs::File::open("file.ext").unwrap(), 282, "application/octet-stream".parse().unwrap()'
}
}
@@ -339,7 +341,7 @@ def schema_markers(s, c):
activities = c.sta_map.get(s.id, dict())
if len(activities) == 0:
res.add('Part')
res.add(PART_MARKER_TRAIT)
else:
# it should have at least one activity that matches it's type to qualify for the Resource trait
for fqan, iot in activities.iteritems():
@@ -348,12 +350,12 @@ def schema_markers(s, c):
if IO_RESPONSE in iot:
res.add('ResponseResult')
if IO_REQUEST in iot:
res.add(REQUEST_MARKER)
res.add(REQUEST_MARKER_TRAIT)
# end for each activity
# end handle activites
if is_nested_type(s):
res.add('NestedType')
res.add(NESTED_MARKER_TRAIT)
return sorted(res)

View File

@@ -34,3 +34,11 @@ pub trait NestedType: MarkerTrait {}
/// A utility to specify reader types which provide seeking capabilities too
pub trait ReadSeek: Seek + Read {}
impl<T: Seek + Read> ReadSeek for T {}
/// A utility type which can decode a server response that indicates error
#[derive(RustcDecodable)]
struct JsonServerError {
error: String,
error_description: Option<String>
}