本文整理汇总了Java中com.github.jknack.handlebars.io.TemplateLoader类的典型用法代码示例。如果您正苦于以下问题:Java TemplateLoader类的具体用法?Java TemplateLoader怎么用?Java TemplateLoader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TemplateLoader类属于com.github.jknack.handlebars.io包,在下文中一共展示了TemplateLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import com.github.jknack.handlebars.io.TemplateLoader; //导入依赖的package包/类
@Override
public void start(Future<Void> startFuture) throws Exception {
TemplateLoader loader = new ClassPathTemplateLoader(TEMPLATE_DIR);
StarterService starter = new StarterService(vertx, tempDir());
ProjectGeneratorService generator = new ProjectGeneratorService(vertx, new TemplateService(vertx, loader));
ArchiveService archive = new ArchiveService(vertx);
vertx.eventBus().<JsonObject>consumer("project.requested").handler(starter::starter);
vertx.eventBus().<JsonObject>consumer("generate").handler(generator::generate);
vertx.eventBus().<JsonObject>consumer("archive").handler(archive::archive);
vertx.eventBus().<JsonObject>consumer("project.created").handler(starter::clean);
log.info("\n----------------------------------------------------------\n\t" +
"{} is running!\n" +
"----------------------------------------------------------",
GeneratorVerticle.class.getSimpleName());
startFuture.complete();
}
示例2: start
import com.github.jknack.handlebars.io.TemplateLoader; //导入依赖的package包/类
@Override
public void start(Future<Void> startFuture) throws Exception {
TemplateLoader loader = new ClassPathTemplateLoader(TEMPLATE_DIR);
ForgeService forge = new ForgeService(vertx, tempDir());
ProjectGeneratorService generator = new ProjectGeneratorService(vertx, new TemplateService(loader));
ArchiveService archive = new ArchiveService(vertx);
vertx.eventBus().<JsonObject>consumer("forge.forge").handler(forge::forge);
vertx.eventBus().<JsonObject>consumer("forge.clean").handler(forge::clean);
vertx.eventBus().<JsonObject>consumer("generate").handler(generator::generate);
vertx.eventBus().<JsonObject>consumer("archive").handler(archive::archive);
log.info("\n----------------------------------------------------------\n\t" +
"{} is running!\n" +
"----------------------------------------------------------",
GeneratorVerticle.class.getSimpleName());
startFuture.complete();
}
示例3: create
import com.github.jknack.handlebars.io.TemplateLoader; //导入依赖的package包/类
static Handlebars create(final List<TemplateLoader> templateLoaders, final I18nResolver i18NResolver, final I18nIdentifierFactory i18nIdentifierFactory) {
if (templateLoaders.isEmpty()) {
throw new SunriseConfigurationException("Could not initialize Handlebars due to missing template loaders configuration", CONFIG_TEMPLATE_LOADERS);
}
logger.info("Provide Handlebars: template loaders [{}]]",
templateLoaders.stream().map(TemplateLoader::getPrefix).collect(joining(", ")));
final TemplateLoader[] loaders = templateLoaders.toArray(new TemplateLoader[templateLoaders.size()]);
final Handlebars handlebars = new Handlebars()
.with(loaders)
.with(new HighConcurrencyTemplateCache())
.infiniteLoops(true);
handlebars.registerHelper("i18n", new HandlebarsI18nHelper(i18NResolver, i18nIdentifierFactory));
handlebars.registerHelper("cms", new HandlebarsCmsHelper());
handlebars.registerHelper("json", new HandlebarsJsonHelper<>());
return handlebars;
}
示例4: it_should_build_a_compiler
import com.github.jknack.handlebars.io.TemplateLoader; //导入依赖的package包/类
@Test
public void it_should_build_a_compiler() throws Exception {
MustacheTemplateLoader templateLoader = mock(MustacheTemplateLoader.class);
Handlebars handlebars = mock(Handlebars.class);
when(handlebars.with(any(TemplateLoader.class))).thenReturn(handlebars);
HandlebarsCompiler hbCompiler = new HandlebarsCompiler(handlebars, templateLoader);
Handlebars hb = (Handlebars) readField(hbCompiler, "handlebars", true);
MustacheTemplateLoader tmplLoader = (MustacheTemplateLoader) readField(hbCompiler, "templateLoader", true);
assertThat(hb).isNotNull().isSameAs(handlebars);
assertThat(tmplLoader).isNotNull();
ArgumentCaptor<HandlebarsTemplateLoader> hbTemplateLoader = ArgumentCaptor.forClass(HandlebarsTemplateLoader.class);
verify(handlebars).with(hbTemplateLoader.capture());
MustacheTemplateLoader hbInternalLoader = (MustacheTemplateLoader) readField(hbTemplateLoader.getValue(), "loader", true);
assertThat(hbInternalLoader).isNotNull().isSameAs(tmplLoader);
}
示例5: MaTemplateEngine
import com.github.jknack.handlebars.io.TemplateLoader; //导入依赖的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));
}
示例6: emailTemplateLoader
import com.github.jknack.handlebars.io.TemplateLoader; //导入依赖的package包/类
@Bean
public TemplateLoader emailTemplateLoader(ResourceLoader resourceLoader) {
SpringTemplateLoader templateLoader = new SpringTemplateLoader(resourceLoader);
templateLoader.setPrefix("classpath:handlebars");
templateLoader.setSuffix(".hbs");
return templateLoader;
}
示例7: emailHandlebars
import com.github.jknack.handlebars.io.TemplateLoader; //导入依赖的package包/类
@Bean
public Handlebars emailHandlebars(TemplateLoader templateLoader, MessageSource messageSource) {
return new Handlebars(templateLoader)
.with(new HighConcurrencyTemplateCache())
.registerHelpers(HandlebarsHelperSource.class)
.registerHelpers(new HandlebarsHelperSource(messageSource));
}
示例8: Config
import com.github.jknack.handlebars.io.TemplateLoader; //导入依赖的package包/类
/**
* Private constructor to prevent other code from instantiating this.
*/
private Config() {
if (!Files.exists(Paths.get(RESOURCE_PATH))) {
throw new RuntimeException("Could not find path to resources. Run JAR file from repo root.");
}
try {
jsonConfig = new ObjectMapper().readValue(new File(getResourcePath("/config.json")), JsonConfig.class);
} catch (IOException e) {
LOGGER.error("Failed to read config.json: {}", e);
}
TemplateLoader loader = new FileTemplateLoader(getResourcePath(HANDLEBARS_DIRECTORY_PATH),
HANDLEBARS_FILE_EXTENSION);
this.handlebars = new Handlebars(loader);
}
示例9: HandlebarsTemplateEngine
import com.github.jknack.handlebars.io.TemplateLoader; //导入依赖的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));
}
示例10: initializeTemplateLoader
import com.github.jknack.handlebars.io.TemplateLoader; //导入依赖的package包/类
protected static TemplateLoader initializeTemplateLoader(final Configuration loaderConfig) {
final String type = loaderConfig.getString(TYPE_ATTR);
final String path = loaderConfig.getString(PATH_ATTR);
switch (type) {
case CLASSPATH_TYPE:
return new ClassPathTemplateLoader(path);
case FILE_TYPE:
return new FileTemplateLoader(path);
default:
throw new SunriseConfigurationException("Could not initialize Handlebars due to unrecognized template loader \"" + type + "\"", CONFIG_TEMPLATE_LOADERS);
}
}
示例11: TemplateService
import com.github.jknack.handlebars.io.TemplateLoader; //导入依赖的package包/类
public TemplateService(Vertx vertx, TemplateLoader loader) {
this.vertx = vertx;
this.loader = loader;
this.handlebars = new Handlebars(loader);
}
示例12: withResourceLoaders
import com.github.jknack.handlebars.io.TemplateLoader; //导入依赖的package包/类
public Builder withResourceLoaders() {
log.debug("using resource loaders");
loaders.add(new ClassPathTemplateLoader());
loaders.add(new ClassPathTemplateLoader(TemplateLoader.DEFAULT_PREFIX, ".sql"));
return this;
}
示例13: build
import com.github.jknack.handlebars.io.TemplateLoader; //导入依赖的package包/类
public Templating build() {
handlebars.with(loaders.toArray(new TemplateLoader[0]));
return new Templating(handlebars);
}
示例14: TemplateService
import com.github.jknack.handlebars.io.TemplateLoader; //导入依赖的package包/类
public TemplateService(TemplateLoader loader) {
this.handlebars = new Handlebars(loader);
}
示例15: HandlebarsApi
import com.github.jknack.handlebars.io.TemplateLoader; //导入依赖的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);
}