spf13/hugo — pull request #706 by halostatue (2014-12-09 06:07:02+00:00)
Title: WIP: `apply` function over sequence

@derekperkins, I was playing around with the code in #683 tonight and it’s
missing some functionality that I really want—and I mostly have it working, but
there are some incompatibilities with the `delimit` function as written.

Basically, I want to replace this:

```html
{{ with .Params.tags }}

Tags//
{{ $len := len . }}
{{ if eq $len 1 }}
{{ partial "post/tag/link" (index . 0) }}
{{ else }}
{{ $last := sub $len 1 }}
{{ range first $last . }}
{{ partial "post/tag/link" . }},
{{ end }}
{{ partial "post/tag/link" (index . $last) }}
{{ end }}

{{ end }}
```

with this:

```html
{{ with .Params.tags }}

Tags//
{{ delimit (apply (sort .) "partial" "post/tag/link" ".") ", " }}

{{ end }}
```

This means:

1. Sort .Params.tags.
2. Loop over .Params.tags, replacing each tag with the output of `partial`
with `"post/tag/link"` as the partial and the tag as the context (`.`).
3. Delimit the resulting objects with `", "`.

The result of `partial` is an HTML template, which is not trivially convertible
to a string, so I’m hitting panics in the delimit code because it tries to
`cast.StringE` each value. If that isn’t done, you can’t easily concatenate the
delimiters to HTML template…and you want it to be `safeHtml` in this case (but
I could probably do that with an appropriate `| safeHtml` at the end of the
`delimit`).

There’s a few things I don’t like about this particular syntax, but it offers
some intriguing capabilities if we can get it working (I *do* have `apply`
working in this branch, but not with your functions underneath).