本文整理汇总了Java中com.github.jknack.handlebars.io.ClassPathTemplateLoader类的典型用法代码示例。如果您正苦于以下问题:Java ClassPathTemplateLoader类的具体用法?Java ClassPathTemplateLoader怎么用?Java ClassPathTemplateLoader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClassPathTemplateLoader类属于com.github.jknack.handlebars.io包,在下文中一共展示了ClassPathTemplateLoader类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import com.github.jknack.handlebars.io.ClassPathTemplateLoader; //导入依赖的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.ClassPathTemplateLoader; //导入依赖的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: TemplateCaptureTarget
import com.github.jknack.handlebars.io.ClassPathTemplateLoader; //导入依赖的package包/类
public TemplateCaptureTarget (File baseDir,
String indexTemplate,
String indexMoreTemplate,
String headerTemplate,
String footerTemplate,
String entryTemplate) {
this.baseDir = baseDir;
if (!baseDir.exists() && !baseDir.mkdirs()) {
throw new IllegalArgumentException("baseDir does not exist and could not be created: "+baseDir.getAbsolutePath());
}
final Handlebars handlebars = new Handlebars(new ClassPathTemplateLoader("/"));
handlebars.registerHelper("nl2br", new Helper<Object>() {
public CharSequence apply(Object src, Options options) {
return src == null || src.toString().isEmpty() ? "" : new Handlebars.SafeString(src.toString().replace("\n", "<br/>"));
}
});
this.indexTemplate = compileOrDie(indexTemplate, handlebars);
this.indexMoreTemplate = compileOrDie(indexMoreTemplate, handlebars);
this.headerTemplate = compileOrDie(headerTemplate, handlebars);
this.footerTemplate = compileOrDie(footerTemplate, handlebars);
this.entryTemplate = compileOrDie(entryTemplate, handlebars);
}
示例4: parseTemplateUrl
import com.github.jknack.handlebars.io.ClassPathTemplateLoader; //导入依赖的package包/类
public static TemplatePath parseTemplateUrl(String templatePath) throws GenerateException {
if (templatePath == null) {
return null;
}
TemplatePath tp;
if (templatePath.startsWith(CLASSPATH)) {
String resPath = templatePath.substring(CLASSPATH.length());
tp = extractTemplateObject(resPath);
tp.loader = new ClassPathTemplateLoader(tp.prefix, tp.suffix);
} else {
tp = extractTemplateObject(templatePath);
tp.loader = new FileTemplateLoader(tp.prefix, tp.suffix);
}
return tp;
}
示例5: TemplateEngine
import com.github.jknack.handlebars.io.ClassPathTemplateLoader; //导入依赖的package包/类
public TemplateEngine(String template) {
handlebars = new Handlebars(new ClassPathTemplateLoader("/", ""));
handlebars.registerHelper("json", Jackson2Helper.INSTANCE);
handlebars.registerHelper("join", StringHelpers.join);
handlebars.registerHelper("ifequal", IfEqualHelper.INSTANCE);
handlebars.prettyPrint(true);
location = "templates/" + template;
}
示例6: setup
import com.github.jknack.handlebars.io.ClassPathTemplateLoader; //导入依赖的package包/类
@Setup
public void setup() throws IOException {
template = new com.github.jknack.handlebars.Handlebars(new ClassPathTemplateLoader("/", ".html"))
.registerHelper("minus", new Helper<Stock>() {
@Override
public CharSequence apply(final Stock stock, final Options options)
throws IOException {
return stock.getChange() < 0 ? new SafeString("class=\"minus\"") : null;
}
}).compile("templates/stocks.hbs");
this.context = getContext();
}
示例7: HandlebarsTemplateEngine
import com.github.jknack.handlebars.io.ClassPathTemplateLoader; //导入依赖的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));
}
示例8: initializeTemplateLoader
import com.github.jknack.handlebars.io.ClassPathTemplateLoader; //导入依赖的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);
}
}
示例9: Hbs
import com.github.jknack.handlebars.io.ClassPathTemplateLoader; //导入依赖的package包/类
/**
* Creates a new {@link Hbs} module.
*
* @param prefix Template prefix.
* @param suffix Template suffix.
* @param helpers Optional list of helpers.
*/
public Hbs(final String prefix, final String suffix, final Class<?>... helpers) {
this.hbs = new Handlebars(new ClassPathTemplateLoader(prefix, suffix));
with(helpers);
// default value resolvers.
this.resolvers.add(MapValueResolver.INSTANCE);
this.resolvers.add(JavaBeanValueResolver.INSTANCE);
this.resolvers.add(MethodValueResolver.INSTANCE);
this.resolvers.add(new RequestValueResolver());
this.resolvers.add(new SessionValueResolver());
this.resolvers.add(new ConfigValueResolver());
this.resolvers.add(FieldValueResolver.INSTANCE);
}
示例10: withResourceLoaders
import com.github.jknack.handlebars.io.ClassPathTemplateLoader; //导入依赖的package包/类
public Builder withResourceLoaders() {
log.debug("using resource loaders");
loaders.add(new ClassPathTemplateLoader());
loaders.add(new ClassPathTemplateLoader(TemplateLoader.DEFAULT_PREFIX, ".sql"));
return this;
}
示例11: initTemplate
import com.github.jknack.handlebars.io.ClassPathTemplateLoader; //导入依赖的package包/类
private static Template initTemplate(String templateName) throws IOException {
Handlebars handlebars = new Handlebars(new ClassPathTemplateLoader(sf_templatePrefix));
StringHelpers.register(handlebars);
handlebars.registerHelpers(ReportHelpers.class);
return handlebars.compile(templateName);
}
示例12: templateLoader
import com.github.jknack.handlebars.io.ClassPathTemplateLoader; //导入依赖的package包/类
private static TemplateLoader templateLoader() {
final List<TemplateLoader> templateLoaders = new ArrayList<>();
templateLoaders.add(new ClassPathTemplateLoader("/templates")); //overrides
templateLoaders.add(new ClassPathTemplateLoader("/META-INF/resources/webjars/templates")); //webjar
return new CompositeTemplateLoader(templateLoaders.toArray(new TemplateLoader[templateLoaders.size()]));
}
示例13: handlebarsTemplateEngine
import com.github.jknack.handlebars.io.ClassPathTemplateLoader; //导入依赖的package包/类
private static TemplateEngine handlebarsTemplateEngine() {
final TestableI18nResolver i18nResolver = new TestableI18nResolver(emptyMap());
final List<TemplateLoader> templateLoaders = singletonList(new ClassPathTemplateLoader("/templates/cmsHelper"));
final Handlebars handlebars = HandlebarsFactory.create(templateLoaders, i18nResolver, new I18nIdentifierFactory());
return HandlebarsTemplateEngine.of(handlebars, new HandlebarsContextFactory(new PlayJavaFormResolver(msg -> msg)));
}
示例14: HandleBarsRepo
import com.github.jknack.handlebars.io.ClassPathTemplateLoader; //导入依赖的package包/类
public HandleBarsRepo() {
TemplateLoader loader = new ClassPathTemplateLoader();
loader.setPrefix("/templates");
loader.setSuffix(".html");
engine = new Handlebars(loader);
}