docs(mbuild): more information, nicer visuals

This commit is contained in:
Sebastian Thiel
2015-03-05 16:21:39 +01:00
parent a3206abc92
commit 4e8872b37a
2 changed files with 507 additions and 622 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -24,9 +24,11 @@
required_props, optional_props, part_prop = organize_params(params, request_value) required_props, optional_props, part_prop = organize_params(params, request_value)
is_string_value = lambda v: v.endswith('"') is_string_value = lambda v: v.endswith('"')
# to rust value
trv = lambda spn, sp, sn=None: to_rust_type(sn, spn, sp, allow_optionals=False)
# rvfrt = random value for rust type # rvfrt = random value for rust type
rvfrt = lambda spn, sp, sn=None: rnd_arg_val_for_type(to_rust_type(sn, spn, sp, allow_optionals=False)) rvfrt = lambda spn, sp, sn=None: rnd_arg_val_for_type(trv(spn, sp, sn))
rb_name = 'request' # name of request binding rb_name = 'req' # name of request binding
required_args = request_value and ['&' + rb_name] or [] required_args = request_value and ['&' + rb_name] or []
for p in required_props: for p in required_props:
# could also just skip the first element, but ... let's be safe # could also just skip the first element, but ... let's be safe
@@ -39,6 +41,8 @@
required_args.append(v) required_args.append(v)
# end for each required property # end for each required property
required_args = ', '.join(required_args) required_args = ', '.join(required_args)
random_value_warning = "Values shown here are random and not representative !"
%>\ %>\
% if 'description' in m: % if 'description' in m:
${m.description | rust_doc_comment} ${m.description | rust_doc_comment}
@@ -53,43 +57,47 @@ ${m.description | rust_doc_comment}
/// ///
<%block filter="rust_doc_test_norun, rust_doc_comment">\ <%block filter="rust_doc_test_norun, rust_doc_comment">\
${capture(util.test_prelude) | hide_rust_doc_test}\ ${capture(util.test_prelude) | hide_rust_doc_test}\
# use ${util.library_name()}::*; % if request_value:
# use ${util.library_name()}::${request_value.id};
% endif
<%block filter="rust_test_fn_invisible">\ <%block filter="rust_test_fn_invisible">\
${capture(lib.test_hub, hub_type_name, comments=False) | hide_rust_doc_test} ${capture(lib.test_hub, hub_type_name, comments=False) | hide_rust_doc_test}
% if request_value: % if request_value:
// As the method needs a request, you would usually fill it with the desired information. // As the method needs a request, you would usually fill it with the desired information
// What can actually be filled in depends on the actual call - the following is just a // into the respective structure.
// random selection of properties ! Values are random and not representative ! // ${random_value_warning}
let mut ${rb_name}: ${request_value.id} = Default::default(); let mut ${rb_name}: ${request_value.id} = Default::default();
% for spn, sp in request_value.get('properties', dict()).iteritems(): % for spn, sp in request_value.get('properties', dict()).iteritems():
<% <%
assignment = rvfrt(spn, sp, request_value.id) rtn = trv(spn, sp, request_value.id)
assignment = rnd_arg_val_for_type(rtn)
if is_string_value(assignment): if is_string_value(assignment):
assignment = assignment + '.to_string()' assignment = assignment + '.to_string()'
if assignment.endswith('default()'): if assignment.endswith('default()'):
assignment = assignment[1:] # cut & - it's not ok in this case :)! assignment = assignment[1:] # cut & - it's not ok in this case :)!
assignment += '; // is %s' % rtn
else: else:
assignment = 'Some(%s)' % assignment assignment = 'Some(%s);' % assignment
%>\ %>\
## ${to_rust_type(request_value.id, spn, sp, allow_optionals=False)} ## ${to_rust_type(request_value.id, spn, sp, allow_optionals=False)}
${rb_name}.${mangle_ident(spn)} = ${assignment}; ${rb_name}.${mangle_ident(spn)} = ${assignment}
% endfor % endfor
% endif % endif
// Even though you wouldn't bind this to a variable, you can configure optional parameters // You can configure optional parameters by calling the respective setters at will, and
// by calling the respective setters. // execute the final call using `${api.terms.action}()`.
// Values are random and not representative ! % if optional_props:
let mut mb = hub.${mangle_ident(resource)}().${mangle_ident(method)}(${required_args})\ // ${random_value_warning}
% endif
let result = hub.${mangle_ident(resource)}().${mangle_ident(method)}(${required_args})\
% for p in optional_props: % for p in optional_props:
<%block filter="indent_by(8)">\ <%block filter="indent_by(8)">\
.${mangle_ident(p.name)}(${rvfrt(p.name, p)})\ .${mangle_ident(p.name)}(${rvfrt(p.name, p)})\
</%block>\ </%block>\
% endfor % endfor
; .${api.terms.action}();
// TODO: show how to handle the result !
// Finally, execute your call and process the result
mb.${api.terms.action}()
</%block> </%block>
</%block> </%block>
pub struct ${ThisType} pub struct ${ThisType}