本文整理匯總了Java中com.github.jknack.handlebars.Handlebars.with方法的典型用法代碼示例。如果您正苦於以下問題:Java Handlebars.with方法的具體用法?Java Handlebars.with怎麽用?Java Handlebars.with使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.github.jknack.handlebars.Handlebars
的用法示例。
在下文中一共展示了Handlebars.with方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: MaTemplateEngine
import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
public MaTemplateEngine(TemplateLoader loader) {
loader.setSuffix(null);
handlebars = new Handlebars(loader);
// Set Guava cache.
Cache<TemplateSource, Template> cache = CacheBuilder.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES)
.maximumSize(1000).build();
handlebars = handlebars.with(new GuavaTemplateCache(cache));
}
示例2: HandlebarsTemplateEngine
import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
/**
* Constructs a handlebars template engine
*
* @param resourceRoot the resource root
*/
public HandlebarsTemplateEngine(String resourceRoot) {
TemplateLoader templateLoader = new ClassPathTemplateLoader();
templateLoader.setPrefix(resourceRoot);
templateLoader.setSuffix(null);
handlebars = new Handlebars(templateLoader);
// Set Guava cache.
Cache<TemplateSource, Template> cache = CacheBuilder.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES)
.maximumSize(1000).build();
handlebars = handlebars.with(new GuavaTemplateCache(cache));
}
示例3: generateBlueprintWithParameters
import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
private String generateBlueprintWithParameters(String blueprintText, Cluster cluster, Set<RDSConfig> rdsConfigs) throws IOException {
Handlebars handlebars = new Handlebars();
handlebars.with(EscapingStrategy.NOOP);
handlebars.registerHelperMissing(new Helper<Object>() {
@Override
public CharSequence apply(final Object context, final Options options) throws IOException {
return options.fn.text();
}
});
Template template = handlebars.compileInline(blueprintText, "{{{", "}}}");
return template.apply(prepareTemplateObject(cluster.getBlueprintInputs().get(Map.class), cluster, rdsConfigs));
}
示例4: HandlebarsApi
import com.github.jknack.handlebars.Handlebars; //導入方法依賴的package包/類
/**
* Initialize Handlebars engine, register cache, handlers.
*
* @param environment
* Play environment, used for getting templates folder.
* Could be null for the inline rendering.
* @param config
* Play configuration, used for getting properties.
* @param messagesApi
* MessagesApi, used in message helper.
* @param assetsFinder
* AssetsFinder, used in assets helper.
*/
@Inject
public HandlebarsApi(
final Environment environment,
final Config config,
final MessagesApi messagesApi,
final AssetsFinder assetsFinder) {
this.messagesApi = messagesApi;
this.assetsFinder = assetsFinder;
// Initialize the properties.
final Properties properties = new Properties(config);
// Get the template folder.
final File rootFolder =
(environment == null) ? null : environment.getFile(properties.getDirectory());
// Put the template extension.
final TemplateLoader loader =
(rootFolder == null) ? null : new FileTemplateLoader(rootFolder, properties.getExtension());
// Initialize the engine with the cache
handlebars = new Handlebars(loader);
if (properties.isCacheEnabled()) {
// Initialize the cache. Could be builded from configuration as well
// For example:
// CacheBuilder.from(config.getString("hbs.cache")).build()
final Cache<TemplateSource, Template> cache = CacheBuilder.newBuilder()
.expireAfterWrite(10, TimeUnit.MINUTES).maximumSize(1000).build();
final GuavaTemplateCache guavaCache = new GuavaTemplateCache(cache);
handlebars.with(guavaCache);
}
// Add helpers.
// MessagesApi is a singleton so we can use it in helpers.
// All assets helpers will use this AssetsFinder.
PlayHelpers helpers = new PlayHelpers(messagesApi, assetsFinder, environment);
handlebars.registerHelpers(helpers);
handlebars.registerHelpers(StringHelpers.class);
}