Closed Fauntleroy closed 10 years ago
:+1:
Here's the library I mentioned yesterday: http://assemble.io/helpers. It definitely offers a lot of what has been useful in Sugar and what we had in Prose.
Swag is probably a better option. Assemble has taken many of it's helpers from it but on skimming Swag has the ones that are actually important vs. some fluffier ones that are in Assemble (i.e. helpers for inserting # <br>
tags or doctypes). Assemble's docs are better though.
One helper we need that I don't see here is something for some string manipulation of URLs in order to take an image URL from a resource and modify it to use a proxy service such as src.sencha.io or WordPress Photon. We don't really need a helper for Sencha technically, but it would be good to have something general purpose for this, like the moxy/proxy transform.
It might be worthwhile to start developing a list of helpers we'd really like to see. Here are a few I've seen a use case for:
timeago
Generates a "ago" statement from a date-like input. "4 minutes ago", "2 years ago", "13 seconds ago" (should this also deal with future times?)formatDate
Outputs dates with based on a format string from a date-like input. HH-MM-SS becomes "12:35:22". Should be able to handle any amount of time, from seconds to years.replace
Simple string replace. This should be able to handle simple URL replacement issues: "http://sparkart.com/images/cats.jpg" to "http://cdn.sparkart.com/images/cats.jpg"equals
A basic equality checker for things like type: 'news'
.Something for URL encoding would be helpful. Sometimes I need to pass a URL in a query string, i.e. for a redirect parameter.
urlEncode
or simply encode
That passes a string through encodeURIComponent
would be sufficient.
first
A replacement for #each
that loops through the first X items in a list.last
A replacement for #each
that loops through the last X items in a list.or maybe this should be a single function?
range
Loops through start
to finish
. Can be done like so:{{#range things 0 5}}
first 5 items in a list
{{#range things 5}}
from item 5 to the end of the list
{{#range things 5 10}}
from item 5 to item 10 in a list
{{#range things -5}}
from item length-5 to the end of the list
And honestly it should be simple to just pass through most native string methods...
The ones I remember using the most were the .date, .time, and .range transforms.
{{#where items title=kittens}}
loops through all items where the title
is kittens
. Tests with ==
.{{#number plays quantity}}
a helper for managing numbers. Can convert 1000
to 1,000
or one thousand
.{{#boolean isCat}}
convert something boolean-like ("true"
,0
,1
,etc) into a real boolean.
It sure would be great if you could write your own Handlebars helpers.