本文整理汇总了Java中com.github.jknack.handlebars.Template类的典型用法代码示例。如果您正苦于以下问题:Java Template类的具体用法?Java Template怎么用?Java Template使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Template类属于com.github.jknack.handlebars包,在下文中一共展示了Template类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: render
import com.github.jknack.handlebars.Template; //导入依赖的package包/类
@Override
public void render(
RoutingContext context, String templateFileName, Handler<AsyncResult<Buffer>> handler) {
try {
Template template = cache.get(templateFileName);
if (template == null) {
synchronized (this) {
loader.setVertx(context.vertx());
template = handlebars.compile(templateFileName);
cache.put(templateFileName, template);
}
}
Context engineContext = Context.newBuilder(context.data()).resolver(getResolvers()).build();
handler.handle(Future.succeededFuture(Buffer.buffer(template.apply(engineContext))));
} catch (Exception ex) {
handler.handle(Future.failedFuture(ex));
}
}
示例2: compileWith
import com.github.jknack.handlebars.Template; //导入依赖的package包/类
String compileWith(Handlebars handlebars) {
try {
Template compiledFragment = handlebars.compileInline(unwrappedContent);
LOGGER.trace("Applying context [{}] to fragment [{}]", fragment.context(),
StringUtils
.abbreviate(fragment.content().replaceAll("[\n\r\t]", ""),
MAX_FRAGMENT_CONTENT_LOG_LENGTH));
return compiledFragment.apply(
Context.newBuilder(fragment.context())
.push(JsonObjectValueResolver.INSTANCE)
.build());
} catch (IOException e) {
LOGGER.error("Could not process fragment [{}]", fragment.content(), e);
throw new IllegalStateException("Handlebars fragment can not be evaluated correctly.");
}
}
示例3: processView
import com.github.jknack.handlebars.Template; //导入依赖的package包/类
@Override
public void processView(ViewEngineContext context) throws ViewEngineException {
Models models = context.getModels();
try (PrintWriter writer = context.getResponse().getWriter();
InputStream resourceAsStream = servletContext.getResourceAsStream(resolveView(context));
InputStreamReader in = new InputStreamReader(resourceAsStream, "UTF-8");
BufferedReader bufferedReader = new BufferedReader(in);) {
String viewContent = bufferedReader.lines().collect(Collectors.joining());
Template template = handlebars.compileInline(viewContent);
template.apply(models, writer);
} catch (IOException e) {
throw new ViewEngineException(e);
}
}
示例4: render
import com.github.jknack.handlebars.Template; //导入依赖的package包/类
private String render(final boolean isInline, final String source, final Object data, final String languageCode) {
try {
final Template template = isInline ? handlebars.compileInline(source) : handlebars.compile(source);
final Context context = Context.newBuilder(data).combine(LANGUAGE_PROPERTY, languageCode)
.resolver(
ScalaJsonValueResolver.INSTANCE,
JsonNodeValueResolver.INSTANCE,
MapValueResolver.INSTANCE,
FieldValueResolver.INSTANCE)
.build();
return template.apply(context);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例5: generateHtmlReport
import com.github.jknack.handlebars.Template; //导入依赖的package包/类
private void generateHtmlReport(Template templateTestClassReport, TestModel tm) throws IOException {
for (ClassModel cm : tm.getClasses()) {
File file = new File(classesSummaryPath + tm.getName() + cm.getName() + ".html");
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
OutputStream os =
new FileOutputStream(file);
PrintWriter rw = new PrintWriter(os);
rw.print(templateTestClassReport.apply(cm));
rw.close();
os.close();
}
}
示例6: writeFeaturePassedReport
import com.github.jknack.handlebars.Template; //导入依赖的package包/类
private void writeFeaturePassedReport() throws IOException {
Template template = bars.compile(FEATURE_OVERVIEW_REPORT);
List<Feature> onlyPassed = new ArrayList<>(getProcessedFeatures());
for (Iterator<Feature> it = onlyPassed.listIterator(); it.hasNext(); ) {
Feature f = it.next();
if (f.getOverallStatus().equalsIgnoreCase(Constants.FAILED)) {
it.remove();
}
}
AllFeatureReports allFeatures = new AllFeatureReports(FEATURES_PASSED_OVERVIEW, onlyPassed);
FileUtils.writeStringToFile(new File(REPORTS_OVERVIEW_PATH + FEATURES_PASSED_HTML),
template.apply(allFeatures));
}
开发者ID:web-innovate,项目名称:bootstraped-multi-test-results-report,代码行数:17,代码来源:CucumberReportBuilder.java
示例7: writeTestsPassedReport
import com.github.jknack.handlebars.Template; //导入依赖的package包/类
private void writeTestsPassedReport() throws IOException {
Template template = new Helpers(new Handlebars()).registerHelpers().compile(TEST_OVERVIEW_REPORT);
List<TestSuiteModel> onlyPassed = new ArrayList<>(processedTestSuites);
for (Iterator<TestSuiteModel> it = onlyPassed.listIterator(); it.hasNext(); ) {
TestSuiteModel f = it.next();
if (f.getOverallStatus().equalsIgnoreCase(Constants.FAILED)) {
it.remove();
}
}
AllRSpecJUnitReports allTestSuites = new AllRSpecJUnitReports("Passed test suites report", onlyPassed);
FileUtils.writeStringToFile(new File(TEST_OVERVIEW_PATH + "testsPassed.html"),
template.apply(allTestSuites));
}
示例8: writeTestsFailedReport
import com.github.jknack.handlebars.Template; //导入依赖的package包/类
private void writeTestsFailedReport() throws IOException {
Template template = new Helpers(new Handlebars()).registerHelpers().compile(TEST_OVERVIEW_REPORT);
List<TestSuiteModel> onlyFailed = new ArrayList<>(processedTestSuites);
for (Iterator<TestSuiteModel> it = onlyFailed.listIterator(); it.hasNext(); ) {
TestSuiteModel f = it.next();
if (f.getOverallStatus().equalsIgnoreCase(Constants.PASSED)) {
it.remove();
}
}
AllRSpecJUnitReports allTestSuites = new AllRSpecJUnitReports("Failed test suites report", onlyFailed);
FileUtils.writeStringToFile(new File(TEST_OVERVIEW_PATH + "testsFailed.html"),
template.apply(allTestSuites));
}
示例9: apply
import com.github.jknack.handlebars.Template; //导入依赖的package包/类
@Override
public CharSequence apply(final String path, final Options options)
throws IOException {
notEmpty(path, "found: '%s', expected 'template path'", path);
String wrapperName = options.hash("wrapper", "anonymous");
final JsWrapper wrapper = JsWrapper.wrapper(wrapperName);
notNull(wrapper, "found '%s', expected: '%s'",
wrapperName, StringUtils.join(JsWrapper.values(), ", ").toLowerCase());
Handlebars handlebars = options.handlebars;
String name = path;
if (name.startsWith("/")) {
name = name.substring(1);
}
if (wrapper == JsWrapper.AMD) {
name += handlebars.getLoader().getSuffix();
}
Template template = handlebars.compile(path);
String precompiled = template.toJavaScript();
return new Handlebars.SafeString(wrapper.wrap(name, precompiled));
}
示例10: applyWithCurrentTemplate
import com.github.jknack.handlebars.Template; //导入依赖的package包/类
@Override
public CharSequence applyWithCurrentTemplate(final String path, final Options options) {
notEmpty(path, "found: '%s', expected 'template path'", path);
String wrapperName = options.hash("wrapper", "anonymous");
final JsWrapper wrapper = JsWrapper.wrapper(wrapperName);
notNull(wrapper, "found '%s', expected: '%s'",
wrapperName, StringUtils.join(JsWrapper.values(), ", ").toLowerCase());
Handlebars handlebars = options.handlebars;
String name = StringUtils.substringBeforeLast(path,".");
if (name.startsWith("/")) {
name = name.substring(1);
}
if (wrapper == JsWrapper.AMD) {
name += handlebars.getLoader().getSuffix();
}
Template template = options.fn;
String precompiled = template.toJavaScript();
return new Handlebars.SafeString(wrapper.wrap(name, precompiled));
}
示例11: getQuery
import com.github.jknack.handlebars.Template; //导入依赖的package包/类
public String getQuery(String id, Map<String, Object> procedureParameters) {
Handlebars handlebars = new Handlebars();
Map<String, Object> parameters = new LinkedHashMap<String, Object>() {};
try {
String query = this.getQueries().get(id.toLowerCase());
Template template = handlebars.compileInline(query);
for (String key : procedureParameters.keySet()) {
// TODO: review the search condition
Boolean escape = (id == "search" || id == "suggestions")? true: false;
String queryCondition = createQueryCondition(procedureParameters.get(key), escape);
parameters.put(key, new Handlebars.SafeString(queryCondition));
}
LOGGER.info("getQuery; parameters: " + parameters);
query = template.apply(parameters);
LOGGER.info("getQuery; Query: " + query);
return query;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例12: ensureReleaseBranch
import com.github.jknack.handlebars.Template; //导入依赖的package包/类
private void ensureReleaseBranch(AdvancedSCMManager amm, String targetBranch) throws AdvancedSCMException, ReleaseBranchInvalidException{
String releaseFileContent = null;
if (releaseFileContentTemplate != null && !releaseFileContentTemplate.isEmpty()
&& releaseFilePath != null && !releaseFilePath.isEmpty()) {
Handlebars handlebars = new Handlebars();
Context templateContext = Context.newContext(null);
templateContext.data("release", amm.getReleaseBranch(targetBranch).getReleaseName());
Template mustacheTemplate;
try {
mustacheTemplate = handlebars.compileInline(releaseFileContentTemplate);
releaseFileContent = mustacheTemplate.apply(templateContext);
} catch (IOException e) {
throw new AdvancedSCMException("Error rendering release file content template");
}
}
amm.ensureReleaseBranch(
targetBranch, releaseFilePath, releaseFileContent,
"[Jenkins Integration Merge] " + targetBranch + " release", commitUsername);
}
示例13: onRender
import com.github.jknack.handlebars.Template; //导入依赖的package包/类
@Override
protected void onRender(Node content, RenderableDefinition definition, RenderingContext renderingContext,
Map<String, Object> context, String templateScript) throws RenderException {
final AppendableWriter out;
try {
out = renderingContext.getAppendable();
AggregationState aggregationState = (AggregationState) context.get("state");
Node node = aggregationState.getCurrentContentNode();
Locale locale = aggregationState.getLocale();
context.put("content", new ChainedContentMap(node, locale));
Context combinedContext = Context.newBuilder(context)
.resolver(JavaBeanValueResolver.INSTANCE, FieldValueResolver.INSTANCE, MapValueResolver.INSTANCE)
.build();
try {
Template template = handlebars.compile(templateScript);
template.apply(combinedContext, out);
} finally {
combinedContext.destroy();
}
} catch (IOException e) {
LOGGER.error("Cannot render template", e);
}
}
示例14: main
import com.github.jknack.handlebars.Template; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
App app = App.configure(conf -> {
conf.set(Config.RENDERER_REPOSITORY, new HandleBarsRepo());
return conf;
});
// see. https://github.com/jknack/handlebars.java
Handlebars engine = new Handlebars();
Template t = engine.compileInline("Hello {{this}}!");
// use handlebars simply
app.get("/bars",
(req, res) -> res.render("john", Renderer.of(t::apply)));
// read template from templates/say/hello.html
app.get("/hello",
(req, res) -> res.render(new User("peter"), "say/hello"));
app.listen().addShutdownHook();
}
示例15: render
import com.github.jknack.handlebars.Template; //导入依赖的package包/类
@Override
public void render(RoutingContext context, String templateDirectory, String templateFileName, Handler<AsyncResult<Buffer>> handler) {
try {
String baseTemplateFileName = templateFileName;
templateFileName = templateDirectory + templateFileName;
Template template = isCachingEnabled() ? cache.get(templateFileName) : null;
if (template == null) {
synchronized (this) {
loader.setPrefix(templateDirectory);
loader.setVertx(context.vertx());
// Strip leading slash from Utils##normalizePath
template = handlebars.compile(baseTemplateFileName.substring(1));
if (isCachingEnabled()) {
cache.put(templateFileName, template);
}
}
}
Context engineContext = Context.newBuilder(context.data()).resolver(getResolvers()).build();
handler.handle(Future.succeededFuture(Buffer.buffer(template.apply(engineContext))));
} catch (Exception ex) {
handler.handle(Future.failedFuture(ex));
}
}