Search in sources :

Example 1 with SoyListData

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

the class PathServletTest method fileHtml.

@Test
public void fileHtml() throws Exception {
    repo.branch("master").commit().add("foo", "foo\ncontents\n").create();
    Map<String, ?> data = buildData("/repo/+/master/foo");
    assertThat(data).containsEntry("type", "REGULAR_FILE");
    SoyListData lines = (SoyListData) getBlobData(data).get("lines");
    assertThat(lines.length()).isEqualTo(2);
    SoyListData spans = lines.getListData(0);
    assertThat(spans.length()).isEqualTo(1);
    assertThat(spans.getMapData(0).get("classes")).isEqualTo(StringData.forValue("pln"));
    assertThat(spans.getMapData(0).get("text")).isEqualTo(StringData.forValue("foo"));
    spans = lines.getListData(1);
    assertThat(spans.length()).isEqualTo(1);
    assertThat(spans.getMapData(0).get("classes")).isEqualTo(StringData.forValue("pln"));
    assertThat(spans.getMapData(0).get("text")).isEqualTo(StringData.forValue("contents"));
}
Also used : SoyListData(com.google.template.soy.data.SoyListData) Test(org.junit.Test)

Example 2 with SoyListData

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

the class HostIndexServletTest method fooBarSubdirHtml.

@Test
public void fooBarSubdirHtml() throws Exception {
    Map<String, ?> data = buildData("/foo/bar/");
    assertThat(data).containsEntry("hostName", URLS.getHostName(null) + "/foo/bar");
    assertThat(data).containsEntry("prefix", "foo/bar/");
    SoyListData breadcrumbs = (SoyListData) data.get("breadcrumbs");
    assertThat(breadcrumbs.length()).isEqualTo(3);
    SoyListData repos = (SoyListData) data.get("repositories");
    assertThat(repos.length()).isEqualTo(1);
    SoyMapData ent = (SoyMapData) repos.get(0);
    assertThat(ent.get("name").toString()).isEqualTo("repo");
    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)

Example 3 with SoyListData

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

the class HostIndexServletTest method fooSubdirHtml.

@Test
public void fooSubdirHtml() throws Exception {
    Map<String, ?> data = buildData("/foo/");
    assertThat(data).containsEntry("hostName", URLS.getHostName(null) + "/foo");
    assertThat(data).containsEntry("prefix", "foo/");
    SoyListData breadcrumbs = (SoyListData) data.get("breadcrumbs");
    assertThat(breadcrumbs.length()).isEqualTo(2);
    SoyListData repos = (SoyListData) data.get("repositories");
    assertThat(repos.length()).isEqualTo(1);
    SoyMapData ent = (SoyMapData) repos.get(0);
    assertThat(ent.get("name").toString()).isEqualTo("bar/repo");
    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)

Example 4 with SoyListData

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

the class ChangeEmail method getDiffTemplateData.

/**
   * Generate a Soy list of maps representing each line of the unified diff. The line maps will have
   * a 'type' key which maps to one of 'common', 'add' or 'remove' and a 'text' key which maps to
   * the line's content.
   */
private SoyListData getDiffTemplateData() {
    SoyListData result = new SoyListData();
    Splitter lineSplitter = Splitter.on(System.getProperty("line.separator"));
    for (String diffLine : lineSplitter.split(getUnifiedDiff())) {
        SoyMapData lineData = new SoyMapData();
        lineData.put("text", diffLine);
        // Skip empty lines and lines that look like diff headers.
        if (diffLine.isEmpty() || diffLine.startsWith("---") || diffLine.startsWith("+++")) {
            lineData.put("type", "common");
        } else {
            switch(diffLine.charAt(0)) {
                case '+':
                    lineData.put("type", "add");
                    break;
                case '-':
                    lineData.put("type", "remove");
                    break;
                default:
                    lineData.put("type", "common");
                    break;
            }
        }
        result.add(lineData);
    }
    return result;
}
Also used : Splitter(com.google.common.base.Splitter) SoyMapData(com.google.template.soy.data.SoyMapData) SoyListData(com.google.template.soy.data.SoyListData)

Example 5 with SoyListData

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

the class BlobSoyData method writeResult.

private static void writeResult(SoyListData lines, String classes, String s, int start, int end) {
    SoyListData line = lines.getListData(lines.length() - 1);
    while (true) {
        int nl = nextLineBreak(s, start, end);
        if (nl < 0) {
            break;
        }
        addSpan(line, classes, s, start, nl);
        start = nl + 1;
        if (start == s.length()) {
            return;
        }
        line = new SoyListData();
        lines.add(line);
    }
    addSpan(line, classes, s, start, end);
}
Also used : SoyListData(com.google.template.soy.data.SoyListData)

Aggregations

SoyListData (com.google.template.soy.data.SoyListData)10 SoyMapData (com.google.template.soy.data.SoyMapData)5 Test (org.junit.Test)4 TraceAttributes (com.facebook.buck.util.trace.BuildTraces.TraceAttributes)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Splitter (com.google.common.base.Splitter)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Path (java.nio.file.Path)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1 ParseResult (syntaxhighlight.ParseResult)1