当前位置: 首页>>代码示例>>Java>>正文


Java TemplateLoader类代码示例

本文整理汇总了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();
}
 
开发者ID:vert-x3,项目名称:vertx-starter,代码行数:19,代码来源:GeneratorVerticle.java

示例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();
}
 
开发者ID:danielpetisme,项目名称:vertx-forge,代码行数:19,代码来源:GeneratorVerticle.java

示例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;
}
 
开发者ID:commercetools,项目名称:commercetools-sunrise-java,代码行数:17,代码来源:HandlebarsFactory.java

示例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);
}
 
开发者ID:mjeanroy,项目名称:springmvc-mustache,代码行数:22,代码来源:HandlebarsCompilerTest.java

示例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));
}
 
开发者ID:VoxelGamesLib,项目名称:VoxelGamesLib,代码行数:12,代码来源:MaTemplateEngine.java

示例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;
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:9,代码来源:MailConfig.java

示例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));
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:8,代码来源:MailConfig.java

示例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);
}
 
开发者ID:amzn,项目名称:swa-sample-seller,代码行数:17,代码来源:Config.java

示例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));
}
 
开发者ID:perwendel,项目名称:spark-template-engines,代码行数:19,代码来源:HandlebarsTemplateEngine.java

示例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);
    }
}
 
开发者ID:commercetools,项目名称:commercetools-sunrise-java,代码行数:13,代码来源:HandlebarsFactory.java

示例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);
}
 
开发者ID:vert-x3,项目名称:vertx-starter,代码行数:6,代码来源:TemplateService.java

示例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;
}
 
开发者ID:StubbornJava,项目名称:StubbornJava,代码行数:7,代码来源:Templating.java

示例13: build

import com.github.jknack.handlebars.io.TemplateLoader; //导入依赖的package包/类
public Templating build() {
    handlebars.with(loaders.toArray(new TemplateLoader[0]));
    return new Templating(handlebars);
}
 
开发者ID:StubbornJava,项目名称:StubbornJava,代码行数:5,代码来源:Templating.java

示例14: TemplateService

import com.github.jknack.handlebars.io.TemplateLoader; //导入依赖的package包/类
public TemplateService(TemplateLoader loader) {
    this.handlebars = new Handlebars(loader);
}
 
开发者ID:danielpetisme,项目名称:vertx-forge,代码行数:4,代码来源:TemplateService.java

示例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);
}
 
开发者ID:andriykuba,项目名称:play-handlebars,代码行数:55,代码来源:HandlebarsApi.java


注:本文中的com.github.jknack.handlebars.io.TemplateLoader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。