use of com.github.mustachejava.Mustache in project error-prone by google.
the class BugPatternIndexWriter method dump.
void dump(Collection<BugPatternInstance> patterns, Writer w, Target target, Set<String> enabledChecks) throws IOException {
// (Default, Severity) -> [Pattern...]
SortedSetMultimap<IndexEntry, MiniDescription> sorted = TreeMultimap.create(Comparator.comparing(IndexEntry::onByDefault).reversed().thenComparing(IndexEntry::severity), Comparator.comparing(MiniDescription::name));
for (BugPatternInstance pattern : patterns) {
sorted.put(IndexEntry.create(enabledChecks.contains(pattern.name), pattern.severity), MiniDescription.create(pattern));
}
Map<String, Object> templateData = new HashMap<>();
List<Map<String, Object>> bugpatternData = Multimaps.asMap(sorted).entrySet().stream().map(e -> ImmutableMap.of("category", e.getKey().asCategoryHeader(), "checks", e.getValue())).collect(Collectors.toCollection(ArrayList::new));
templateData.put("bugpatterns", bugpatternData);
if (target == Target.EXTERNAL) {
Map<String, String> frontmatterData = ImmutableMap.<String, String>builder().put("title", "Bug Patterns").put("layout", "bugpatterns").build();
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(options);
Writer yamlWriter = new StringWriter();
yamlWriter.write("---\n");
yaml.dump(frontmatterData, yamlWriter);
yamlWriter.write("---\n");
templateData.put("frontmatter", yamlWriter.toString());
MustacheFactory mf = new DefaultMustacheFactory();
Mustache mustache = mf.compile("com/google/errorprone/resources/bugpatterns_external.mustache");
mustache.execute(w, templateData);
} else {
MustacheFactory mf = new DefaultMustacheFactory();
Mustache mustache = mf.compile("com/google/errorprone/resources/bugpatterns_internal.mustache");
mustache.execute(w, templateData);
}
}
use of com.github.mustachejava.Mustache in project POL-POM-5 by PlayOnLinux.
the class HtmlTemplate method render.
public String render(Object userScope) throws IOException {
final Reader reader = new InputStreamReader(inputStream);
final Mustache mustache = mf.compile(reader, null);
OutputStream stream = new ByteArrayOutputStream();
Object[] scopes = new Object[2];
scopes[0] = userScope;
scopes[1] = globalScope();
mustache.execute(new PrintWriter(stream), scopes).flush();
return stream.toString();
}
Aggregations