From 75d25b7f47542aa003c92ce576b6e82bae66aec9 Mon Sep 17 00:00:00 2001 From: Giovanni Campagna Date: Wed, 19 Feb 2014 16:19:53 +0100 Subject: doctool: improve Gjs documentation - Add documentation for structures, fields, constants and callbacks - Improve the synopsis for interfaces to have prerequisites and known implementations - Respect gjs constraints for field writability - Format in and out parameters for callables according to GJS conventions - Format property names according to the GJS API - Show boxed constructors according to how they can be used in the gjs API https://bugzilla.gnome.org/show_bug.cgi?id=724735 --- giscanner/doctemplates/C/callback.tmpl | 4 ++++ giscanner/doctemplates/C/field.tmpl | 1 + giscanner/doctemplates/C/function.tmpl | 17 ++++++++-------- giscanner/doctemplates/C/interface.tmpl | 2 ++ giscanner/doctemplates/Gjs/callback.tmpl | 27 ++++++++++++++++++++++++++ giscanner/doctemplates/Gjs/class.tmpl | 11 +++++++---- giscanner/doctemplates/Gjs/field.tmpl | 9 +++++++++ giscanner/doctemplates/Gjs/function.tmpl | 23 +++++++++++----------- giscanner/doctemplates/Gjs/interface.tmpl | 17 ++++++++++++++++ giscanner/doctemplates/Gjs/property.tmpl | 7 +++---- giscanner/doctemplates/Gjs/signal.tmpl | 19 +++++++++--------- giscanner/doctemplates/Gjs/vfunc.tmpl | 14 +++++++------- giscanner/doctemplates/Python/callback.tmpl | 27 ++++++++++++++++++++++++++ giscanner/doctemplates/Python/class.tmpl | 9 +++++---- giscanner/doctemplates/Python/field.tmpl | 1 + giscanner/doctemplates/Python/function.tmpl | 22 ++++++++------------- giscanner/doctemplates/Python/interface.tmpl | 16 +++++++++++++++ giscanner/doctemplates/Python/property.tmpl | 5 ++--- giscanner/doctemplates/Python/signal.tmpl | 13 ++++++------- giscanner/doctemplates/Python/vfunc.tmpl | 20 +++++++------------ giscanner/doctemplates/base.tmpl | 29 ++++++++++------------------ giscanner/doctemplates/class.tmpl | 27 +++++++++++++++++++++++--- giscanner/doctemplates/namespace.tmpl | 11 ++++------- 23 files changed, 216 insertions(+), 115 deletions(-) create mode 100644 giscanner/doctemplates/C/callback.tmpl create mode 100644 giscanner/doctemplates/C/field.tmpl create mode 100644 giscanner/doctemplates/C/interface.tmpl create mode 100644 giscanner/doctemplates/Gjs/callback.tmpl create mode 100644 giscanner/doctemplates/Gjs/field.tmpl create mode 100644 giscanner/doctemplates/Gjs/interface.tmpl create mode 100644 giscanner/doctemplates/Python/callback.tmpl create mode 100644 giscanner/doctemplates/Python/field.tmpl create mode 100644 giscanner/doctemplates/Python/interface.tmpl (limited to 'giscanner/doctemplates') diff --git a/giscanner/doctemplates/C/callback.tmpl b/giscanner/doctemplates/C/callback.tmpl new file mode 100644 index 00000000..f285ff68 --- /dev/null +++ b/giscanner/doctemplates/C/callback.tmpl @@ -0,0 +1,4 @@ +<%inherit file="./function.tmpl"/> +<%block name="info"> + ${formatter.format_xref(node.parent, type="guide", group=page_kind)} + diff --git a/giscanner/doctemplates/C/field.tmpl b/giscanner/doctemplates/C/field.tmpl new file mode 100644 index 00000000..b66ae926 --- /dev/null +++ b/giscanner/doctemplates/C/field.tmpl @@ -0,0 +1 @@ +<%inherit file="/base.tmpl"/> diff --git a/giscanner/doctemplates/C/function.tmpl b/giscanner/doctemplates/C/function.tmpl index 8d669438..3f9e6275 100644 --- a/giscanner/doctemplates/C/function.tmpl +++ b/giscanner/doctemplates/C/function.tmpl @@ -6,7 +6,7 @@ ${formatter.format_type(node.retval.type) | x} ${formatter.format_function_name(node)} -% for arg in formatter.get_parameters(node): +% for arg in formatter.get_in_parameters(node): % if arg.type.ctype == '': % else: @@ -19,12 +19,12 @@ <%block name="synopsis"> - + ${node.retval.type.ctype} ${formatter.format_function_name(node)} (\ -% if not formatter.get_parameters(node): +% if not formatter.get_in_parameters(node): void\ % else: -% for ix, arg in enumerate(formatter.get_parameters(node)): +% for ix, arg in enumerate(formatter.get_in_parameters(node)): % if ix != 0: ${' ' * (len(formatter.format_type(node.retval.type)) + len(formatter.format_function_name(node)) + 3)}\ % endif @@ -33,18 +33,17 @@ ${' ' * (len(formatter.format_type(node.retval.type)) + len(formatter.format_fun % else: ${formatter.format_type(arg.type) | x} ${arg.argname}\ % endif -% if ix != len(formatter.get_parameters(node)) - 1: +% if ix != len(formatter.get_in_parameters(node)) - 1: , % endif % endfor % endif ); - - + <%block name="details"> -% if formatter.get_parameters(node) or node.retval: +% if formatter.get_in_parameters(node) or node.retval: -% for arg in formatter.get_parameters(node): +% for arg in formatter.get_in_parameters(node): <code>${arg.argname}</code> ${formatter.format(node, arg.doc)} diff --git a/giscanner/doctemplates/C/interface.tmpl b/giscanner/doctemplates/C/interface.tmpl new file mode 100644 index 00000000..3f18b021 --- /dev/null +++ b/giscanner/doctemplates/C/interface.tmpl @@ -0,0 +1,2 @@ +<%! page_type="guide" %>\ +<%inherit file="/class.tmpl"/> diff --git a/giscanner/doctemplates/Gjs/callback.tmpl b/giscanner/doctemplates/Gjs/callback.tmpl new file mode 100644 index 00000000..d7b97794 --- /dev/null +++ b/giscanner/doctemplates/Gjs/callback.tmpl @@ -0,0 +1,27 @@ +<%inherit file="/base.tmpl"/> +<%block name="synopsis"> + +function on${node.name}(\ +${', '.join('%s: %s' % (arg.argname, formatter.format_type(arg.type, True)) for arg in formatter.get_in_parameters(node))}\ +): ${formatter.format_out_parameters(node)} { +} + +<%block name="details"> +% if formatter.has_any_parameters(node): + +% for arg in formatter.get_in_parameters(node): + +<code>${arg.argname}</code> +${formatter.format(node, arg.doc)} + +% endfor +% for arg in formatter.get_out_parameters(node): + +<code>${(arg.argname + ' (out)') if arg.direction == 'inout' else arg.argname}</code> +${formatter.format(node, arg.doc)} + +% endfor + +% endif + + diff --git a/giscanner/doctemplates/Gjs/class.tmpl b/giscanner/doctemplates/Gjs/class.tmpl index 887c646b..d8433704 100644 --- a/giscanner/doctemplates/Gjs/class.tmpl +++ b/giscanner/doctemplates/Gjs/class.tmpl @@ -3,16 +3,19 @@ const ${namespace.name} = imports.gi.${namespace.name}; -let ${formatter.to_underscores(node.name).lower()} = new ${namespace.name}.${node.name}(\ +let ${formatter.to_lower_camel_case(node.name)} = new ${namespace.name}.${node.name}(\ +% if isinstance(node, (ast.Class, ast.Interface)): % if len(node.properties) > 0: { % for ix, property_ in enumerate(node.properties): -% if property_.construct or property_.construct_only or property_.writable: +% if (property_.construct or property_.construct_only) and property_.writable: ${property_.name.replace('-', '_')}: value, % endif % endfor }\ % endif +% else: +${formatter.format_gboxed_constructor(node)}\ +% endif ); - - + diff --git a/giscanner/doctemplates/Gjs/field.tmpl b/giscanner/doctemplates/Gjs/field.tmpl new file mode 100644 index 00000000..dda82469 --- /dev/null +++ b/giscanner/doctemplates/Gjs/field.tmpl @@ -0,0 +1,9 @@ +<%inherit file="/base.tmpl"/> +<%block name="info"> + ${formatter.format_xref(node.parent, type="guide", group=page_kind)} + ${node.name} + +<%block name="synopsis"> + +${node.parent.name}.${formatter.to_underscores(node)}: ${formatter.format_type(node.type, True)} (${formatter.format_property_flags(node)}) + diff --git a/giscanner/doctemplates/Gjs/function.tmpl b/giscanner/doctemplates/Gjs/function.tmpl index e0fd9612..012978ac 100644 --- a/giscanner/doctemplates/Gjs/function.tmpl +++ b/giscanner/doctemplates/Gjs/function.tmpl @@ -6,7 +6,7 @@ ${formatter.format_type(node.retval.type) | x} ${node.symbol} -% for arg in formatter.get_parameters(node): +% for arg in formatter.get_in_parameters(node): % if arg.type.ctype == '': % else: @@ -19,30 +19,29 @@ <%block name="synopsis"> - + function \ ${node.name}(\ -${', '.join('%s:%s' % (arg.argname, formatter.format_type(arg.type)) for arg in formatter.get_parameters(node))}\ -):${formatter.format_type(node.retval.type)} { +${', '.join('%s: %s' % (arg.argname, formatter.format_type(arg.type, True)) for arg in formatter.get_in_parameters(node))}\ +): ${formatter.format_out_parameters(node)} { // Gjs wrapper for ${node.symbol}() } - - + <%block name="details"> -% if formatter.get_parameters(node) or node.retval: +% if formatter.has_any_parameters(node): -% for arg in formatter.get_parameters(node): +% for arg in formatter.get_in_parameters(node): <code>${arg.argname}</code> ${formatter.format(node, arg.doc)} % endfor -% if node.retval and node.retval.type.ctype != 'void': +% for arg in formatter.get_out_parameters(node): -<code>Returns</code> -${formatter.format(node, node.retval.doc)} +<code>${(arg.argname + ' (out)') if arg.direction == 'inout' else arg.argname}</code> +${formatter.format(node, arg.doc)} -% endif +% endfor % endif diff --git a/giscanner/doctemplates/Gjs/interface.tmpl b/giscanner/doctemplates/Gjs/interface.tmpl new file mode 100644 index 00000000..2f01f20f --- /dev/null +++ b/giscanner/doctemplates/Gjs/interface.tmpl @@ -0,0 +1,17 @@ +<%inherit file="/class.tmpl"/> +<%block name="synopsis"> + +const ${namespace.name} = imports.gi.${namespace.name}; + +let ${formatter.to_underscores(node).lower()} = new ${namespace.name}.${node.name}(\ +% if len(node.properties) > 0: +{ +% for ix, property_ in enumerate(node.properties): +% if (property_.construct or property_.construct_only) and property_.writable: + ${property_.name.replace('-', '_')}: value, +% endif +% endfor +}\ +% endif +); + diff --git a/giscanner/doctemplates/Gjs/property.tmpl b/giscanner/doctemplates/Gjs/property.tmpl index 3316a00c..dda82469 100644 --- a/giscanner/doctemplates/Gjs/property.tmpl +++ b/giscanner/doctemplates/Gjs/property.tmpl @@ -4,7 +4,6 @@ ${node.name} <%block name="synopsis"> - -"${node.name}" ${formatter.format_type(node.type)} : ${formatter.format_property_flags(node)} - - + +${node.parent.name}.${formatter.to_underscores(node)}: ${formatter.format_type(node.type, True)} (${formatter.format_property_flags(node)}) + diff --git a/giscanner/doctemplates/Gjs/signal.tmpl b/giscanner/doctemplates/Gjs/signal.tmpl index 084d9743..7c508162 100644 --- a/giscanner/doctemplates/Gjs/signal.tmpl +++ b/giscanner/doctemplates/Gjs/signal.tmpl @@ -4,21 +4,22 @@ ${node.name} <%block name="synopsis"> - -function callback(${formatter.to_underscores(node.parent.name).lower()}, \ -% for arg in formatter.get_parameters(node): -${arg.argname}:${formatter.format_type(arg.type)}, \ + +connect('${node.name}', function (${formatter.to_lower_camel_case(node.parent.name)}, \ +% for arg in formatter.get_in_parameters(node): +% if arg.type.target_fundamental != 'none': +${arg.argname}: ${formatter.format_type(arg.type, True)}, \ +% endif % endfor -):${formatter.format_type(node.retval.type)}; - - +): ${formatter.format_type(node.retval.type, True)}); + <%block name="details"> -<code>${formatter.to_underscores(node.parent.name).lower()}</code> +<code>${formatter.to_lower_camel_case(node.parent.name)}</code>

instance of ${formatter.format_xref(node.parent)} that is emitting the signal

-% for arg in formatter.get_parameters(node): +% for arg in formatter.get_in_parameters(node): <code>${arg.argname}</code> ${formatter.format(node, arg.doc)} diff --git a/giscanner/doctemplates/Gjs/vfunc.tmpl b/giscanner/doctemplates/Gjs/vfunc.tmpl index 1cbe511c..2bd1127d 100644 --- a/giscanner/doctemplates/Gjs/vfunc.tmpl +++ b/giscanner/doctemplates/Gjs/vfunc.tmpl @@ -1,16 +1,15 @@ <%inherit file="/base.tmpl"/> <%block name="synopsis"> - + function vfunc_${node.name}(\ -${', '.join('%s:%s' % (arg.argname, formatter.format_type(arg.type)) for arg in formatter.get_parameters(node))}\ -):${formatter.format_type(node.retval.type)} { +${', '.join('%s: %s' % (arg.argname, formatter.format_type(arg.type, True)) for arg in formatter.get_in_parameters(node))}\ +): ${formatter.format_out_parameters(node)} { } - - + <%block name="details"> -% if formatter.get_parameters(node) or node.retval: +% if formatter.get_in_parameters(node) or node.retval: -% for arg in formatter.get_parameters(node): +% for arg in formatter.get_in_parameters(node): <code>${arg.argname}</code> ${formatter.format(node, arg.doc)} @@ -25,3 +24,4 @@ ${formatter.format(node, node.retval.doc)} % endif + diff --git a/giscanner/doctemplates/Python/callback.tmpl b/giscanner/doctemplates/Python/callback.tmpl new file mode 100644 index 00000000..4fcbfe3b --- /dev/null +++ b/giscanner/doctemplates/Python/callback.tmpl @@ -0,0 +1,27 @@ +<%inherit file="/base.tmpl"/> +<%block name="synopsis"> + +% if formatter.get_in_parameters(node): +@accepts(${', '.join((formatter.format_type(arg.type) for arg in formatter.get_in_parameters(node)))}) +% endif +@returns(${formatter.format_type(node.retval.type) | x}) +def on_${node.name}(${', '.join((arg.argname for arg in formatter.get_in_parameters(node)))}): + +<%block name="details"> +% if formatter.get_in_parameters(node) or node.retval: + +% for arg in formatter.get_in_parameters(node): + +<code>${arg.argname}</code> +${formatter.format(node, arg.doc)} + +% endfor +% if node.retval and node.retval.type.ctype != 'void': + +<code>Returns</code> +${formatter.format(node, node.retval.doc)} + +% endif + +% endif + diff --git a/giscanner/doctemplates/Python/class.tmpl b/giscanner/doctemplates/Python/class.tmpl index 435b31a5..51d25a91 100644 --- a/giscanner/doctemplates/Python/class.tmpl +++ b/giscanner/doctemplates/Python/class.tmpl @@ -3,7 +3,8 @@ from gi.repository import ${namespace.name} -${formatter.to_underscores(node.name).lower()} = ${namespace.name}.${node.name}(\ +${formatter.to_underscores(node).lower()} = ${namespace.name}.${node.name}(\ +% if isinstance(node, (ast.Class, ast.Interface)): % for ix, property_ in enumerate(node.properties): % if property_.construct or property_.construct_only or property_.writable: ${property_.name.replace('-', '_')}=value\ @@ -12,6 +13,6 @@ ${formatter.to_underscores(node.name).lower()} = ${namespace.name}.${node.name}( % endif % endif % endfor -)\ - - +% endif +) + diff --git a/giscanner/doctemplates/Python/field.tmpl b/giscanner/doctemplates/Python/field.tmpl new file mode 100644 index 00000000..b66ae926 --- /dev/null +++ b/giscanner/doctemplates/Python/field.tmpl @@ -0,0 +1 @@ +<%inherit file="/base.tmpl"/> diff --git a/giscanner/doctemplates/Python/function.tmpl b/giscanner/doctemplates/Python/function.tmpl index 072a1185..7ad1ac04 100644 --- a/giscanner/doctemplates/Python/function.tmpl +++ b/giscanner/doctemplates/Python/function.tmpl @@ -6,7 +6,7 @@ ${formatter.format_type(node.retval.type) | x} ${node.symbol} -% for arg in formatter.get_parameters(node): +% for arg in formatter.get_in_parameters(node): % if arg.type.ctype == '': % else: @@ -19,24 +19,18 @@ <%block name="synopsis"> - -% if formatter.get_parameters(node): -@accepts(\ -${', '.join((formatter.format_type(arg.type) for arg in formatter.get_parameters(node)))}\ -) + +% if formatter.get_in_parameters(node): +@accepts(${', '.join((formatter.format_type(arg.type) for arg in formatter.get_in_parameters(node)))}) % endif @returns(${formatter.format_type(node.retval.type) | x}) -def \ -${node.name}(\ -${', '.join((formatter.format_parameter_name(node, arg) for arg in formatter.get_parameters(node)))}\ -): +def ${node.name}(${', '.join((formatter.format_parameter_name(node, arg) for arg in formatter.get_in_parameters(node)))}): # Python wrapper for ${node.symbol}() - - + <%block name="details"> -% if formatter.get_parameters(node) or node.retval: +% if formatter.get_in_parameters(node) or node.retval: -% for ix, arg in enumerate(formatter.get_parameters(node)): +% for ix, arg in enumerate(formatter.get_in_parameters(node)): <code>${formatter.format_parameter_name(node, arg)}</code> ${formatter.format(node, arg.doc)} diff --git a/giscanner/doctemplates/Python/interface.tmpl b/giscanner/doctemplates/Python/interface.tmpl new file mode 100644 index 00000000..b3596a8d --- /dev/null +++ b/giscanner/doctemplates/Python/interface.tmpl @@ -0,0 +1,16 @@ +<%inherit file="/class.tmpl"/> +<%block name="synopsis"> + +from gi.repository import ${namespace.name} + +${formatter.to_underscores(node).lower()} = ${namespace.name}.${node.name}(\ +% for ix, property_ in enumerate(node.properties): +% if property_.construct or property_.construct_only or property_.writable: +${property_.name.replace('-', '_')}=value\ +% if ix != len(node.properties) - 1: +, \ +% endif +% endif +% endfor +)\ + diff --git a/giscanner/doctemplates/Python/property.tmpl b/giscanner/doctemplates/Python/property.tmpl index 3316a00c..c93d59b7 100644 --- a/giscanner/doctemplates/Python/property.tmpl +++ b/giscanner/doctemplates/Python/property.tmpl @@ -4,7 +4,6 @@ ${node.name} <%block name="synopsis"> - + "${node.name}" ${formatter.format_type(node.type)} : ${formatter.format_property_flags(node)} - - + diff --git a/giscanner/doctemplates/Python/signal.tmpl b/giscanner/doctemplates/Python/signal.tmpl index dc931107..c61b7229 100644 --- a/giscanner/doctemplates/Python/signal.tmpl +++ b/giscanner/doctemplates/Python/signal.tmpl @@ -4,21 +4,20 @@ ${node.name} <%block name="synopsis"> - -def callback(${formatter.to_underscores(node.parent.name).lower()}, \ -% for arg in formatter.get_parameters(node): + +def callback(${formatter.to_underscores(node.parent).lower()}, \ +% for arg in formatter.get_in_parameters(node): ${arg.argname}, \ % endfor user_param1, ...) - - + <%block name="details"> -<code>${formatter.to_underscores(node.parent.name).lower()}</code> +<code>${formatter.to_underscores(node.parent).lower()}</code>

instance of ${formatter.format_xref(node.parent)} that is emitting the signal

-% for arg in formatter.get_parameters(node): +% for arg in formatter.get_in_parameters(node): <code>${arg.argname}</code> ${formatter.format(node, arg.doc)} diff --git a/giscanner/doctemplates/Python/vfunc.tmpl b/giscanner/doctemplates/Python/vfunc.tmpl index 98a30932..2c532e70 100644 --- a/giscanner/doctemplates/Python/vfunc.tmpl +++ b/giscanner/doctemplates/Python/vfunc.tmpl @@ -1,22 +1,16 @@ <%inherit file="/base.tmpl"/> <%block name="synopsis"> - -% if formatter.get_parameters(node): -@accepts(\ -${', '.join((formatter.format_type(arg.type) for arg in formatter.get_parameters(node)))}\ -) + +% if formatter.get_in_parameters(node): +@accepts(${', '.join((formatter.format_type(arg.type) for arg in formatter.get_in_parameters(node)))}) % endif @returns(${formatter.format_type(node.retval.type) | x}) -def \ -do_${node.name}(\ -${', '.join((arg.argname for arg in formatter.get_parameters(node)))}\ -): - - +def do_${node.name}(${', '.join((arg.argname for arg in formatter.get_in_parameters(node)))}): + <%block name="details"> -% if formatter.get_parameters(node) or node.retval: +% if formatter.get_in_parameters(node) or node.retval: -% for arg in formatter.get_parameters(node): +% for arg in formatter.get_in_parameters(node): <code>${arg.argname}</code> ${formatter.format(node, arg.doc)} diff --git a/giscanner/doctemplates/base.tmpl b/giscanner/doctemplates/base.tmpl index 78980773..7a1d8db2 100644 --- a/giscanner/doctemplates/base.tmpl +++ b/giscanner/doctemplates/base.tmpl @@ -6,24 +6,15 @@ xmlns="http://projectmallard.org/1.0/" xmlns:api="http://projectmallard.org/experimental/api/" xmlns:ui="http://projectmallard.org/1.0/ui/"> - - <%block name="info"> - ${formatter.format_xref(node.parent, type="guide", group=page_kind)} - + <%block name="info"> + ${formatter.format_xref(node.parent, type="guide", group=page_kind)} +\ - <%block name="title">${formatter.format_page_name(node)}</%block> - <%block name="synopsis"> - - <%block name="doc"> - ${formatter.format(node, node.doc)} - - <%block name="since_version"> - % if node.version: -

Since ${node.version}

- % endif - - <%block name="details"> - - <%block name="links"> - + <%block name="title">${formatter.format_page_name(node)}</%block><%block name="synopsis"><%block name="doc"> +${formatter.format(node, node.doc)} +<%block name="since_version">\ +% if node.version: +

Since ${node.version}

\ +% endif +<%block name="details"><%block name="links"> diff --git a/giscanner/doctemplates/class.tmpl b/giscanner/doctemplates/class.tmpl index 7f8b6869..86333866 100644 --- a/giscanner/doctemplates/class.tmpl +++ b/giscanner/doctemplates/class.tmpl @@ -1,6 +1,7 @@ <%! page_type="guide" %>\ <%inherit file="/base.tmpl"/> <%block name="details"> +% if isinstance(node, ast.Class): Hierarchy @@ -13,8 +14,23 @@ % endfor +% elif isinstance(node, ast.Interface): + + Prerequisites +

${node.name} requires ${formatter.format_prerequisites(node)}

+
+ + Known Implementations +

${formatter.format_known_implementations(node)}

+
+% endif -<%block name="links"> +<%block name="links">\ + + Constructors + @@ -23,8 +39,9 @@ - Functions + Static Functions +% if isinstance(node, (ast.Class, ast.Interface)): Properties @@ -34,7 +51,11 @@ Virtual functions +% endif + + Fields + Other - + \ diff --git a/giscanner/doctemplates/namespace.tmpl b/giscanner/doctemplates/namespace.tmpl index bb58bb16..d4edcec0 100644 --- a/giscanner/doctemplates/namespace.tmpl +++ b/giscanner/doctemplates/namespace.tmpl @@ -1,11 +1,9 @@ <%! page_type="guide" %>\ <%inherit file="/base.tmpl"/> -<%block name="doc"> - -<%block name="info"> - +<%block name="doc"> +<%block name="info"> <%block name="links"> - + Classes @@ -15,5 +13,4 @@ Other -<%block name="since_version"> - +<%block name="since_version"> -- cgit v1.2.1