You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dust.js (at least LinkedIn's version) has a useful {@sep} capability to denote what "separator" should be used when generating list entries. It's akin to the "join" operator for an array.
Well, it was easy enough to write a helper function
forEachWithSep: (list, itemFn, sep) ->
for idx, item of list
itemFn item
if idx < list.length - 1
switch typeof sep
when 'string'
text sep
when 'function'
sep()
that I could then call generically
forEachWithSep links,
(link) -> a href:"/#{link.path}", link.name ## Note: arbitrary item handler function
", "
Dust.js (at least LinkedIn's version) has a useful {@sep} capability to denote what "separator" should be used when generating list entries. It's akin to the "join" operator for an array.
I can't quite figure out the best way to do this in coffeecup. It's easy to generate a list of links:
but producing them as a comma-separated list is more problematic.
Since coffeecup is "generating" results to a special buffer rather than "returning" results to coffeescript, I can't use a normal "join" operator.
I'm hoping there's a nifty mechanism to do this without resorting to index counting and emitting a
text ', '
for all-but-the-last list item.Any solutions to this? Can I encapsulate this sort of functionality in a helper somehow? Am I overlooking something trivial?
The text was updated successfully, but these errors were encountered: