All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.polyapi.plugin.service.template.PolyHandlebars Maven / Gradle / Ivy

There is a newer version: 0.15.3
Show newest version
package io.polyapi.plugin.service.template;

import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Options;
import com.github.jknack.handlebars.io.ClassPathTemplateLoader;
import io.polyapi.plugin.utils.StringUtils;

import java.util.function.BiPredicate;
import java.util.function.Function;

public class PolyHandlebars extends Handlebars {

    public PolyHandlebars() {
        super(new ClassPathTemplateLoader("/templates", ".hbs"));
        registerSimpleHelper("toCamelCase", StringUtils::toCamelCase);
        registerSimpleHelper("toPascalCase", StringUtils::toCamelCase);
        registerConditionalHelper("ifIsType", (object, options) -> object.getClass().getSimpleName().equals(options.param(0)));
    }

    private  void registerSimpleHelper(String name, Function helper) {
        registerHelper(name, (T object, Options options) -> helper.apply(object));
    }

    private  void registerConditionalHelper(String name, BiPredicate helper) {
        registerHelper(name, new ConditionHelper<>(helper));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy