sgte icon indicating copy to clipboard operation
sgte copied to clipboard

Add StringTemplate-like iteration over attributes

Open gregorej opened this issue 13 years ago • 3 comments

As far as I am aware at the moment the only way to iterate over an array is a map operation. I think adding a StringTemplate style iteration would be great. I mean something like this:

$["john","mary", "mark", "peter"]:{ it | <b>name:</b> $it$}

Also, this should work for non-array values (treating such value as one-element array)

EDIT: It's just come to me that this is in fact an extension of http://github.com/filippo/sgte/issues/3 (applying function to an attribute) :-)

gregorej avatar Oct 13 '11 07:10 gregorej

I think you can use inline map fo this: $map:{<b>name</b> $it$} names$

Where names is: {names, [{it, "foo"}, {it, "bar"}]}

So it's basically syntactic sugar. What do you think?

filippo avatar Oct 13 '11 08:10 filippo

I don't think it's only syntactic sugar. In order to use map property I have to prepare the Data for render function correctly. Considering above case, following will not work: sgte:render(NameTemplate, [{names, ["john","mary","peter"]}]) I would have to preprocess the list myself to create list with it keys. I think this should be done under the hood.

In other words I would like to be able to iterate over a simple list of elements (without keys) easily.

gregorej avatar Oct 13 '11 08:10 gregorej

Ok I see your point. I'try to come up with a solution.

filippo avatar Oct 13 '11 08:10 filippo