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


Java Mustache.execute方法代码示例

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


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

示例1: render

import com.github.mustachejava.Mustache; //导入方法依赖的package包/类
/**
 * Create a response object by mustache template engine.
 *
 * @param template
 * @param context
 * @return
 */
public WebResponse render(@NonNull HTMLFilterProvider controller,
		@NonNull String template,
		Object context) {
	final Mustache mustache = mustacheFactory.compile(template);
	final StringWriter writer = new StringWriter();
	mustache.execute(writer, context);
	String bodyString = writer.toString();
	bodyString = controller.filterHTML(bodyString);

	final byte[] body = bodyString.getBytes(StandardCharsets.UTF_8);

	final ByteArrayResponse res = new ByteArrayResponse(200, body);
	res.setContentType("text/html; charset=utf-8");
	res.setContentLength(body.length);
	return res;
}
 
开发者ID:tokuhirom,项目名称:avans-mustache,代码行数:24,代码来源:MustacheView.java

示例2: test1

import com.github.mustachejava.Mustache; //导入方法依赖的package包/类
private void test1() throws IOException {
	// final JsonObject scope = this.getScope();
	final JsonObject x = this.getScope();
	// Map<String, Object> scope = x.getMap();

	final Map<String, Object> scope = this.mappifyJsonObject(x);
	// Map<String, Object> scope = new HashMap<>();
	// scope.put("YesNo", true);
	// scope.put("answer", 42);
	final Mustache m = this.getTemplate();
	final Writer w = this.getWriter();
	w.append(x.encodePrettily());
	m.execute(w, scope);
	w.close();

}
 
开发者ID:Stwissel,项目名称:vertx-sfdc-platformevents,代码行数:17,代码来源:JsonExperiments.java

示例3: buildPluginOutput

import com.github.mustachejava.Mustache; //导入方法依赖的package包/类
private static void buildPluginOutput(File input) throws IOException {
    String name = parseName(input.getName());

    Dep dep = parseDep(input);
    String url = dep.toUrl(MAVEN2);
    if (testURL(url)) {
        System.out.println("URL is good: " + url);
    } else {
        throw new IOException("Invalid URL: " + url + " for dep " + dep);
    }

    HashMap<String, Object> scopes = new HashMap<String, Object>();
    scopes.put("name", name);
    scopes.put("url", url);
    scopes.put("version", (dep.version!=null)?dep.version:dep.rev);
    scopes.put("date", new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
    scopes.put("md5", getUrlAsString(url + ".md5"));

    Writer writer = new OutputStreamWriter(new FileOutputStream(new File(dirOut, name+".xml")));
    MustacheFactory mf = new DefaultMustacheFactory();
    Mustache mustache = mf.compile(new StringReader(template), "template");
    mustache.execute(writer, scopes);
    writer.flush();
    writer.close();
}
 
开发者ID:OpenSageTV,项目名称:sagetv-plugin-repo,代码行数:26,代码来源:BuildLibraries.java

示例4: writeFile

import com.github.mustachejava.Mustache; //导入方法依赖的package包/类
private void writeFile(String headTemplateFile) {
	try {

		Reader reader = new FileReader(new File(headTemplateFile));

		log.debug(headTemplateFile);
		File outputFile = new File(headTemplateFile.split("template")[0] + "html");

		Writer writer = new FileWriter(outputFile);

		MustacheFactory mf = new DefaultMustacheFactory();
		Mustache mustache = mf.compile(reader, "example");
		mustache.execute(writer, templates);
		writer.flush();

		log.debug(Tools.readFile(outputFile.getAbsolutePath()));

	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:dessalines,项目名称:referendum,代码行数:22,代码来源:WriteHTMLFiles.java

示例5: getTemplate

import com.github.mustachejava.Mustache; //导入方法依赖的package包/类
@Override
public Template getTemplate(String templateName) {
    try {
        MustacheFactory mf = new DefaultMustacheFactory();
        final Mustache mustache = mf.compile(new StringReader(Templates.loadTemplate(templateName, resourceManager)), templateName);

        return new Template() {
            @Override
            public String apply(Object data) {
                final StringWriter stringWriter = new StringWriter();
                mustache.execute(stringWriter, data);
                return stringWriter.getBuffer().toString();
            }
        };
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:undertow-io,项目名称:undertow.js,代码行数:19,代码来源:MustacheTemplateProvider.java

示例6: generateIndex

import com.github.mustachejava.Mustache; //导入方法依赖的package包/类
private void generateIndex(Mustache template, Writer out, ImmutableMap<String, Object> staticContext) {
    List<DocumentedClassView> units = new ArrayList<DocumentedClassView>();
    List<DocumentedClassView> services = new ArrayList<DocumentedClassView>();
    for (DocumentedClassView clazz : documentationDataView.documentedClasses()) {
        if (clazz.isUnit()) {
            units.add(clazz);
        } else {
            services.add(clazz);
        }
    }
    Collections.sort(units, DocumentedClassView.SIMPLE_NAME_COMPARATOR);
    Collections.sort(services, DocumentedClassView.SIMPLE_NAME_COMPARATOR);

    ImmutableMap<String, Object> context = ImmutableMap.<String, Object>builder()
            .put("title", "Index")
            .put("units", units)
            .put("services", services)
            .put("searchData", generateSearchData())
            .putAll(staticContext)
            .build();
    template.execute(out, context);
}
 
开发者ID:Ladicek,项目名称:ann-docu-gen,代码行数:23,代码来源:DocumentationWriter.java

示例7: renderTemplate

import com.github.mustachejava.Mustache; //导入方法依赖的package包/类
protected void renderTemplate(HandlingContext context, File templateFile, Map<String, ?> scopes) throws IOException, ServletException {
    try {
        if (templateFile.exists()) {
            Map<String, Object> templateScopes = new HashMap<String, Object>(serverContext.params);
            templateScopes.putAll(scopes);
            Mustache template = getTemplate(templateFile); 
            StringWriter writer = new StringWriter();
            template.execute(writer, templateScopes);
            writer.flush();
            renderText(context, HttpServletResponse.SC_OK, writer.toString());
        } else {
            renderText(context, SC_BAD_REQUEST, "File does not exist: " + templateFile);
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new ServletException(e);
    }
}
 
开发者ID:wdsx,项目名称:testing-tools,代码行数:19,代码来源:GenericHandler.java

示例8: doGet

import com.github.mustachejava.Mustache; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException {
  try {
    response.setContentType("text/html");
    response.setStatus(HttpServletResponse.SC_OK);

    Mustache template = service.getMustacheFactory().compile("templates/index.mustache");
    Writer writer = response.getWriter();

    // Collect server status objects from around this place.
    ImmutableMap<ModuleType, C5Module> modules = service.getServer().getModules();

    ImmutableMap<Long, NodeInfo> nodes = getNodes();
    Collection<Tablet> tablets = getTablets();

    TopLevelHolder templateContext = new TopLevelHolder(service.getServer(), modules, nodes, tablets);
    template.execute(writer, templateContext);
    writer.flush();

  } catch (ExecutionException | InterruptedException | TimeoutException e) {
    throw new IOException("Getting status", e);
  }
}
 
开发者ID:cloud-software-foundation,项目名称:c5,代码行数:24,代码来源:StatusServlet.java

示例9: sendMail

import com.github.mustachejava.Mustache; //导入方法依赖的package包/类
private CompletableFuture sendMail(Mustache titleCompiler, Mustache contentCompiler, Mustache htmlCompiler, String email, Map<String, Object> data) {
    StringWriter writer;

    writer = new StringWriter();
    contentCompiler.execute(writer, data);
    String txtContent = writer.toString();

    writer = new StringWriter();
    htmlCompiler.execute(writer, data);
    String htmlContent = writer.toString();

    writer = new StringWriter();
    titleCompiler.execute(writer, data);
    String title = writer.toString();
    MailSender mailSender = mailConfig.getMailSender();

    return CompletableFuture.runAsync(() -> {
        try {
            mailSender.sendMail(email, title, txtContent, Optional.of(htmlContent), Stream.empty());
        } catch (MessagingException e) {
            LOGGER.error(e, "Unable to send mail");
        }
    });
}
 
开发者ID:rakam-io,项目名称:rakam,代码行数:25,代码来源:WebUserService.java

示例10: getTemplatizedPodYamlString

import com.github.mustachejava.Mustache; //导入方法依赖的package包/类
public static String getTemplatizedPodYamlString(String podYaml) {
    StringWriter writer = new StringWriter();
    MustacheFactory mf = new DefaultMustacheFactory();
    Mustache mustache = mf.compile(new StringReader(podYaml), "templatePod");
    mustache.execute(writer, KubernetesInstanceFactory.getJinJavaContext());
    return writer.toString();
}
 
开发者ID:gocd,项目名称:kubernetes-elastic-agents,代码行数:8,代码来源:KubernetesInstanceFactory.java

示例11: saveAsSVG

import com.github.mustachejava.Mustache; //导入方法依赖的package包/类
static void saveAsSVG(final File destination_directory, Analyser analyzer) throws IOException, JSONException {

        final JFreeChart chart = analyzer.getChart();
        final File analysis_dir = makeAnalysisDirectory(destination_directory);
        final String analyzer_name = analyzer.getName();
        ChartExportUtils.saveAsSVG(chart, DEFAULT_SVG_WIDTH, DEFAULT_SVG_HEIGHT, new File(analysis_dir, analyzer_name + ".svg"));
        FileUtils.write(new File(analysis_dir, analyzer_name + ".json"), analyzer.toJSON().toString());

        final String relative_path = analysis_dir.toPath().relativize(RESOURCES.toPath()).toString();
        final HashMap<String, Object> scope = new HashMap<>();
        scope.put("data", analyzer.toJSON());
        scope.put("relative_path", relative_path);
        final boolean category = CategoryDataset.class.isAssignableFrom(analyzer.getDataset().getClass());
        scope.put("category", category);
        scope.put("title", analyzer_name);
        scope.put("legend", chart.getLegend() != null);

        if(category) {
            scope.put("x_title", chart.getCategoryPlot().getDomainAxis().getLabel());
            scope.put("y_title", chart.getCategoryPlot().getRangeAxis().getLabel());
        }else{
            scope.put("x_title", chart.getXYPlot().getDomainAxis().getLabel());
            scope.put("y_title", chart.getXYPlot().getRangeAxis().getLabel());
        }

        final MustacheFactory factory = new DefaultMustacheFactory();
        final String template = FileUtils.readFileToString(new File(RESOURCES, "template.html"));

        final Mustache mustache = factory.compile(new StringReader(template), "test");
        try (FileWriter writer = new FileWriter(new File(analysis_dir, analyzer_name + ".html"))) {
            mustache.execute(writer, scope);
            writer.flush();
        }

    }
 
开发者ID:stacs-srg,项目名称:shabdiz,代码行数:36,代码来源:Analysis.java

示例12: applyVariables

import com.github.mustachejava.Mustache; //导入方法依赖的package包/类
/**
 * Replaces any {{ }} wrapped variable placeholders in a {@link String} with
 * the current value in this {@link YarnState}
 * 
 * @param text
 *            The {@link String} to replace variable placeholders in
 * @return The {@link String} with variable values inserted
 */
public String applyVariables(String text) {
	if (!mustacheCache.containsKey(text)) {
		mustacheCache.put(text, mustacheFactory.compile(new StringReader(text), text));
	}
	Mustache mustache = mustacheCache.get(text);

	StringWriter result = new StringWriter();
	mustache.execute(result, variablesMustache);
	return result.toString();
}
 
开发者ID:mini2Dx,项目名称:jarn,代码行数:19,代码来源:YarnState.java

示例13: execute

import com.github.mustachejava.Mustache; //导入方法依赖的package包/类
public static String execute(File externalTemplate, String defautInternalTemplate, Map<String, Object> scopes) throws IOException, URISyntaxException {
    Writer writer = new StringWriter();
    MustacheFactory mf = new DefaultMustacheFactory();

    String templateName = externalTemplate != null ? externalTemplate.getName() : defautInternalTemplate;
    Reader template = externalTemplate != null ? Files.newBufferedReader(externalTemplate.toPath()) : getReader(defautInternalTemplate);
    Mustache mustache = mf.compile(template, templateName);
    mustache.execute(writer, scopes);
    return writer.toString();
}
 
开发者ID:jboz,项目名称:living-documentation,代码行数:11,代码来源:MustacheUtil.java

示例14: merge

import com.github.mustachejava.Mustache; //导入方法依赖的package包/类
public static String merge(String template, Map<String,Object> model){
    Writer w = new StringWriter();
    MustacheFactory mf = new DefaultMustacheFactory();
    Mustache mustache = mf.compile(new StringReader(template), UUID.randomUUID().toString());
    mustache.execute(w,model);
    return w.toString();
}
 
开发者ID:claytantor,项目名称:blueweave,代码行数:8,代码来源:MustacheUtils.java

示例15: build

import com.github.mustachejava.Mustache; //导入方法依赖的package包/类
/**
 * build.
 *
 * @return String
 */
public String build() {
    final MustacheFactory mf = new DefaultMustacheFactory();
    final Mustache template = mf.compile(this.template);

    final StringWriter writer = new StringWriter();
    template.execute(writer, this.scope);
    return writer.toString();
}
 
开发者ID:pan-dora,项目名称:modeller,代码行数:14,代码来源:TemplateBuilder.java


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