本文整理汇总了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;
}
示例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)));
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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
}
示例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);
}
}
示例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();
}
示例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();
}
}
示例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();
}
}
示例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");
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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();
}