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

com.github.jknack.handlebars.Lambda Maven / Gradle / Ivy

The newest version!
/*
 * Handlebars.java: https://github.com/jknack/handlebars.java
 * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
 * Copyright (c) 2012 Edgar Espina
 */
package com.github.jknack.handlebars;

import java.io.IOException;

/**
 * When the value is a callable object, such as a lambda, the object will be invoked and passed the
 * block of text. The text passed is the literal block, unrendered. {{tags}} will not have been
 * expanded - the lambda should do that on its own. In this way you can implement filters or
 * caching.
 *
 * 

Template: * *

 * {{#wrapped}}
 * {{name}} is awesome.
 * {{/wrapped}}
 * 
* * Hash: * *
 * Map hash = ...
 * hash.put("name", "Willy");
 * hash.put("wrapped", new Lambda<String>() {
 *   public String apply(Scope scope, Template template) {
 *    return "" + template.apply(scope) + "";
 *   }
 * });
 * 
* *

Output: * *

 * Willy is awesome.
 * 
* * @author edgar.espina * @param The lambda context. * @param The lambda output. */ public interface Lambda { /** * Apply the lambda. * * @param context The current context. * @param template The current template. * @return The resulting text. * @throws IOException If the resource cannot be loaded. */ O apply(C context, Template template) throws IOException; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy