solidusjs / solidus

A simple server that generates pages from JSON and Templates
MIT License
28 stars 7 forks source link

Add custom handlebars helpers #45

Closed Fauntleroy closed 10 years ago

Fauntleroy commented 11 years ago

It sure would be great if you could write your own Handlebars helpers.

pushred commented 11 years ago

:+1:

pushred commented 11 years ago

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.

pushred commented 11 years ago

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.

pushred commented 11 years ago

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.

Fauntleroy commented 11 years ago

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:

pushred commented 11 years ago

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.

Fauntleroy commented 11 years ago

or maybe this should be a single function?

{{#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

Fauntleroy commented 11 years ago

And honestly it should be simple to just pass through most native string methods...

monika commented 11 years ago

The ones I remember using the most were the .date, .time, and .range transforms.

Fauntleroy commented 11 years ago
Fauntleroy commented 11 years ago

https://github.com/SparkartGroupInc/solidus/pull/72