Search in sources :

Example 11 with SoyMapData

use of com.google.template.soy.data.SoyMapData in project buck by facebook.

the class TracesHandlerDelegate method getTraces.

@VisibleForTesting
SoyListData getTraces() throws IOException {
    List<Path> traceFiles = buildTraces.listTraceFilesByLastModified();
    SoyListData traces = new SoyListData();
    for (Path path : traceFiles) {
        String name = path.getFileName().toString();
        Matcher matcher = TRACE_FILE_NAME_PATTERN.matcher(name);
        if (!matcher.matches()) {
            // Could be build.trace or launch.xxx.trace.
            continue;
        }
        SoyMapData trace = new SoyMapData();
        trace.put("name", name);
        trace.put("id", matcher.group(1));
        TraceAttributes traceAttributes = buildTraces.getTraceAttributesFor(path);
        trace.put("dateTime", traceAttributes.getFormattedDateTime());
        if (traceAttributes.getCommand().isPresent()) {
            trace.put("command", traceAttributes.getCommand().get());
        } else {
            trace.put("command", "");
        }
        traces.add(trace);
    }
    return traces;
}
Also used : Path(java.nio.file.Path) SoyMapData(com.google.template.soy.data.SoyMapData) Matcher(java.util.regex.Matcher) TraceAttributes(com.facebook.buck.util.trace.BuildTraces.TraceAttributes) SoyListData(com.google.template.soy.data.SoyListData) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 12 with SoyMapData

use of com.google.template.soy.data.SoyMapData in project gerrit by GerritCodeReview.

the class IndexServletTest method pathAndNoCDN.

@Test
public void pathAndNoCDN() throws URISyntaxException {
    SoyMapData data = IndexServlet.getTemplateData("http://example.com/gerrit/", null);
    assertThat(data.getSingle("canonicalPath").stringValue()).isEqualTo("/gerrit");
    assertThat(data.getSingle("staticResourcePath").stringValue()).isEqualTo("/gerrit");
}
Also used : SoyMapData(com.google.template.soy.data.SoyMapData) Test(org.junit.Test)

Example 13 with SoyMapData

use of com.google.template.soy.data.SoyMapData in project gerrit by GerritCodeReview.

the class IndexServletTest method noPathAndCDN.

@Test
public void noPathAndCDN() throws URISyntaxException {
    SoyMapData data = IndexServlet.getTemplateData("http://example.com/", "http://my-cdn.com/foo/bar/");
    assertThat(data.getSingle("canonicalPath").stringValue()).isEqualTo("");
    assertThat(data.getSingle("staticResourcePath").stringValue()).isEqualTo("http://my-cdn.com/foo/bar/");
}
Also used : SoyMapData(com.google.template.soy.data.SoyMapData) Test(org.junit.Test)

Example 14 with SoyMapData

use of com.google.template.soy.data.SoyMapData in project gitiles by GerritCodeReview.

the class HostIndexServletTest method rootHtml.

@Test
public void rootHtml() throws Exception {
    Map<String, ?> data = buildData("/");
    assertThat(data).containsEntry("hostName", URLS.getHostName(null));
    assertThat(data).containsEntry("breadcrumbs", NullData.INSTANCE);
    assertThat(data).containsEntry("prefix", "");
    SoyListData repos = (SoyListData) data.get("repositories");
    assertThat(repos).hasSize(1);
    SoyMapData ent = (SoyMapData) repos.get(0);
    assertThat(ent.get("name").toString()).isEqualTo(NAME);
    assertThat(ent.get("url").toString()).isEqualTo("/b/" + NAME + "/");
}
Also used : SoyMapData(com.google.template.soy.data.SoyMapData) SoyListData(com.google.template.soy.data.SoyListData) Test(org.junit.Test)

Aggregations

SoyMapData (com.google.template.soy.data.SoyMapData)14 Test (org.junit.Test)9 SoyListData (com.google.template.soy.data.SoyListData)5 TraceAttributes (com.facebook.buck.util.trace.BuildTraces.TraceAttributes)2 Matcher (java.util.regex.Matcher)2 Nullable (javax.annotation.Nullable)2 Request (org.eclipse.jetty.server.Request)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Splitter (com.google.common.base.Splitter)1 SanitizedContent (com.google.template.soy.data.SanitizedContent)1 SoyTofu (com.google.template.soy.tofu.SoyTofu)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Path (java.nio.file.Path)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1