From bf37e515d2b5affec6296c34fbfa68fa89f7d4b9 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 16 Apr 2015 12:16:40 +0200 Subject: [PATCH] fix(docs): corrected cursor handling in mkdocs The trick was to use an actual list of cursor tokens that is consumed on use. That way, we don't loose track of were we are in the structure. Related to #64 --- src/mako/cli/docs/commands.md.mako | 36 ++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/mako/cli/docs/commands.md.mako b/src/mako/cli/docs/commands.md.mako index efc8b154b5..28aa596ae8 100644 --- a/src/mako/cli/docs/commands.md.mako +++ b/src/mako/cli/docs/commands.md.mako @@ -158,36 +158,48 @@ ${SPLIT_END} - ${p.get('description') or NO_DESC | xml_escape ,indent_all_but_first_by(2)} -<%def name="_list_schem_args(schema, abs_cursor='')">\ +<%def name="_list_schem_args(schema, cursor_tokens=list())">\ <% + if len(cursor_tokens) == 0: + cursor_tokens = [FIELD_SEP] + def cursor_fmt(cursor): - return '-%s %s ' % (STRUCT_FLAG, cursor) + fndfi = 0 # first non-dot field index + for (fndfi, v) in enumerate(cursor): + if v != FIELD_SEP: + break + return '-%s %s ' % (STRUCT_FLAG, ''.join(cursor[:fndfi]) + FIELD_SEP.join(cursor[fndfi:])) def cursor_arg(): - if abs_cursor: - return cursor_fmt(abs_cursor) + if cursor_tokens: + res = cursor_fmt(cursor_tokens) + del cursor_tokens[:] + return res return '' - abs_cursor_arg = cursor_arg() %>\ % for fn in sorted(schema.fields.keys()): <% f = schema.fields[fn] - cursor_prefix = '' - if abs_cursor == '': - cursor_prefix = FIELD_SEP %>\ % if isinstance(f, SchemaEntry): -* **${abs_cursor_arg}-${STRUCT_FLAG} ${mangle_subcommand(fn)}=${field_to_value(f)}** +* **${cursor_arg()}-${STRUCT_FLAG} ${mangle_subcommand(fn)}=${field_to_value(f)}** - ${f.property.get('description', NO_DESC) | xml_escape, indent_all_but_first_by(2)} % if f.container_type == CTYPE_ARRAY: - Each invocation of this argument appends the given value to the array. % elif f.container_type == CTYPE_MAP: - the value will be associated with the given `key` % endif # handle container type -<% abs_cursor_arg = '' %> % else: -${self._list_schem_args(f, '%s%s' % (cursor_prefix, mangle_subcommand(fn)))} -<% abs_cursor_arg = cursor_fmt(FIELD_SEP + FIELD_SEP) %>\ +<% + cursor_tokens.append(mangle_subcommand(fn)) +%>\ +${self._list_schem_args(f, cursor_tokens)} +<% + assert not cursor_tokens or cursor_tokens[-1] == FIELD_SEP + if not cursor_tokens: + cursor_tokens.append(FIELD_SEP) + cursor_tokens.append(FIELD_SEP) +%>\ % endif % endfor \ No newline at end of file