io.polyapi.plugin.service.template.PolyHandlebars Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of polyapi-maven-plugin Show documentation
Show all versions of polyapi-maven-plugin Show documentation
Maven plugin to run handle Poly API functions.
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));
}
}