當前位置: 首頁>>代碼示例>>Java>>正文


Java MustacheFactory類代碼示例

本文整理匯總了Java中com.github.mustachejava.MustacheFactory的典型用法代碼示例。如果您正苦於以下問題:Java MustacheFactory類的具體用法?Java MustacheFactory怎麽用?Java MustacheFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MustacheFactory類屬於com.github.mustachejava包,在下文中一共展示了MustacheFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: announce

import com.github.mustachejava.MustacheFactory; //導入依賴的package包/類
private String announce(NuclearStream stream, List<String> responseList, Map<String, String> context) {
    String response = responseList.get(RandomUtils.nextInt(0, responseList.size()));
    if (context == null) {
        announcePresenter.announce(stream.getPublisher().getId(), response, true, false);
    } else {
        MustacheFactory mf = new DefaultMustacheFactory();
        Mustache mustache = mf.compile(new StringReader(response), "response");
        try {
            StringWriter writer = new StringWriter();
            mustache.execute(writer, context).flush();
            response = writer.toString();
            announcePresenter.announce(stream.getPublisher().getId(), response, true, false);
        } catch (IOException e) {
            log.warn("Could not create response", e);
        }
    }
    return response;
}
 
開發者ID:quanticc,項目名稱:ugc-bot-redux,代碼行數:19,代碼來源:NuclearService.java

示例2: VersionResourceImpl

import com.github.mustachejava.MustacheFactory; //導入依賴的package包/類
@Inject
VersionResourceImpl(
    ServiceMetadata serviceMetadata,
    @HealthTemplateFactory MustacheFactory mustacheFactory) {

  BuildInfo buildInfo = serviceMetadata.getBuildInfo();

  BuildDto.Builder buildInfoBuilder = BuildDto
      .builder()
      .setArtifactName(buildInfo.getArtifactId())
      .setVersion(buildInfo.getVersion());

  buildInfo.getBuildDateTime().ifPresent(date -> buildInfoBuilder.setBuildDateTime(date));

  buildDto = buildInfoBuilder.build();

  healthHtmlOutput = StreamingWriterOutput
      .with(writer -> mustacheFactory
          .compile("version.mustache")
          .execute(writer, new BuildPresenter(buildDto)));
}
 
開發者ID:cerner,項目名稱:beadledom,代碼行數:22,代碼來源:VersionResourceImpl.java

示例3: initialize

import com.github.mustachejava.MustacheFactory; //導入依賴的package包/類
public void initialize(String mustacheTemplate)
        throws IOException
{
    InputStream stream = this.getClass().getClassLoader().getResourceAsStream(mustacheTemplate);
    if (stream == null) {
        throw new FileNotFoundException("Resource not found: " + mustacheTemplate);
    }

    // compile template
    MustacheFactory mf = new DefaultMustacheFactory();
    Reader reader = new InputStreamReader(stream, "utf-8");
    mustache = mf.compile(reader, "template");

    // output path
    if (!outputPath.exists()) {
        outputPath.mkdirs();
    }
}
 
開發者ID:UKPLab,項目名稱:argument-reasoning-comprehension-task,代碼行數:19,代碼來源:AbstractHITCreator.java

示例4: main

import com.github.mustachejava.MustacheFactory; //導入依賴的package包/類
public static void main(String[] args) {
    System.out.println("Starting executor");

    if (new File("config").mkdir()) {
        System.out.println("Created config directory");
    }

    MustacheFactory mustacheFactory = new DefaultMustacheFactory();
    final Mustache filebeatMustache = mustacheFactory.compile("filebeat.yaml.mustache");
    final Mustache metricbeatMustache = mustacheFactory.compile("metricbeat.yaml.mustache");
    try {
        MesosExecutorDriver driver = new MesosExecutorDriver(new HumioExecutor(filebeatMustache, metricbeatMustache));
        final Protos.Status status = driver.run();

        System.out.println("status = " + status);
        if (status.equals(Protos.Status.DRIVER_STOPPED)) {
            System.exit(0);
        } else {
            System.err.println("Error: " + status);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:humio,項目名稱:dcos2humio,代碼行數:25,代碼來源:ExecutorApplication.java

示例5: init

import com.github.mustachejava.MustacheFactory; //導入依賴的package包/類
private void init()
{
  String templatePath = _config.get("view.mustache.templates",
                                    "classpath:/templates");

  MustacheResolver resolver;

  if (templatePath.startsWith("classpath:")) {
    String root = templatePath.substring("classpath:".length());

    resolver = new ClasspathResolver(root);

    //ClassLoader loader = Thread.currentThread().getContextClassLoader();
    //resolver = new MustacheResolverImpl(loader, root);
  }
  else {
    resolver = new DefaultResolver(templatePath);
  }

  MustacheFactory factory = new DefaultMustacheFactory(resolver);

  _factory = factory;
}
 
開發者ID:baratine,項目名稱:baratine,代碼行數:24,代碼來源:ViewMustache.java

示例6: testGenerate

import com.github.mustachejava.MustacheFactory; //導入依賴的package包/類
@Test
public void testGenerate() throws IOException {
    UuidSupplier uuidSupplier = mock(UuidSupplier.class);
    MustacheFactory mustacheFactory = mock(MustacheFactory.class);
    Mustache mustache = mock(Mustache.class);

    String aclToken = "acl-token";
    when(uuidSupplier.get()).thenReturn(aclToken);
    when(mustacheFactory.compile("templates/vault-acl.json.mustache")).thenReturn(mustache);

    ArgumentCaptor<Writer> writer = ArgumentCaptor.forClass(Writer.class);
    ArgumentCaptor<VaultAclInput> input = ArgumentCaptor.forClass(VaultAclInput.class);

    when(mustache.execute(writer.capture(), input.capture())).thenReturn(mock(Writer.class));

    VaultAclGenerator generator = new VaultAclGenerator(uuidSupplier, mustacheFactory);

    // invoke method under test
    VaultAclEntry result = generator.generate();

    assertEquals(aclToken, input.getValue().getAclToken());
    assertEquals(aclToken, result.getAclToken());
    assertEquals(writer.getValue().toString(), result.getEntry()); // test could be improved, compares empty Strings here
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-lifecycle-cli,代碼行數:25,代碼來源:VaultAclGeneratorTest.java

示例7: getTemplate

import com.github.mustachejava.MustacheFactory; //導入依賴的package包/類
public static String getTemplate(PXContext pxContext, PXConfiguration pxConfig, String template) throws PXException {
    try {
        // In case of challenge
        if (pxContext.getBlockAction().equals("challenge") && pxContext.getBlockActionData() != null) {
            return pxContext.getBlockActionData();
        }

        Map<String, String> props = getProps(pxContext, pxConfig);
        MustacheFactory mf = new DefaultMustacheFactory();
        Mustache m = mf.compile((getTemplate(template)), (getTemplate(template)).toString());
        StringWriter sw = new StringWriter();
        m.execute(sw, props).close();
        return sw.toString();
    } catch (IOException e) {
        throw new PXException(e);
    }

}
 
開發者ID:PerimeterX,項目名稱:perimeterx-java-sdk,代碼行數:19,代碼來源:TemplateFactory.java

示例8: buildPluginOutput

import com.github.mustachejava.MustacheFactory; //導入依賴的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

示例9: writeFile

import com.github.mustachejava.MustacheFactory; //導入依賴的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

示例10: doExport

import com.github.mustachejava.MustacheFactory; //導入依賴的package包/類
private void doExport(MustachePojoWrapper mustachePojoWrapper) {
    MustacheFactory mf = new DefaultMustacheFactory();

    // enrich repo information
    mustachePojoWrapper.repoOwner = repoOwner;
    mustachePojoWrapper.repoName = repoName;

    try {


        for (String curTemplate : templates) {
            //TODO remove this hack!
            String reportFileName = curTemplate.replaceAll("/templates", "");

            System.out.println(">>>>>> write template " + curTemplate + " >> to >> " + reportFileName);

            Mustache curMustache = mf.compile(curTemplate);

            curMustache.execute(new PrintWriter(new File(reportFileName)), mustachePojoWrapper).flush();
            //curMustache.execute(new PrintWriter(System.out), new NonseneWrapper(issueEvents)).flush();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

}
 
開發者ID:stola3,項目名稱:github-issue-events-report,代碼行數:27,代碼來源:GitHubEventsReport.java

示例11: setup

import com.github.mustachejava.MustacheFactory; //導入依賴的package包/類
@Setup
public void setup() {
    MustacheFactory mustacheFactory = new DefaultMustacheFactory() {

        @Override
        public void encode(String value, Writer writer) {
            // Disable HTML escaping
            try {
                writer.write(value);
            } catch (IOException e) {
                throw new MustacheException(e);
            }
        }
    };
    template = mustacheFactory.compile("templates/stocks.mustache.html");
}
 
開發者ID:mbosecke,項目名稱:template-benchmark,代碼行數:17,代碼來源:Mustache.java

示例12: getTemplate

import com.github.mustachejava.MustacheFactory; //導入依賴的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

示例13: render

import com.github.mustachejava.MustacheFactory; //導入依賴的package包/類
/**
 * Get the changelog.
 *
 * @throws GitChangelogRepositoryException
 */
public void render(final Writer writer) throws GitChangelogRepositoryException {
  final MustacheFactory mf = new DefaultMustacheFactory();
  final String templateContent = checkNotNull(getTemplateContent(), "No template!");
  final StringReader reader = new StringReader(templateContent);
  final Mustache mustache = mf.compile(reader, this.settings.getTemplatePath());
  try {
    final boolean useIntegrationIfConfigured = shouldUseIntegrationIfConfigured(templateContent);
    final Changelog changelog = this.getChangelog(useIntegrationIfConfigured);
    mustache
        .execute(
            writer, //
            new Object[] {changelog, this.settings.getExtendedVariables()} //
            )
        .flush();
  } catch (final IOException e) {
    // Should be impossible!
    throw new GitChangelogRepositoryException("", e);
  }
}
 
開發者ID:tomasbjerre,項目名稱:git-changelog-lib,代碼行數:25,代碼來源:GitChangelogApi.java

示例14: index

import com.github.mustachejava.MustacheFactory; //導入依賴的package包/類
@GET
@Produces("text/html")
public String index() throws Exception {

    System.out.println(world.getConfig("key1"));
    System.out.println(world.getConfig("key2"));
    System.out.println(world.getConfig("key3"));
    
    // TODO
    final String root_url = "/jersey-ex/";
    final String static_web_path = "/jersey-ex/static/"; // TODO rewrite to ServletContext.getContextPath()

    MustacheFactory mf = new DefaultMustacheFactory();
    Mustache mustache = mf.compile("exercise2/mustache-tmpl/layout-default.html");
    Map<String, Object> layoutScope = new HashMap<>();
    layoutScope.put("rooturl", root_url);
    layoutScope.put("title", "Jersey Exercise Demo Application(2)");
    layoutScope.put("user", userContext);
    layoutScope.put("body", "protected resource");
    layoutScope.put("staticroot", static_web_path);
    StringWriter sw = new StringWriter();
    mustache.execute(sw, layoutScope).flush();
    return sw.toString();
}
 
開發者ID:msakamoto-sf,項目名稱:jaxrs2-exercise-jersey-servlet,代碼行數:25,代碼來源:Protected.java

示例15: index

import com.github.mustachejava.MustacheFactory; //導入依賴的package包/類
@GET
@Produces("text/html")
public String index() throws Exception {

    // TODO
    final String root_url = "/jersey-ex/";
    final String static_web_path = "/jersey-ex/static/"; // TODO rewrite to ServletContext.getContextPath()
    final UserContext userContext = new UserContext();
    userContext.setAuthenticated(true);
    userContext.setId(1000);
    userContext.setDisplayName("user1");

    System.out.println("Resource class Index#index(), lifecycle_indicator = " + lifecycle_indicator);
    MustacheFactory mf = new DefaultMustacheFactory();
    Mustache mustache = mf.compile("exercise2/mustache-tmpl/layout-default.html");
    Map<String, Object> layoutScope = new HashMap<>();
    layoutScope.put("rooturl", root_url);
    layoutScope.put("title", "Jersey Exercise Demo Application(2)");
    layoutScope.put("user", userContext);
    layoutScope.put("body", "Body Contents Block");
    layoutScope.put("staticroot", static_web_path);
    StringWriter sw = new StringWriter();
    mustache.execute(sw, layoutScope).flush();
    return sw.toString();
}
 
開發者ID:msakamoto-sf,項目名稱:jaxrs2-exercise-jersey-servlet,代碼行數:26,代碼來源:Index.java


注:本文中的com.github.mustachejava.MustacheFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。