Search in sources :

Example 11 with Mustache

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);
    }
}
Also used : DefaultMustacheFactory(com.github.mustachejava.DefaultMustacheFactory) SortedSetMultimap(com.google.common.collect.SortedSetMultimap) ImmutableMap(com.google.common.collect.ImmutableMap) StringWriter(java.io.StringWriter) Collection(java.util.Collection) Mustache(com.github.mustachejava.Mustache) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) Multimaps(com.google.common.collect.Multimaps) ArrayList(java.util.ArrayList) Yaml(org.yaml.snakeyaml.Yaml) DumperOptions(org.yaml.snakeyaml.DumperOptions) List(java.util.List) TreeMultimap(com.google.common.collect.TreeMultimap) Map(java.util.Map) MustacheFactory(com.github.mustachejava.MustacheFactory) AutoValue(com.google.auto.value.AutoValue) Writer(java.io.Writer) Comparator(java.util.Comparator) SeverityLevel(com.google.errorprone.BugPattern.SeverityLevel) Target(com.google.errorprone.DocGenTool.Target) HashMap(java.util.HashMap) DefaultMustacheFactory(com.github.mustachejava.DefaultMustacheFactory) Mustache(com.github.mustachejava.Mustache) Yaml(org.yaml.snakeyaml.Yaml) DefaultMustacheFactory(com.github.mustachejava.DefaultMustacheFactory) MustacheFactory(com.github.mustachejava.MustacheFactory) StringWriter(java.io.StringWriter) DumperOptions(org.yaml.snakeyaml.DumperOptions) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 12 with Mustache

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();
}
Also used : Mustache(com.github.mustachejava.Mustache)

Aggregations

Mustache (com.github.mustachejava.Mustache)12 DefaultMustacheFactory (com.github.mustachejava.DefaultMustacheFactory)6 MustacheFactory (com.github.mustachejava.MustacheFactory)5 StringWriter (java.io.StringWriter)4 CompiledScript (org.elasticsearch.script.CompiledScript)4 ExecutableScript (org.elasticsearch.script.ExecutableScript)4 BytesReference (org.elasticsearch.common.bytes.BytesReference)3 ScriptEngineService (org.elasticsearch.script.ScriptEngineService)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 Writer (java.io.Writer)2 ArrayList (java.util.ArrayList)2 DumperOptions (org.yaml.snakeyaml.DumperOptions)2 Yaml (org.yaml.snakeyaml.Yaml)2 UIContext (com.github.bordertech.wcomponents.UIContext)1 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)1 AutoValue (com.google.auto.value.AutoValue)1 Multimaps (com.google.common.collect.Multimaps)1 SortedSetMultimap (com.google.common.collect.SortedSetMultimap)1