Package ratpack.handlebars
Interface NamedHelper<T>
-
- Type Parameters:
T
- The context object type.
- All Superinterfaces:
com.github.jknack.handlebars.Helper<T>
public interface NamedHelper<T> extends com.github.jknack.handlebars.Helper<T>
Implementations of this interface bound with Guice will be automatically registered as handlebars helpers.import com.github.jknack.handlebars.Options; import ratpack.guice.Guice; import ratpack.handlebars.HandlebarsModule; import ratpack.handlebars.NamedHelper; import ratpack.test.embed.EphemeralBaseDir; import ratpack.test.embed.EmbeddedApp; import java.io.IOException; import java.nio.file.Path; import static ratpack.handlebars.Template.handlebarsTemplate; import static org.junit.jupiter.api.Assertions.*; public class Example { public static class HelloHelper implements NamedHelper<String> { public String getName() { return "hello"; } public CharSequence apply(String context, Options options) throws IOException { return "Hello " + context.toUpperCase() + "!"; } } public static void main(String... args) throws Exception { EphemeralBaseDir.tmpDir().use(baseDir -> { baseDir.write("handlebars/myTemplate.html.hbs", "{{hello \"ratpack\"}}"); EmbeddedApp.of(s -> s .serverConfig(c -> c.baseDir(baseDir.getRoot())) .registry(Guice.registry(b -> b .module(new HandlebarsModule()) .bind(HelloHelper.class) )) .handlers(chain -> chain .get(ctx -> ctx.render(handlebarsTemplate("myTemplate.html"))) ) ).test(httpClient -> { assertEquals("Hello RATPACK!", httpClient.getText()); }); }); } }
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description String
getName()
-
-
-
Method Detail
-
getName
String getName()
-
-