samskivert / jmustache

A Java implementation of the Mustache templating language.
Other
841 stars 128 forks source link

Current support filter method? #80

Closed zlx closed 8 years ago

zlx commented 8 years ago

Hi

sorry about disturb. I use the library in my project. It's so great for mostly case.

But when I want to make some simple convert, for eg: phone_number => phoneNumber, It's seem hard.

Does it have some way to complete the convert now? AKA does it support some method like https://github.com/Shopify/liquid/wiki/Liquid-for-Designers#standard-filters

Thank you.

yihtserns commented 8 years ago

Create an underscore-to-camelCase Lambda?

samskivert commented 8 years ago

I'm not 100% sure of your requirements, but I think a lambda is is probably the right approach. You can put a set of "filter lambdas" into your top-level context, like:

Map<String,Object> ctx = new HashMap<>();
ctx.put("upcase", new Template.Lambda() {
  public void execute (Template.Fragment frag, Writer out) {
    String contents = frag.execute();
    out.write(contents.toUpperCase());
  }
});

and so forth for all the filters you want.

zlx commented 8 years ago

Hi, @samskivert, It seem the filter lambda is match my requirements. Thanks