MustacheExtensionPoint

MustacheExtensionPoint.java
package org.jreleaser.extensions.api.mustache;

import org.jreleaser.extensions.api.ExtensionPoint;

import java.util.Map;

/**
 * Enables customization of the Mustache context used when evaluating named templates.
 *
 * @author Andres Almiray
 * @since 1.3.0
 */
public interface MustacheExtensionPoint extends ExtensionPoint {
    /**
     * Enhances the given context with additional properties.
     * <p>
     * <strong>WARNING: </strong> be careful when defining key names
     * as you may override existing ones.
     *
     * @param context the evaluation context.
     */
    void apply(Map<String, Object> context);
}

Example:

The following extension point adds a new function named f_chop:

package com.acme;

import java.util.Map;
import java.util.function.Function;
import org.apache.commons.lang3.StringUtils;
import org.jreleaser.extensions.api.mustache.MustacheExtensionPoint;

public final class MyMustacheExtensionPoint implements MustacheExtensionPoint {
    public void apply(Map<String, Object> context) {
        context.put("f_chop", new ChopFunction());
    }

    private static class ChopFunction implements Function<String, String> {
        @Override
        public String apply(String input) {
            return StringUtils.chop(input);
        }
    }
}

With this extension in place you’ll be able to invoke the function on a template, such as

{{#f_chop}}JReleaser{{/f_chop}}

Which will result in JRelease when evaluated.