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


Java Template.apply方法代码示例

本文整理汇总了Java中com.github.jknack.handlebars.Template.apply方法的典型用法代码示例。如果您正苦于以下问题:Java Template.apply方法的具体用法?Java Template.apply怎么用?Java Template.apply使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.github.jknack.handlebars.Template的用法示例。


在下文中一共展示了Template.apply方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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.");
  }
}
 
开发者ID:Cognifide,项目名称:knotx,代码行数:17,代码来源:HandlebarsFragment.java

示例2: 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);
    }
}
 
开发者ID:mvc-spec,项目名称:ozark,代码行数:18,代码来源:HandlebarsViewEngine.java

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

示例4: 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;
    }
}
 
开发者ID:FAOSTAT,项目名称:faostat-api,代码行数:22,代码来源:QUERIES.java

示例5: 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);
}
 
开发者ID:jenkinsci,项目名称:gatekeeper-plugin,代码行数:20,代码来源:GatekeeperMerge.java

示例6: 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);
    }
}
 
开发者ID:magnoliales,项目名称:magnolia-handlebars,代码行数:25,代码来源:HandlebarsRenderer.java

示例7: prepareStatement

import com.github.jknack.handlebars.Template; //导入方法依赖的package包/类
private void prepareStatement() throws ReportException {
  try {
    Map<String, String> parameters = new HashMap<String, String>();
    Enumeration<String> paramNames = request.getParameterNames();
    while (paramNames.hasMoreElements()) {
      String key = paramNames.nextElement();
      parameters.put(key, StringEscapeUtils.escapeSql(request.getParameter(key)));
    }
    log.trace("Loading parameters from request: {}", parameters);

    Handlebars handlebars = new Handlebars();

    Template template = handlebars.compileInline(config.getQuery());

    statement = template.apply(parameters);

    log.trace("Loaded statement: {}", statement);
  } catch (IOException ioe) {
    throw new ReportException("Exception templating query", ioe);
  }
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:22,代码来源:QueryReportExecutor.java

示例8: render

import com.github.jknack.handlebars.Template; //导入方法依赖的package包/类
private String render(Template template, Object data) {
    try {
        // Can't currently get the jackson module working not sure why.
        Map<String, Object> jsonMap = Json.serializer().mapFromJson(Json.serializer().toString(data));
        if (log.isDebugEnabled()) {
            log.debug("rendering template " + template.filename() + "\n" + Json.serializer().toPrettyString(jsonMap));
        }
        return template.apply(jsonMap);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:StubbornJava,项目名称:StubbornJava,代码行数:13,代码来源:Templating.java

示例9: render

import com.github.jknack.handlebars.Template; //导入方法依赖的package包/类
@Override
public String render(ModelAndView modelAndView) {
    String viewName = modelAndView.getViewName();
    try {
        Template template = handlebars.compile(viewName);
        return template.apply(modelAndView.getModel());
    } catch (IOException e) {
        throw new RuntimeIOException(e);
    }
}
 
开发者ID:VoxelGamesLib,项目名称:VoxelGamesLib,代码行数:11,代码来源:MaTemplateEngine.java

示例10: writeTemplate

import com.github.jknack.handlebars.Template; //导入方法依赖的package包/类
private void writeTemplate(Path path, Template template, Object context) {
  try (final BufferedWriter writer = Files.newBufferedWriter(path, UTF_8)) {
    template.apply(context, writer);
  } catch (Exception e) {
    throw Throwables.propagate(e);
  }
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:8,代码来源:TemplateManager.java

示例11: createGlossary

import com.github.jknack.handlebars.Template; //导入方法依赖的package包/类
private String createGlossary(final Template template, final SubDomain domain) {
    final String glossary;
    try {
        glossary = template.apply(domain);
    } catch (IOException e) {
        log.debug(e.getMessage(), e);
        throw new IllegalStateException(
            format("Glossary Template is not applicable: %s", e.getMessage())
        );
    }
    return glossary;
}
 
开发者ID:myunusov,项目名称:maxur-ldoc,代码行数:13,代码来源:GlossaryWriter.java

示例12: writeReport

import com.github.jknack.handlebars.Template; //导入方法依赖的package包/类
private static void writeReport(@Nonnull String reportName, @Nonnull Map<String,Object> data, @Nonnull Path filePath) throws IOException {
  Template template = initTemplate(reportName);
  String html = template.apply(data);
  try (BufferedWriter writer = Files.newBufferedWriter(filePath, StandardCharsets.UTF_8)) {
    writer.write(html);
  }
}
 
开发者ID:PharmGKB,项目名称:PharmCAT,代码行数:8,代码来源:HtmlReportGenerator.java

示例13: saveMeshUiConfig

import com.github.jknack.handlebars.Template; //导入方法依赖的package包/类
private void saveMeshUiConfig() {
	File parentFolder = new File(CONFIG_FOLDERNAME);
	if (!parentFolder.exists() && !parentFolder.mkdirs()) {
		throw error(INTERNAL_SERVER_ERROR, "Could not create configuration folder {" + parentFolder.getAbsolutePath() + "}");
	}
	File outputFile = new File(parentFolder, CONF_FILE);
	if (!outputFile.exists()) {
		InputStream ins = getClass().getResourceAsStream("/meshui-templates/mesh-ui-config.hbs");
		if (ins == null) {
			throw error(INTERNAL_SERVER_ERROR, "Could not find mesh-ui config template within classpath.");
		}
		try {
			Handlebars handlebars = new Handlebars();
			Template template = handlebars.compileInline(IOUtils.toString(ins));

			Map<String, Object> model = new HashMap<>();
			int httpPort = Mesh.mesh().getOptions().getHttpServerOptions().getPort();
			model.put("mesh_http_port", httpPort);

			// Prepare render context
			Context context = Context.newBuilder(model).resolver(MapValueResolver.INSTANCE).build();
			FileWriter writer = new FileWriter(outputFile);
			template.apply(context, writer);
			writer.close();
		} catch (Exception e) {
			log.error("Could not save configuration file {" + outputFile.getAbsolutePath() + "}");
		}
	}
}
 
开发者ID:gentics,项目名称:mesh,代码行数:30,代码来源:AdminGUIEndpoint.java

示例14: writeTestCaseSummaryReport

import com.github.jknack.handlebars.Template; //导入方法依赖的package包/类
private void writeTestCaseSummaryReport() throws IOException {
    Template template = new Helpers(new Handlebars()).registerHelpers().compile(TEST_SUMMARY_REPORT);
    for (TestSuiteModel ts : processedTestSuites) {
        String content = template.apply(ts);
        FileUtils.writeStringToFile(new File(TEST_SUMMARY_PATH + ts.getUniqueID() + ".html"),
            content);
    }
}
 
开发者ID:web-innovate,项目名称:bootstraped-multi-test-results-report,代码行数:9,代码来源:JUnitReportBuilder.java

示例15: writeFeatureSummaryReports

import com.github.jknack.handlebars.Template; //导入方法依赖的package包/类
private void writeFeatureSummaryReports() throws IOException {
    Template template = bars.compile(FEATURE_SUMMARY_REPORT);
    for (Feature feature : getProcessedFeatures()) {
        String generatedFeatureHtmlContent = template.apply(feature);
        // generatedFeatureSummaryReports.put(feature.getUniqueID(), generatedFeatureHtmlContent);
        FileUtils.writeStringToFile(new File(REPORTS_SUMMARY_PATH + feature.getUniqueID() + ".html"),
            generatedFeatureHtmlContent);
    }
}
 
开发者ID:web-innovate,项目名称:bootstraped-multi-test-results-report,代码行数:10,代码来源:CucumberReportBuilder.java


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