linkedin/dustjs — pull request #264 by sethkinast (2013-04-25 03:19:27+00:00)
Title: Enhance filters to accept variables, using syntax similar to Liquid or Twig

Hi!

I've added support for Dust's filters to accept arguments. This allows for syntax such as:

{foo|replace:"bar","baz"}

Or even:

{some_text|link_to:"{url}"}

The syntax is the same as that supported by Twig, the popular PHP templating language, and Liquid, which is used by lots of Ruby projects including Shopify. Filter variables are extremely useful when you need to do some simple string manipulation that is too simple to need a helper! Some examples of filters that use variables in Liquid: https://github.com/Shopify/liquid/wiki/Liquid-for-Designers

The change is completely backwards-compatible. All tests still pass. I also added six new tests around the new functionality-- please check them out to get an idea of how filter variables work.

To have something to test with, I did add two filters to dust.filters-- "replace" and "link_to". I understand those probably don't permanently belong in the core but I know there is some movement around filters anyways so hopefully they can find a temporary home in core and migrate on when we have a place for them.

As an unrelated change, I noticed that the browser test suite had some incorrect logic that was removing some of the test cases erroneously, so I've fixed that as well.

As this is a new, backwards-compatible change, I also incremented the minor version, making this Dust 1.3.0.

Thank you for reviewing this change!