From d758f410f68b84cb635a6a0633bb09b147939397 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 17 Mar 2015 17:16:27 +0100 Subject: [PATCH] feat(doit): repeatable parameters working The code dealing with them currently assumes they are "/" separated. --- src/mako/lib/mbuild.mako | 22 ++++++++++++++++++++-- src/mako/lib/util.py | 7 ++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/mako/lib/mbuild.mako b/src/mako/lib/mbuild.mako index 5dd7d811a1..72cfb46f02 100644 --- a/src/mako/lib/mbuild.mako +++ b/src/mako/lib/mbuild.mako @@ -160,6 +160,12 @@ ${self._setter_fn(resource, method, m, p, part_prop, ThisType, c)}\ <% InType = activity_input_type(schemas, p) + is_repeated_property = p.get('repeated', False) + if is_repeated_property: + p.repeated = False + InType = activity_input_type(schemas, p) + p.repeated = True + def show_part_info(m, p): if p.name != 'part': return False @@ -169,7 +175,7 @@ ${self._setter_fn(resource, method, m, p, part_prop, ThisType, c)}\ value_name = 'new_value' new_value_copied = rust_copy_value_s(value_name, InType, p) - if not is_required_property(p): + if not is_required_property(p) and not is_repeated_property: new_value_copied = 'Some(%s)' % new_value_copied part_desc = None @@ -198,7 +204,11 @@ ${self._setter_fn(resource, method, m, p, part_prop, ThisType, c)}\ ${p.description | rust_doc_comment, indent_all_but_first_by(1)} % endif pub fn ${mangle_ident(p.name)}(mut self, ${value_name}: ${InType}) -> ${ThisType} { + % if p.get('repeated', False): + self.${property(p.name)}.push(${new_value_copied}); + % else: self.${property(p.name)} = ${new_value_copied}; + % endif self } @@ -421,7 +431,15 @@ match result { } % endif % endif - % if not is_required_property(p): + % if p.get('repeated', False): + if ${pname}.len() > 0 { + let mut s = String::new(); + for f in ${pname}.iter() { + s.push_str(&("/".to_string() + f)); + } + params.push(("${p.name}", s)); + } + % elif not is_required_property(p): if ${pname}.is_some() { params.push(("${p.name}", ${pname}.unwrap().to_string())); } diff --git a/src/mako/lib/util.py b/src/mako/lib/util.py index 634824c9b0..35d7722e67 100644 --- a/src/mako/lib/util.py +++ b/src/mako/lib/util.py @@ -330,7 +330,12 @@ def to_rust_type(schemas, sn, pn, t, allow_optionals=True): rust_type = 'i64' elif rust_type == USE_FORMAT: rust_type = TYPE_MAP[t.format] - return wrap_type(rust_type) + + if t.get('repeated', False): + rust_type = 'Vec<%s>' % rust_type + else: + rust_type = wrap_type(rust_type) + return rust_type except KeyError as err: raise AssertionError("%s: Property type '%s' unknown - add new type mapping: %s" % (str(err), t.type, str(t))) except AttributeError as err: